Remove rustc_feature::Stability

This commit is contained in:
mejrs 2025-06-06 11:11:42 +02:00
parent 959d6de1a9
commit 81eb182a02
6 changed files with 5 additions and 106 deletions

View file

@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_span::edition::Edition;
use rustc_span::{Symbol, sym};
use crate::{Features, Stability};
use crate::Features;
type GateFn = fn(&Features) -> bool;
@ -98,7 +98,6 @@ pub enum AttributeSafety {
pub enum AttributeGate {
/// A gated attribute which requires a feature gate to be enabled.
Gated {
stability: Stability,
/// The feature gate, for example `#![feature(rustc_attrs)]` for rustc_* attributes.
feature: Symbol,
/// The error message displayed when an attempt is made to use the attribute without its feature gate.
@ -112,12 +111,6 @@ pub enum AttributeGate {
Ungated,
}
impl AttributeGate {
fn is_deprecated(&self) -> bool {
matches!(*self, Self::Gated { stability: Stability::Deprecated(_, _), .. })
}
}
/// A template that the attribute input must match.
/// Only top-level shape (`#[attr]` vs `#[attr(...)]` vs `#[attr = ...]`) is considered now.
#[derive(Clone, Copy, Default)]
@ -252,7 +245,6 @@ macro_rules! gated {
template: $tpl,
duplicates: $duplicates,
gate: Gated {
stability: Stability::Unstable,
feature: sym::$gate,
message: $message,
check: Features::$gate,
@ -269,7 +261,6 @@ macro_rules! gated {
template: $tpl,
duplicates: $duplicates,
gate: Gated {
stability: Stability::Unstable,
feature: sym::$attr,
message: $message,
check: Features::$attr,
@ -286,7 +277,6 @@ macro_rules! gated {
template: $tpl,
duplicates: $duplicates,
gate: Gated {
stability: Stability::Unstable,
feature: sym::$gate,
message: $message,
check: Features::$gate,
@ -303,7 +293,6 @@ macro_rules! gated {
template: $tpl,
duplicates: $duplicates,
gate: Gated {
stability: Stability::Unstable,
feature: sym::$attr,
message: $message,
check: Features::$attr,
@ -337,7 +326,6 @@ macro_rules! rustc_attr {
template: $tpl,
duplicates: $duplicates,
gate: Gated {
stability: Stability::Unstable,
feature: sym::rustc_attrs,
message: "use of an internal attribute",
check: Features::rustc_attrs,
@ -1025,7 +1013,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
template: template!(NameValueStr: "name"),
duplicates: ErrorFollowing,
gate: Gated{
stability: Stability::Unstable,
feature: sym::rustc_attrs,
message: "use of an internal attribute",
check: Features::rustc_attrs,
@ -1240,10 +1227,6 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),
];
pub fn deprecated_attributes() -> Vec<&'static BuiltinAttribute> {
BUILTIN_ATTRIBUTES.iter().filter(|attr| attr.gate.is_deprecated()).collect()
}
pub fn is_builtin_attr_name(name: Symbol) -> bool {
BUILTIN_ATTRIBUTE_MAP.get(&name).is_some()
}

View file

@ -40,14 +40,6 @@ pub struct Feature {
issue: Option<NonZero<u32>>,
}
#[derive(Copy, Clone, Debug)]
pub enum Stability {
Unstable,
// First argument is tracking issue link; second argument is an optional
// help message, which defaults to "remove this attribute".
Deprecated(&'static str, Option<&'static str>),
}
#[derive(Clone, Copy, Debug, Hash)]
pub enum UnstableFeatures {
/// Disallow use of unstable features, as on beta/stable channels.
@ -144,9 +136,8 @@ pub fn find_feature_issue(feature: Symbol, issue: GateIssue) -> Option<NonZero<u
pub use accepted::ACCEPTED_LANG_FEATURES;
pub use builtin_attrs::{
AttributeDuplicates, AttributeGate, AttributeSafety, AttributeTemplate, AttributeType,
BUILTIN_ATTRIBUTE_MAP, BUILTIN_ATTRIBUTES, BuiltinAttribute, GatedCfg, deprecated_attributes,
encode_cross_crate, find_gated_cfg, is_builtin_attr_name, is_stable_diagnostic_attribute,
is_valid_for_get_attr,
BUILTIN_ATTRIBUTE_MAP, BUILTIN_ATTRIBUTES, BuiltinAttribute, GatedCfg, encode_cross_crate,
find_gated_cfg, is_builtin_attr_name, is_stable_diagnostic_attribute, is_valid_for_get_attr,
};
pub use removed::REMOVED_LANG_FEATURES;
pub use unstable::{

View file

@ -72,9 +72,6 @@ lint_builtin_const_no_mangle = const items should never be `#[no_mangle]`
lint_builtin_decl_unsafe_fn = declaration of an `unsafe` function
lint_builtin_decl_unsafe_method = declaration of an `unsafe` method
lint_builtin_deprecated_attr_link = use of deprecated attribute `{$name}`: {$message}. See {$link}
.msg_suggestion = {$suggestion}
.default_suggestion = remove this attribute
lint_builtin_deref_nullptr = dereferencing a null pointer
.label = this code causes undefined behavior when executed

View file

@ -22,7 +22,7 @@ use rustc_ast::visit::{FnCtxt, FnKind};
use rustc_ast::{self as ast, *};
use rustc_ast_pretty::pprust::expr_to_string;
use rustc_errors::{Applicability, LintDiagnostic};
use rustc_feature::{AttributeGate, BuiltinAttribute, GateIssue, Stability, deprecated_attributes};
use rustc_feature::GateIssue;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
@ -48,8 +48,7 @@ use rustc_trait_selection::traits::{self};
use crate::errors::BuiltinEllipsisInclusiveRangePatterns;
use crate::lints::{
BuiltinAnonymousParams, BuiltinConstNoMangle, BuiltinDeprecatedAttrLink,
BuiltinDeprecatedAttrLinkSuggestion, BuiltinDerefNullptr, BuiltinDoubleNegations,
BuiltinAnonymousParams, BuiltinConstNoMangle, BuiltinDerefNullptr, BuiltinDoubleNegations,
BuiltinDoubleNegationsAddParens, BuiltinEllipsisInclusiveRangePatternsLint,
BuiltinExplicitOutlives, BuiltinExplicitOutlivesSuggestion, BuiltinFeatureIssueNote,
BuiltinIncompleteFeatures, BuiltinIncompleteFeaturesHelp, BuiltinInternalFeatures,
@ -798,50 +797,6 @@ impl EarlyLintPass for AnonymousParameters {
}
}
/// Check for use of attributes which have been deprecated.
#[derive(Clone)]
pub struct DeprecatedAttr {
// This is not free to compute, so we want to keep it around, rather than
// compute it for every attribute.
depr_attrs: Vec<&'static BuiltinAttribute>,
}
impl_lint_pass!(DeprecatedAttr => []);
impl Default for DeprecatedAttr {
fn default() -> Self {
DeprecatedAttr { depr_attrs: deprecated_attributes() }
}
}
impl EarlyLintPass for DeprecatedAttr {
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
for BuiltinAttribute { name, gate, .. } in &self.depr_attrs {
if attr.ident().map(|ident| ident.name) == Some(*name) {
if let &AttributeGate::Gated {
stability: Stability::Deprecated(link, suggestion),
message,
..
} = gate
{
let suggestion = match suggestion {
Some(suggestion) => {
BuiltinDeprecatedAttrLinkSuggestion::Msg { span: attr.span, suggestion }
}
None => BuiltinDeprecatedAttrLinkSuggestion::Default { span: attr.span },
};
cx.emit_span_lint(
DEPRECATED,
attr.span,
BuiltinDeprecatedAttrLink { name: *name, message, link, suggestion },
);
}
return;
}
}
}
}
fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &[ast::Attribute]) {
use rustc_ast::token::CommentKind;

View file

@ -172,7 +172,6 @@ early_lint_methods!(
AnonymousParameters: AnonymousParameters,
EllipsisInclusiveRangePatterns: EllipsisInclusiveRangePatterns::default(),
NonCamelCaseTypes: NonCamelCaseTypes,
DeprecatedAttr: DeprecatedAttr::default(),
WhileTrue: WhileTrue,
NonAsciiIdents: NonAsciiIdents,
IncompleteInternalFeatures: IncompleteInternalFeatures,

View file

@ -199,32 +199,6 @@ pub(crate) struct BuiltinAnonymousParams<'a> {
pub ty_snip: &'a str,
}
// FIXME(davidtwco) translatable deprecated attr
#[derive(LintDiagnostic)]
#[diag(lint_builtin_deprecated_attr_link)]
pub(crate) struct BuiltinDeprecatedAttrLink<'a> {
pub name: Symbol,
pub message: &'a str,
pub link: &'a str,
#[subdiagnostic]
pub suggestion: BuiltinDeprecatedAttrLinkSuggestion<'a>,
}
#[derive(Subdiagnostic)]
pub(crate) enum BuiltinDeprecatedAttrLinkSuggestion<'a> {
#[suggestion(lint_msg_suggestion, code = "", applicability = "machine-applicable")]
Msg {
#[primary_span]
span: Span,
suggestion: &'a str,
},
#[suggestion(lint_default_suggestion, code = "", applicability = "machine-applicable")]
Default {
#[primary_span]
span: Span,
},
}
#[derive(LintDiagnostic)]
#[diag(lint_builtin_unused_doc_comment)]
pub(crate) struct BuiltinUnusedDocComment<'a> {