diff --git a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs index 930f87e697c..a6c19f4032f 100644 --- a/compiler/rustc_attr_parsing/src/attributes/crate_level.rs +++ b/compiler/rustc_attr_parsing/src/attributes/crate_level.rs @@ -352,6 +352,10 @@ fn parse_register_tool( cx.adcx().expected_identifier(path.span()); continue; }; + if !ident.name.can_be_raw() { + cx.adcx().expected_identifier(path.span()); + continue; + } if ident.name == sym::rustc { cx.should_emit diff --git a/tests/ui/tool-attributes/invalid-tool.rs b/tests/ui/tool-attributes/invalid-tool.rs index aec31cc7f66..51bf9bdf4b0 100644 --- a/tests/ui/tool-attributes/invalid-tool.rs +++ b/tests/ui/tool-attributes/invalid-tool.rs @@ -2,5 +2,24 @@ #![register_tool(1)] //~^ ERROR malformed `register_tool` attribute input +#![register_tool(_)] +//~^ ERROR expected identifier, found reserved identifier `_` +//~| ERROR expected identifier, found reserved identifier `_` +//~| ERROR expected identifier, found reserved identifier `_` +//~| ERROR malformed `register_tool` attribute input + +// Special path keywords cannot be used. +#![register_tool(crate)] +//~^ ERROR malformed `register_tool` attribute input +#![register_tool(self)] +//~^ ERROR malformed `register_tool` attribute input +#![register_tool(Self)] +//~^ ERROR malformed `register_tool` attribute input +#![register_tool(super)] +//~^ ERROR malformed `register_tool` attribute input + +// These are okay +#![register_tool(r#type)] +#![register_tool(铁锈)] fn main() {} diff --git a/tests/ui/tool-attributes/invalid-tool.stderr b/tests/ui/tool-attributes/invalid-tool.stderr index b4e2c3e7eac..5d7742c45d2 100644 --- a/tests/ui/tool-attributes/invalid-tool.stderr +++ b/tests/ui/tool-attributes/invalid-tool.stderr @@ -1,3 +1,17 @@ +error: expected identifier, found reserved identifier `_` + --> $DIR/invalid-tool.rs:5:18 + | +LL | #![register_tool(_)] + | ^ expected identifier, found reserved identifier + +error: expected identifier, found reserved identifier `_` + --> $DIR/invalid-tool.rs:5:18 + | +LL | #![register_tool(_)] + | ^ expected identifier, found reserved identifier + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0565]: malformed `register_tool` attribute input --> $DIR/invalid-tool.rs:3:4 | @@ -12,6 +26,84 @@ LL - #![register_tool(1)] LL + #![register_tool(tool1, tool2, ...)] | -error: aborting due to 1 previous error +error: expected identifier, found reserved identifier `_` + --> $DIR/invalid-tool.rs:5:18 + | +LL | #![register_tool(_)] + | ^ expected identifier, found reserved identifier + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error[E0565]: malformed `register_tool` attribute input + --> $DIR/invalid-tool.rs:5:4 + | +LL | #![register_tool(_)] + | ^^^^^^^^^^^^^^-^ + | | + | expected a valid identifier here + | +help: must be of the form + | +LL - #![register_tool(_)] +LL + #![register_tool(tool1, tool2, ...)] + | + +error[E0565]: malformed `register_tool` attribute input + --> $DIR/invalid-tool.rs:12:4 + | +LL | #![register_tool(crate)] + | ^^^^^^^^^^^^^^-----^ + | | + | expected a valid identifier here + | +help: must be of the form + | +LL - #![register_tool(crate)] +LL + #![register_tool(tool1, tool2, ...)] + | + +error[E0565]: malformed `register_tool` attribute input + --> $DIR/invalid-tool.rs:14:4 + | +LL | #![register_tool(self)] + | ^^^^^^^^^^^^^^----^ + | | + | expected a valid identifier here + | +help: must be of the form + | +LL - #![register_tool(self)] +LL + #![register_tool(tool1, tool2, ...)] + | + +error[E0565]: malformed `register_tool` attribute input + --> $DIR/invalid-tool.rs:16:4 + | +LL | #![register_tool(Self)] + | ^^^^^^^^^^^^^^----^ + | | + | expected a valid identifier here + | +help: must be of the form + | +LL - #![register_tool(Self)] +LL + #![register_tool(tool1, tool2, ...)] + | + +error[E0565]: malformed `register_tool` attribute input + --> $DIR/invalid-tool.rs:18:4 + | +LL | #![register_tool(super)] + | ^^^^^^^^^^^^^^-----^ + | | + | expected a valid identifier here + | +help: must be of the form + | +LL - #![register_tool(super)] +LL + #![register_tool(tool1, tool2, ...)] + | + +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0565`.