Skip to content

Gauge usage of FnOnce::Output in the wild #127291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct LoweringContext<'a, 'hir> {
/// NodeIds that are lowered inside the current HIR owner.
node_id_to_local_id: NodeMap<hir::ItemLocalId>,

allow_fn_once_output: Lrc<[Symbol]>,
allow_try_trait: Lrc<[Symbol]>,
allow_gen_future: Lrc<[Symbol]>,
allow_async_iterator: Lrc<[Symbol]>,
Expand Down Expand Up @@ -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()
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,14 +440,14 @@ 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);

(
Expand Down
28 changes: 17 additions & 11 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,7 @@ symbols! {
fn_once_output,
fn_ptr_addr,
fn_ptr_trait,
fn_traits,
forbid,
forget,
format,
Expand Down
3 changes: 2 additions & 1 deletion library/core/src/ops/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ pub trait FnMut<Args: Tuple>: FnOnce<Args> {
pub trait FnOnce<Args: Tuple> {
/// 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.
Expand Down
Loading