@@ -110,7 +110,9 @@ pub fn is_known(attr: &Attribute) -> bool {
110
110
const RUST_KNOWN_TOOL : & [ & str ] = & [ "clippy" , "rustfmt" ] ;
111
111
112
112
pub 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 ( ) )
114
116
}
115
117
116
118
impl NestedMetaItem {
@@ -211,7 +213,7 @@ impl NestedMetaItem {
211
213
}
212
214
213
215
fn 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
215
217
}
216
218
217
219
impl Attribute {
@@ -223,8 +225,8 @@ impl Attribute {
223
225
matches
224
226
}
225
227
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]`.
228
230
pub fn name ( & self ) -> Name {
229
231
name_from_path ( & self . path )
230
232
}
@@ -1162,6 +1164,7 @@ impl MetaItem {
1162
1164
fn tokens ( & self ) -> TokenStream {
1163
1165
let mut idents = vec ! [ ] ;
1164
1166
let mut last_pos = BytePos ( 0 as u32 ) ;
1167
+ // FIXME: Share code with `parse_path`.
1165
1168
for ( i, segment) in self . name . segments . iter ( ) . enumerate ( ) {
1166
1169
let is_first = i == 0 ;
1167
1170
if !is_first {
0 commit comments