Skip to content

Commit c87cd68

Browse files
committed
document some functions on AttributeExt
1 parent bbe8536 commit c87cd68

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,11 +876,15 @@ pub trait AttributeExt: Debug {
876876
/// a doc comment) will return `false`.
877877
fn is_doc_comment(&self) -> Option<Span>;
878878

879+
/// Returns true if the attribute's first *and only* path segment is equal to the passed-in
880+
/// symbol.
879881
#[inline]
880882
fn has_name(&self, name: Symbol) -> bool {
881883
self.name().map(|x| x == name).unwrap_or(false)
882884
}
883885

886+
/// Returns true if the attribute's first *and only* path segment is any of the passed-in
887+
/// symbols.
884888
#[inline]
885889
fn has_any_name(&self, names: &[Symbol]) -> bool {
886890
names.iter().any(|&name| self.has_name(name))
@@ -889,6 +893,7 @@ pub trait AttributeExt: Debug {
889893
/// get the span of the entire attribute
890894
fn span(&self) -> Span;
891895

896+
/// Returns whether the attribute is a path, without any arguments.
892897
fn is_word(&self) -> bool;
893898

894899
fn path(&self) -> SmallVec<[Symbol; 1]> {
@@ -911,11 +916,14 @@ pub trait AttributeExt: Debug {
911916
/// * `#[deprecated(note = "note", ...)]` returns `Some("note")`.
912917
fn deprecation_note(&self) -> Option<Ident>;
913918

919+
/// Returns whether this attribute is any of the proc macro attributes.
920+
/// i.e. `proc_macro`, `proc_macro_attribute` or `proc_macro_derive`.
914921
fn is_proc_macro_attr(&self) -> bool {
915922
[sym::proc_macro, sym::proc_macro_attribute, sym::proc_macro_derive]
916923
.iter()
917924
.any(|kind| self.has_name(*kind))
918925
}
926+
/// Returns true if this attribute is `#[automatically_deived]`.
919927
fn is_automatically_derived_attr(&self) -> bool;
920928

921929
/// Returns the documentation and its kind if this is a doc comment or a sugared doc comment.

compiler/rustc_hir/src/hir.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,6 +1264,8 @@ pub struct HashIgnoredAttrId {
12641264
pub attr_id: AttrId,
12651265
}
12661266

1267+
/// Many functions on this type have their documentation in the [`AttributeExt`] trait,
1268+
/// since they defer their implementation directly to that trait.
12671269
#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic)]
12681270
pub enum Attribute {
12691271
/// A parsed built-in attribute.

0 commit comments

Comments
 (0)