diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 882464c5dcf..ed0cfb1a10d 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3413,6 +3413,29 @@ pub struct Attribute { /// Denotes if the attribute decorates the following construct (outer) /// or the construct this attribute is contained within (inner). pub style: AttrStyle, + + /// The carets in the examples below show the spans for various cases. + /// ```text + /// #[foo] - A vanilla parsed attribute. + /// ^^^^^^ - Its span covers it all. + /// + /// /** abc */ /// xyz - A parsed doc comment. + /// ^^^^^^^^^^ ^^^^^^^ - Its span covers the text and comment marker(s). + /// - The same span is also used if the doc comment is desugared (into + /// a new normal `#[doc = r"..."]` attribute) by + /// `desugar_doc_comments` before being passed to a macro (which + /// is done so that `#[$m:meta]` will match). + /// + /// #[cfg_attr(pred, foo)] - A parsed `cfg_attr` attribute. + /// ^^^^^^^^^^^^^^^^^^^^^^ - Its span covers it all. + /// ^^^ - Span of the new replacement attribute (equivalent to `#[foo]`) + /// created by `cfg_attr` expansion (if `pred` is true). + /// ^^^^^^^^^^^^^^^^^^^^^^ - Span of the synthetic `CfgAttrTrace` attribute created by + /// `cfg_attr` expansion. (`CfgTrace` is derived from `#[cfg(..)]` and + /// handled similarly.) + /// ``` + /// Finally, for compiler-generated attributes the span is whatever the construction site + /// chooses. Usually `DUMMY_SP` or some relevant span from the source code. pub span: Span, }