From fb53299b5fcecc12db61c338d4062fa361df2003 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 3 Jul 2024 15:30:15 -0400 Subject: [PATCH 1/2] No output allowed --- compiler/rustc_ast_lowering/src/lib.rs | 2 ++ compiler/rustc_ast_lowering/src/path.rs | 13 +++++-------- compiler/rustc_span/src/symbol.rs | 1 + library/core/src/ops/function.rs | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 8fba46625ab9a..f941e161dff9b 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -129,6 +129,7 @@ struct LoweringContext<'a, 'hir> { /// NodeIds that are lowered inside the current HIR owner. node_id_to_local_id: NodeMap, + allow_fn_once_output: Lrc<[Symbol]>, allow_try_trait: Lrc<[Symbol]>, allow_gen_future: Lrc<[Symbol]>, allow_async_iterator: Lrc<[Symbol]>, @@ -177,6 +178,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { current_item: None, impl_trait_defs: Vec::new(), impl_trait_bounds: Vec::new(), + allow_fn_once_output: [sym::fn_traits].into(), allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(), allow_gen_future: if tcx.features().async_fn_track_caller { [sym::gen_future, sym::closure_track_caller].into() diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 9a1ca703699a8..2d921602c42a1 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -440,14 +440,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // If we have a bound like `async Fn() -> T`, make sure that we mark the // `Output = T` associated type bound with the right feature gates. - let mut output_span = output_ty.span; - if let Some(bound_modifier_allowed_features) = bound_modifier_allowed_features { - output_span = self.mark_span_with_reason( - DesugaringKind::BoundModifier, - output_span, - Some(bound_modifier_allowed_features), - ); - } + let output_span = self.mark_span_with_reason( + DesugaringKind::BoundModifier, + output_ty.span, + Some(bound_modifier_allowed_features.unwrap_or_else(|| self.allow_fn_once_output.clone())), + ); let constraint = self.assoc_ty_binding(sym::Output, output_span, output_ty); ( diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7da9211bcbf74..59031034e4558 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -898,6 +898,7 @@ symbols! { fn_once_output, fn_ptr_addr, fn_ptr_trait, + fn_traits, forbid, forget, format, diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index 3a3d3fcf1da64..dec0063876e38 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -242,7 +242,8 @@ pub trait FnMut: FnOnce { pub trait FnOnce { /// The returned type after the call operator is used. #[lang = "fn_once_output"] - #[stable(feature = "fn_once_output", since = "1.12.0")] + #[cfg_attr(bootstrap, stable(feature = "fn_once_output", since = "1.12.0"))] + #[cfg_attr(not(bootstrap), unstable(feature = "fn_traits", issue = "29625"))] type Output; /// Performs the call operation. From a7e10ca0380120f690f14bfe68cf7aaca65cf9e7 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 3 Jul 2024 16:53:23 -0400 Subject: [PATCH 2/2] Hack bootstrap --- compiler/rustc_ast_lowering/src/path.rs | 7 +++-- compiler/rustc_middle/src/middle/stability.rs | 28 +++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 2d921602c42a1..311116aa68eda 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -440,10 +440,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // If we have a bound like `async Fn() -> T`, make sure that we mark the // `Output = T` associated type bound with the right feature gates. - let output_span = self.mark_span_with_reason( + let output_span = self.mark_span_with_reason( DesugaringKind::BoundModifier, output_ty.span, - Some(bound_modifier_allowed_features.unwrap_or_else(|| self.allow_fn_once_output.clone())), + Some( + bound_modifier_allowed_features + .unwrap_or_else(|| self.allow_fn_once_output.clone()), + ), ); let constraint = self.assoc_ty_binding(sym::Output, output_span, output_ty); diff --git a/compiler/rustc_middle/src/middle/stability.rs b/compiler/rustc_middle/src/middle/stability.rs index d1ccd158cf938..de8aaacad2df0 100644 --- a/compiler/rustc_middle/src/middle/stability.rs +++ b/compiler/rustc_middle/src/middle/stability.rs @@ -12,7 +12,7 @@ use rustc_data_structures::unord::UnordMap; use rustc_errors::{Applicability, Diag, EmissionGuarantee}; use rustc_feature::GateIssue; use rustc_hir::def::DefKind; -use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; +use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LOCAL_CRATE}; use rustc_hir::{self as hir, HirId}; use rustc_macros::{Decodable, Encodable, HashStable, Subdiagnostic}; use rustc_middle::ty::print::with_no_trimmed_paths; @@ -604,16 +604,22 @@ impl<'tcx> TyCtxt<'tcx> { let is_allowed = matches!(eval_result, EvalResult::Allow); match eval_result { EvalResult::Allow => {} - EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => report_unstable( - self.sess, - feature, - reason, - issue, - suggestion, - is_soft, - span, - soft_handler, - ), + EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => { + if feature.as_str() == "fn_traits" && std::env::var("RUSTC_BOOTSTRAP").is_ok() { + // uwu + } else { + report_unstable( + self.sess, + feature, + reason, + issue, + suggestion, + is_soft, + span, + soft_handler, + ) + } + } EvalResult::Unmarked => unmarked(span, def_id), }