Skip to content
Merged
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
62 changes: 7 additions & 55 deletions compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_ast::NodeId;
use rustc_attr_ir::{
ConstStability, DefaultBodyStability, DeprecatedSince, Deprecation, Stability, StabilityLevel,
};
use rustc_errors::{Applicability, Diag, Diagnostic, LintBuffer, msg};
use rustc_errors::{Diag, Diagnostic, LintBuffer, msg};
use rustc_feature::GateIssue;
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::{self as hir, HirId};
Expand Down Expand Up @@ -62,7 +62,6 @@ pub fn report_unstable(
feature: Symbol,
reason: Option<Symbol>,
issue: Option<NonZero<u32>>,
suggestion: Option<(Span, String, String, Applicability)>,
span: Span,
kind: UnstableKind,
) {
Expand All @@ -77,9 +76,6 @@ pub fn report_unstable(
};

let mut err = feature_err_issue(sess, feature, span, GateIssue::Library(issue), msg);
if let Some((inner_types, msg, sugg, applicability)) = suggestion {
err.span_suggestion(inner_types, msg, sugg, applicability);
}
if let UnstableKind::Const(kw) = kind {
err.span_label(kw, "trait is not stable as const yet");
}
Expand Down Expand Up @@ -260,42 +256,11 @@ pub enum EvalResult {
Allow,
/// We cannot use the item because it is unstable and we did not provide the
/// corresponding feature gate.
Deny {
feature: Symbol,
reason: Option<Symbol>,
issue: Option<NonZero<u32>>,
suggestion: Option<(Span, String, String, Applicability)>,
},
Deny { feature: Symbol, reason: Option<Symbol>, issue: Option<NonZero<u32>> },
/// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
Unmarked,
}

// See issue #83250.
fn suggestion_for_allocator_api(
tcx: TyCtxt<'_>,
def_id: DefId,
span: Span,
feature: Symbol,
) -> Option<(Span, String, String, Applicability)> {
if feature == sym::allocator_api {
if let Some(trait_) = tcx.opt_parent(def_id) {
if tcx.is_diagnostic_item(sym::Vec, trait_) {
let sm = tcx.sess.psess.source_map();
let inner_types = sm.span_extend_to_prev_char(span, '<', true);
if let Ok(snippet) = sm.span_to_snippet(inner_types) {
return Some((
inner_types,
"consider wrapping the inner types in tuple".to_string(),
format!("({snippet})"),
Applicability::MaybeIncorrect,
));
}
}
}
}
None
}

/// An override option for eval_stability.
pub enum AllowUnstable {
/// Don't emit an unstable error for the item
Expand Down Expand Up @@ -425,8 +390,7 @@ impl<'tcx> TyCtxt<'tcx> {
return EvalResult::Allow;
}

let suggestion = suggestion_for_allocator_api(self, def_id, span, feature);
EvalResult::Deny { feature, reason: reason.to_opt_reason(), issue, suggestion }
EvalResult::Deny { feature, reason: reason.to_opt_reason(), issue }
}
Some(_) => {
// Stable APIs are always ok to call and deprecated APIs are
Expand Down Expand Up @@ -472,12 +436,7 @@ impl<'tcx> TyCtxt<'tcx> {
return EvalResult::Allow;
}

EvalResult::Deny {
feature,
reason: reason.to_opt_reason(),
issue,
suggestion: None,
}
EvalResult::Deny { feature, reason: reason.to_opt_reason(), issue }
}
Some(_) => {
// Stable APIs are always ok to call
Expand Down Expand Up @@ -559,15 +518,9 @@ impl<'tcx> TyCtxt<'tcx> {
let is_allowed = matches!(eval_result, EvalResult::Allow);
match eval_result {
EvalResult::Allow => {}
EvalResult::Deny { feature, reason, issue, suggestion } => report_unstable(
self.sess,
feature,
reason,
issue,
suggestion,
span,
UnstableKind::Regular,
),
EvalResult::Deny { feature, reason, issue } => {
report_unstable(self.sess, feature, reason, issue, span, UnstableKind::Regular)
}
EvalResult::Unmarked => unmarked(span, def_id),
}

Expand Down Expand Up @@ -628,7 +581,6 @@ impl<'tcx> TyCtxt<'tcx> {
feature,
reason.to_opt_reason(),
issue,
None,
span,
UnstableKind::Const(const_kw_span),
);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
feature,
reason.to_opt_reason(),
issue,
None,
span,
stability::UnstableKind::Regular,
);
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,6 @@ symbols! {
alloc_layout,
alloc_zeroed,
allocator,
allocator_api,

@nnethercote nnethercote Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for removing the symbol

View changes since the review

allocator_internals,
allow,
allow_fail,
Expand Down
Loading