Skip to content

Commit bbc0e62

Browse files
committed
Change Attribute::name to return the last segment
And fix some typos
1 parent 9dcb692 commit bbc0e62

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

src/libsyntax/attr.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ pub fn is_known(attr: &Attribute) -> bool {
111111
const RUST_KNOWN_TOOL: &[&str] = &["clippy", "rustfmt"];
112112

113113
pub fn is_known_tool(attr: &Attribute) -> bool {
114-
RUST_KNOWN_TOOL.contains(&attr.name().as_str().as_ref())
114+
let tool_name =
115+
attr.path.segments.iter().next().expect("empty path in attribute").identifier.name;
116+
RUST_KNOWN_TOOL.contains(&tool_name.as_str().as_ref())
115117
}
116118

117119
impl NestedMetaItem {
@@ -212,7 +214,7 @@ impl NestedMetaItem {
212214
}
213215

214216
fn name_from_path(path: &ast::Path) -> Name {
215-
path.segments.iter().next().unwrap().identifier.name
217+
path.segments.last().expect("empty path in attribute").identifier.name
216218
}
217219

218220
impl Attribute {
@@ -224,8 +226,8 @@ impl Attribute {
224226
matches
225227
}
226228

227-
/// Returns the first segment of the name of this attribute.
228-
/// E.g. `foo` for `#[foo]`, `rustfmt` for `#[rustfmt::skip]`.
229+
/// Returns the **last** segment of the name of this attribute.
230+
/// E.g. `foo` for `#[foo]`, `skip` for `#[rustfmt::skip]`.
229231
pub fn name(&self) -> Name {
230232
name_from_path(&self.path)
231233
}
@@ -1124,6 +1126,7 @@ impl MetaItem {
11241126
fn tokens(&self) -> TokenStream {
11251127
let mut idents = vec![];
11261128
let mut last_pos = BytePos(0 as u32);
1129+
// FIXME: Share code with `parse_path`.
11271130
for (i, segment) in self.name.segments.iter().enumerate() {
11281131
let is_first = i == 0;
11291132
if !is_first {

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ impl<'a> Context<'a> {
11271127
self.parse_sess.span_diagnostic,
11281128
attr.span,
11291129
E0693,
1130-
"An unkown tool name found in scoped attributes: `{}`.",
1130+
"An unknown tool name found in scoped attributes: `{}`.",
11311131
attr.path
11321132
);
11331133
}

src/test/compile-fail/unknown-tool-name.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#![feature(tool_attributes)]
1212

13-
#![foo::bar] //~ ERROR An unkown tool name found in scoped attributes: `foo::bar`. [E0693]
13+
#![foo::bar] //~ ERROR An unknown tool name found in scoped attributes: `foo::bar`. [E0693]
1414

15-
#[foo::bar] //~ ERROR An unkown tool name found in scoped attributes: `foo::bar`. [E0693]
15+
#[foo::bar] //~ ERROR An unknown tool name found in scoped attributes: `foo::bar`. [E0693]
1616
fn main() {}

src/test/compile-fail/unknown_tool_attributes-1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414

1515
#[foo::bar]
1616
//~^ ERROR scoped attribute `foo::bar` is experimental (see issue #44690) [E0658]
17-
//~^^ ERROR An unkown tool name found in scoped attributes: `foo::bar`. [E0693]
17+
//~^^ ERROR An unknown tool name found in scoped attributes: `foo::bar`. [E0693]
1818
fn main() {}

0 commit comments

Comments
 (0)