Rollup merge of #140372 - mejrs:attrs, r=jdonszelmann
Exhaustively handle parsed attributes in CheckAttr This pr - Deletes the unused `DiagnosticAttribute ` struct and variant - Comments the `AttributeKind ` enum - The match in `CheckAttrVisitor` is now exhaustive for `AttributeKind::Parsed`. - Moved some checks around after that change I did *not* thoroughly check that there's no duplicated logic between this pass and the attribute parsing but I think it's OK. r? ````@jdonszelmann````
This commit is contained in:
@@ -57,14 +57,6 @@ impl OptimizeAttr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic, PrintAttribute)]
|
|
||||||
pub enum DiagnosticAttribute {
|
|
||||||
// tidy-alphabetical-start
|
|
||||||
DoNotRecommend,
|
|
||||||
OnUnimplemented,
|
|
||||||
// tidy-alphabetical-end
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone, HashStable_Generic, PrintAttribute)]
|
#[derive(PartialEq, Debug, Encodable, Decodable, Copy, Clone, HashStable_Generic, PrintAttribute)]
|
||||||
pub enum ReprAttr {
|
pub enum ReprAttr {
|
||||||
ReprInt(IntType),
|
ReprInt(IntType),
|
||||||
@@ -160,40 +152,52 @@ impl Deprecation {
|
|||||||
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
|
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable, PrintAttribute)]
|
||||||
pub enum AttributeKind {
|
pub enum AttributeKind {
|
||||||
// tidy-alphabetical-start
|
// tidy-alphabetical-start
|
||||||
|
/// Represents `#[rustc_allow_const_fn_unstable]`.
|
||||||
AllowConstFnUnstable(ThinVec<Symbol>),
|
AllowConstFnUnstable(ThinVec<Symbol>),
|
||||||
|
|
||||||
|
/// Represents `#[allow_internal_unstable]`.
|
||||||
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
|
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
|
||||||
|
|
||||||
|
/// Represents `#[rustc_default_body_unstable]`.
|
||||||
BodyStability {
|
BodyStability {
|
||||||
stability: DefaultBodyStability,
|
stability: DefaultBodyStability,
|
||||||
/// Span of the `#[rustc_default_body_unstable(...)]` attribute
|
/// Span of the `#[rustc_default_body_unstable(...)]` attribute
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Represents `#[rustc_confusables]`.
|
||||||
Confusables {
|
Confusables {
|
||||||
symbols: ThinVec<Symbol>,
|
symbols: ThinVec<Symbol>,
|
||||||
// FIXME(jdonszelmann): remove when target validation code is moved
|
// FIXME(jdonszelmann): remove when target validation code is moved
|
||||||
first_span: Span,
|
first_span: Span,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Represents `#[rustc_const_stable]` and `#[rustc_const_unstable]`.
|
||||||
ConstStability {
|
ConstStability {
|
||||||
stability: PartialConstStability,
|
stability: PartialConstStability,
|
||||||
/// Span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` attribute
|
/// Span of the `#[rustc_const_stable(...)]` or `#[rustc_const_unstable(...)]` attribute
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/// Represents `#[rustc_const_stable_indirect]`.
|
||||||
ConstStabilityIndirect,
|
ConstStabilityIndirect,
|
||||||
Deprecation {
|
|
||||||
deprecation: Deprecation,
|
/// Represents [`#[deprecated]`](https://doc.rust-lang.org/stable/reference/attributes/diagnostics.html#the-deprecated-attribute).
|
||||||
span: Span,
|
Deprecation { deprecation: Deprecation, span: Span },
|
||||||
},
|
|
||||||
Diagnostic(DiagnosticAttribute),
|
/// Represents [`#[doc]`](https://doc.rust-lang.org/stable/rustdoc/write-documentation/the-doc-attribute.html).
|
||||||
DocComment {
|
DocComment { style: AttrStyle, kind: CommentKind, span: Span, comment: Symbol },
|
||||||
style: AttrStyle,
|
|
||||||
kind: CommentKind,
|
/// Represents `#[rustc_macro_transparency]`.
|
||||||
span: Span,
|
|
||||||
comment: Symbol,
|
|
||||||
},
|
|
||||||
MacroTransparency(Transparency),
|
MacroTransparency(Transparency),
|
||||||
|
|
||||||
|
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
|
||||||
Repr(ThinVec<(ReprAttr, Span)>),
|
Repr(ThinVec<(ReprAttr, Span)>),
|
||||||
|
|
||||||
|
/// Represents `#[stable]`, `#[unstable]` and `#[rustc_allowed_through_unstable_modules]`.
|
||||||
Stability {
|
Stability {
|
||||||
stability: Stability,
|
stability: Stability,
|
||||||
/// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute
|
/// Span of the attribute.
|
||||||
span: Span,
|
span: Span,
|
||||||
},
|
},
|
||||||
// tidy-alphabetical-end
|
// tidy-alphabetical-end
|
||||||
|
|||||||
@@ -132,7 +132,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
target,
|
target,
|
||||||
attrs,
|
attrs,
|
||||||
),
|
),
|
||||||
_ => {
|
Attribute::Parsed(AttributeKind::AllowConstFnUnstable { .. }) => {
|
||||||
|
self.check_rustc_allow_const_fn_unstable(hir_id, attr, span, target)
|
||||||
|
}
|
||||||
|
Attribute::Parsed(AttributeKind::Deprecation { .. }) => {
|
||||||
|
self.check_deprecated(hir_id, attr, span, target)
|
||||||
|
}
|
||||||
|
Attribute::Parsed(AttributeKind::DocComment { .. }) => { /* `#[doc]` is actually a lot more than just doc comments, so is checked below*/
|
||||||
|
}
|
||||||
|
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
|
||||||
|
}
|
||||||
|
Attribute::Parsed(
|
||||||
|
AttributeKind::BodyStability { .. }
|
||||||
|
| AttributeKind::ConstStabilityIndirect
|
||||||
|
| AttributeKind::MacroTransparency(_),
|
||||||
|
) => { /* do nothing */ }
|
||||||
|
Attribute::Unparsed(_) => {
|
||||||
match attr.path().as_slice() {
|
match attr.path().as_slice() {
|
||||||
[sym::diagnostic, sym::do_not_recommend, ..] => {
|
[sym::diagnostic, sym::do_not_recommend, ..] => {
|
||||||
self.check_do_not_recommend(attr.span(), hir_id, target, attr, item)
|
self.check_do_not_recommend(attr.span(), hir_id, target, attr, item)
|
||||||
@@ -169,9 +184,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
self.check_rustc_layout_scalar_valid_range(attr, span, target)
|
self.check_rustc_layout_scalar_valid_range(attr, span, target)
|
||||||
}
|
}
|
||||||
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
|
[sym::debugger_visualizer, ..] => self.check_debugger_visualizer(attr, target),
|
||||||
[sym::rustc_allow_const_fn_unstable, ..] => {
|
|
||||||
self.check_rustc_allow_const_fn_unstable(hir_id, attr, span, target)
|
|
||||||
}
|
|
||||||
[sym::rustc_std_internal_symbol, ..] => {
|
[sym::rustc_std_internal_symbol, ..] => {
|
||||||
self.check_rustc_std_internal_symbol(attr, span, target)
|
self.check_rustc_std_internal_symbol(attr, span, target)
|
||||||
}
|
}
|
||||||
@@ -229,7 +241,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
[sym::link_name, ..] => self.check_link_name(hir_id, attr, span, target),
|
[sym::link_name, ..] => self.check_link_name(hir_id, attr, span, target),
|
||||||
[sym::link_section, ..] => self.check_link_section(hir_id, attr, span, target),
|
[sym::link_section, ..] => self.check_link_section(hir_id, attr, span, target),
|
||||||
[sym::no_mangle, ..] => self.check_no_mangle(hir_id, attr, span, target),
|
[sym::no_mangle, ..] => self.check_no_mangle(hir_id, attr, span, target),
|
||||||
[sym::deprecated, ..] => self.check_deprecated(hir_id, attr, span, target),
|
|
||||||
[sym::macro_use, ..] | [sym::macro_escape, ..] => {
|
[sym::macro_use, ..] | [sym::macro_escape, ..] => {
|
||||||
self.check_macro_use(hir_id, attr, target)
|
self.check_macro_use(hir_id, attr, target)
|
||||||
}
|
}
|
||||||
@@ -283,7 +294,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
| sym::pointee // FIXME(derive_coerce_pointee)
|
| sym::pointee // FIXME(derive_coerce_pointee)
|
||||||
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
|
| sym::omit_gdb_pretty_printer_section // FIXME(omit_gdb_pretty_printer_section)
|
||||||
| sym::used // handled elsewhere to restrict to static items
|
| sym::used // handled elsewhere to restrict to static items
|
||||||
| sym::repr // handled elsewhere to restrict to type decls items
|
|
||||||
| sym::instruction_set // broken on stable!!!
|
| sym::instruction_set // broken on stable!!!
|
||||||
| sym::windows_subsystem // broken on stable!!!
|
| sym::windows_subsystem // broken on stable!!!
|
||||||
| sym::patchable_function_entry // FIXME(patchable_function_entry)
|
| sym::patchable_function_entry // FIXME(patchable_function_entry)
|
||||||
|
|||||||
Reference in New Issue
Block a user