Skip to content

Commit 34c3b22

Browse files
committed
Auto merge of rust-lang#127291 - compiler-errors:output-ty-stab, r=<try>
Gauge usage of `FnOnce::Output` in the wild I'm curious what crates are using `FnOnce::Output` directly. Let's run crater to see. I downloaded all crates with `get-all-crates --latest` then used `zgrep` to grep for `::Output`, which may or may not be any of the traits in `std::ops`, though it did majorly cut down on the crates we'll crater: https://gist.githubusercontent.com/compiler-errors/1ef63d6e086d9a5915fb510dafdfdd43/raw/86e3bac4235e667c4c2cdf2a21d52ca38567ab1a/gistfile1.txt With relevance to tracking: - rust-lang#62290 r? `@ghost`
2 parents aa1d4f6 + a7e10ca commit 34c3b22

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ struct LoweringContext<'a, 'hir> {
129129
/// NodeIds that are lowered inside the current HIR owner.
130130
node_id_to_local_id: NodeMap<hir::ItemLocalId>,
131131

132+
allow_fn_once_output: Lrc<[Symbol]>,
132133
allow_try_trait: Lrc<[Symbol]>,
133134
allow_gen_future: Lrc<[Symbol]>,
134135
allow_async_iterator: Lrc<[Symbol]>,
@@ -177,6 +178,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
177178
current_item: None,
178179
impl_trait_defs: Vec::new(),
179180
impl_trait_bounds: Vec::new(),
181+
allow_fn_once_output: [sym::fn_traits].into(),
180182
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
181183
allow_gen_future: if tcx.features().async_fn_track_caller {
182184
[sym::gen_future, sym::closure_track_caller].into()

compiler/rustc_ast_lowering/src/path.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -440,14 +440,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
440440

441441
// If we have a bound like `async Fn() -> T`, make sure that we mark the
442442
// `Output = T` associated type bound with the right feature gates.
443-
let mut output_span = output_ty.span;
444-
if let Some(bound_modifier_allowed_features) = bound_modifier_allowed_features {
445-
output_span = self.mark_span_with_reason(
446-
DesugaringKind::BoundModifier,
447-
output_span,
448-
Some(bound_modifier_allowed_features),
449-
);
450-
}
443+
let output_span = self.mark_span_with_reason(
444+
DesugaringKind::BoundModifier,
445+
output_ty.span,
446+
Some(
447+
bound_modifier_allowed_features
448+
.unwrap_or_else(|| self.allow_fn_once_output.clone()),
449+
),
450+
);
451451
let constraint = self.assoc_ty_binding(sym::Output, output_span, output_ty);
452452

453453
(

compiler/rustc_middle/src/middle/stability.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_data_structures::unord::UnordMap;
1212
use rustc_errors::{Applicability, Diag, EmissionGuarantee};
1313
use rustc_feature::GateIssue;
1414
use rustc_hir::def::DefKind;
15-
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap};
15+
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LOCAL_CRATE};
1616
use rustc_hir::{self as hir, HirId};
1717
use rustc_macros::{Decodable, Encodable, HashStable, Subdiagnostic};
1818
use rustc_middle::ty::print::with_no_trimmed_paths;
@@ -604,16 +604,22 @@ impl<'tcx> TyCtxt<'tcx> {
604604
let is_allowed = matches!(eval_result, EvalResult::Allow);
605605
match eval_result {
606606
EvalResult::Allow => {}
607-
EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => report_unstable(
608-
self.sess,
609-
feature,
610-
reason,
611-
issue,
612-
suggestion,
613-
is_soft,
614-
span,
615-
soft_handler,
616-
),
607+
EvalResult::Deny { feature, reason, issue, suggestion, is_soft } => {
608+
if feature.as_str() == "fn_traits" && std::env::var("RUSTC_BOOTSTRAP").is_ok() {
609+
// uwu
610+
} else {
611+
report_unstable(
612+
self.sess,
613+
feature,
614+
reason,
615+
issue,
616+
suggestion,
617+
is_soft,
618+
span,
619+
soft_handler,
620+
)
621+
}
622+
}
617623
EvalResult::Unmarked => unmarked(span, def_id),
618624
}
619625

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ symbols! {
898898
fn_once_output,
899899
fn_ptr_addr,
900900
fn_ptr_trait,
901+
fn_traits,
901902
forbid,
902903
forget,
903904
format,

library/core/src/ops/function.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
242242
pub trait FnOnce<Args: Tuple> {
243243
/// The returned type after the call operator is used.
244244
#[lang = "fn_once_output"]
245-
#[stable(feature = "fn_once_output", since = "1.12.0")]
245+
#[cfg_attr(bootstrap, stable(feature = "fn_once_output", since = "1.12.0"))]
246+
#[cfg_attr(not(bootstrap), unstable(feature = "fn_traits", issue = "29625"))]
246247
type Output;
247248

248249
/// Performs the call operation.

0 commit comments

Comments
 (0)