@@ -110,7 +110,9 @@ pub fn is_known(attr: &Attribute) -> bool {
110110const RUST_KNOWN_TOOL : & [ & str ] = & [ "clippy" , "rustfmt" ] ;
111111
112112pub fn is_known_tool ( attr : & Attribute ) -> bool {
113- RUST_KNOWN_TOOL . contains ( & attr. name ( ) . as_str ( ) . as_ref ( ) )
113+ let tool_name =
114+ attr. path . segments . iter ( ) . next ( ) . expect ( "empty path in attribute" ) . identifier . name ;
115+ RUST_KNOWN_TOOL . contains ( & tool_name. as_str ( ) . as_ref ( ) )
114116}
115117
116118impl NestedMetaItem {
@@ -211,7 +213,7 @@ impl NestedMetaItem {
211213}
212214
213215fn name_from_path ( path : & ast:: Path ) -> Name {
214- path. segments . iter ( ) . next ( ) . unwrap ( ) . identifier . name
216+ path. segments . last ( ) . expect ( "empty path in attribute" ) . identifier . name
215217}
216218
217219impl Attribute {
@@ -223,8 +225,8 @@ impl Attribute {
223225 matches
224226 }
225227
226- /// Returns the first segment of the name of this attribute.
227- /// E.g. `foo` for `#[foo]`, `rustfmt ` for `#[rustfmt::skip]`.
228+ /// Returns the **last** segment of the name of this attribute.
229+ /// E.g. `foo` for `#[foo]`, `skip ` for `#[rustfmt::skip]`.
228230 pub fn name ( & self ) -> Name {
229231 name_from_path ( & self . path )
230232 }
@@ -1162,6 +1164,7 @@ impl MetaItem {
11621164 fn tokens ( & self ) -> TokenStream {
11631165 let mut idents = vec ! [ ] ;
11641166 let mut last_pos = BytePos ( 0 as u32 ) ;
1167+ // FIXME: Share code with `parse_path`.
11651168 for ( i, segment) in self . name . segments . iter ( ) . enumerate ( ) {
11661169 let is_first = i == 0 ;
11671170 if !is_first {
0 commit comments