@@ -77,10 +77,6 @@ impl Attribute {
7777}
7878
7979impl AttributeExt for Attribute {
80- fn id ( & self ) -> AttrId {
81- self . id
82- }
83-
8480 fn value_span ( & self ) -> Option < Span > {
8581 match & self . kind {
8682 AttrKind :: Normal ( normal) => match & normal. item . args {
@@ -146,10 +142,6 @@ impl AttributeExt for Attribute {
146142 }
147143 }
148144
149- fn span ( & self ) -> Span {
150- self . span
151- }
152-
153145 fn is_word ( & self ) -> bool {
154146 match & self . kind {
155147 AttrKind :: Normal ( normal) => matches ! ( normal. item. args, AttrArgs :: Empty ) ,
@@ -195,20 +187,24 @@ impl AttributeExt for Attribute {
195187 }
196188 }
197189
198- /// Returns the documentation and its kind if this is a doc comment or a sugared doc comment.
199- /// * `///doc` returns `Some(("doc", DocFragmentKind::Sugared(CommentKind::Line)))`.
200- /// * `/** doc */` returns `Some(("doc", DocFragmentKind::Sugared(CommentKind::Block)))`.
201- /// * `#[doc = "doc"]` returns `Some(("doc", DocFragmentKind::Raw))`.
190+ /// Returns the documentation, its kind if this is a doc comment or a sugared doc comment
191+ /// and the span of the entire comment (or the entire attribute if raw - see the span in
192+ /// [`DocFragmentKind`] for the literal span.)
193+ /// * `///doc` returns `Some(("doc", DocFragmentKind::Sugared(CommentKind::Line)), _)`.
194+ /// * `/** doc */` returns `Some(("doc", DocFragmentKind::Sugared(CommentKind::Block), _))`.
195+ /// * `#[doc = "doc"]` returns `Some(("doc", DocFragmentKind::Raw), _)`.
202196 /// * `#[doc(...)]` returns `None`.
203- fn doc_str_and_fragment_kind ( & self ) -> Option < ( Symbol , DocFragmentKind ) > {
197+ fn doc_str_and_fragment_kind ( & self ) -> Option < ( Symbol , DocFragmentKind , Span ) > {
204198 match & self . kind {
205- AttrKind :: DocComment ( kind, data) => Some ( ( * data, DocFragmentKind :: Sugared ( * kind) ) ) ,
199+ AttrKind :: DocComment ( kind, data) => {
200+ Some ( ( * data, DocFragmentKind :: Sugared ( * kind) , self . span ) )
201+ }
206202 AttrKind :: Normal ( normal)
207203 if normal. item . path == sym:: doc
208204 && let Some ( value) = normal. item . value_str ( )
209205 && let Some ( value_span) = normal. item . value_span ( ) =>
210206 {
211- Some ( ( value, DocFragmentKind :: Raw ( value_span) ) )
207+ Some ( ( value, DocFragmentKind :: Raw ( value_span) , self . span ) )
212208 }
213209 AttrKind :: Normal ( ..) | AttrKind :: Synthetic ( ..) => None ,
214210 }
@@ -263,6 +259,14 @@ impl AttributeExt for Attribute {
263259 fn is_rustc_doc_primitive ( & self ) -> bool {
264260 self . has_name ( sym:: rustc_doc_primitive)
265261 }
262+
263+ /// Returns whether this attribute is any of the proc macro attributes.
264+ /// i.e. `proc_macro`, `proc_macro_attribute` or `proc_macro_derive`.
265+ fn is_proc_macro_attr ( & self ) -> bool {
266+ [ sym:: proc_macro, sym:: proc_macro_attribute, sym:: proc_macro_derive]
267+ . iter ( )
268+ . any ( |kind| self . has_name ( * kind) )
269+ }
266270}
267271
268272impl Attribute {
@@ -909,9 +913,7 @@ impl MetaItemLit {
909913 }
910914}
911915
912- pub trait AttributeExt : Debug {
913- fn id ( & self ) -> AttrId ;
914-
916+ pub trait AttributeExt : Debug + ' static {
915917 /// For a single-segment attribute (i.e., `#[attr]` and not `#[path::atrr]`),
916918 /// return the name of the attribute; otherwise, returns `None`.
917919 fn name ( & self ) -> Option < Symbol > ;
@@ -948,10 +950,6 @@ pub trait AttributeExt: Debug {
948950 fn has_any_name ( & self , names : & [ Symbol ] ) -> bool {
949951 names. iter ( ) . any ( |& name| self . has_name ( name) )
950952 }
951-
952- /// get the span of the entire attribute
953- fn span ( & self ) -> Span ;
954-
955953 /// Returns whether the attribute is a path, without any arguments.
956954 fn is_word ( & self ) -> bool ;
957955
@@ -972,11 +970,8 @@ pub trait AttributeExt: Debug {
972970
973971 /// Returns whether this attribute is any of the proc macro attributes.
974972 /// i.e. `proc_macro`, `proc_macro_attribute` or `proc_macro_derive`.
975- fn is_proc_macro_attr ( & self ) -> bool {
976- [ sym:: proc_macro, sym:: proc_macro_attribute, sym:: proc_macro_derive]
977- . iter ( )
978- . any ( |kind| self . has_name ( * kind) )
979- }
973+ fn is_proc_macro_attr ( & self ) -> bool ;
974+
980975 /// Returns true if this attribute is `#[automatically_deived]`.
981976 fn is_automatically_derived_attr ( & self ) -> bool ;
982977
@@ -985,7 +980,7 @@ pub trait AttributeExt: Debug {
985980 /// * `/** doc */` returns `Some(("doc", CommentKind::Block))`.
986981 /// * `#[doc = "doc"]` returns `Some(("doc", CommentKind::Line))`.
987982 /// * `#[doc(...)]` returns `None`.
988- fn doc_str_and_fragment_kind ( & self ) -> Option < ( Symbol , DocFragmentKind ) > ;
983+ fn doc_str_and_fragment_kind ( & self ) -> Option < ( Symbol , DocFragmentKind , Span ) > ;
989984
990985 /// Returns outer or inner if this is a doc attribute or a sugared doc
991986 /// comment, otherwise None.
@@ -1009,10 +1004,6 @@ pub trait AttributeExt: Debug {
10091004// FIXME(fn_delegation): use function delegation instead of manually forwarding
10101005
10111006impl Attribute {
1012- pub fn id ( & self ) -> AttrId {
1013- AttributeExt :: id ( self )
1014- }
1015-
10161007 pub fn name ( & self ) -> Option < Symbol > {
10171008 AttributeExt :: name ( self )
10181009 }
@@ -1048,10 +1039,6 @@ impl Attribute {
10481039 AttributeExt :: has_any_name ( self , names)
10491040 }
10501041
1051- pub fn span ( & self ) -> Span {
1052- AttributeExt :: span ( self )
1053- }
1054-
10551042 pub fn is_word ( & self ) -> bool {
10561043 AttributeExt :: is_word ( self )
10571044 }
@@ -1068,7 +1055,7 @@ impl Attribute {
10681055 AttributeExt :: is_proc_macro_attr ( self )
10691056 }
10701057
1071- pub fn doc_str_and_fragment_kind ( & self ) -> Option < ( Symbol , DocFragmentKind ) > {
1058+ pub fn doc_str_and_fragment_kind ( & self ) -> Option < ( Symbol , DocFragmentKind , Span ) > {
10721059 AttributeExt :: doc_str_and_fragment_kind ( self )
10731060 }
10741061}
0 commit comments