diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 72e7b27a1f97..369fe12539fa 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -876,11 +876,15 @@ pub trait AttributeExt: Debug { /// a doc comment) will return `false`. fn is_doc_comment(&self) -> Option; + /// Returns true if the attribute's first *and only* path segment is equal to the passed-in + /// symbol. #[inline] fn has_name(&self, name: Symbol) -> bool { self.name().map(|x| x == name).unwrap_or(false) } + /// Returns true if the attribute's first *and only* path segment is any of the passed-in + /// symbols. #[inline] fn has_any_name(&self, names: &[Symbol]) -> bool { names.iter().any(|&name| self.has_name(name)) @@ -889,6 +893,7 @@ fn has_any_name(&self, names: &[Symbol]) -> bool { /// get the span of the entire attribute fn span(&self) -> Span; + /// Returns whether the attribute is a path, without any arguments. fn is_word(&self) -> bool; fn path(&self) -> SmallVec<[Symbol; 1]> { @@ -911,11 +916,14 @@ fn has_any_name(&self, names: &[Symbol]) -> bool { /// * `#[deprecated(note = "note", ...)]` returns `Some("note")`. fn deprecation_note(&self) -> Option; + /// Returns whether this attribute is any of the proc macro attributes. + /// i.e. `proc_macro`, `proc_macro_attribute` or `proc_macro_derive`. fn is_proc_macro_attr(&self) -> bool { [sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive] .iter() .any(|kind| self.has_name(*kind)) } + /// Returns true if this attribute is `#[automatically_deived]`. fn is_automatically_derived_attr(&self) -> bool; /// Returns the documentation and its kind if this is a doc comment or a sugared doc comment. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 9526143fcace..71424f7275c9 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1264,6 +1264,8 @@ pub struct HashIgnoredAttrId { pub attr_id: AttrId, } +/// Many functions on this type have their documentation in the [`AttributeExt`] trait, +/// since they defer their implementation directly to that trait. #[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)] pub enum Attribute { /// A parsed built-in attribute.