Reject invalid identifiers in register_tool

Forbid super/crate/self/Self to be used in register_tool.
Also, add test for raw identifier and unicode identifiers.
This commit is contained in:
Gary Guo
2026-07-29 12:49:14 +01:00
parent 0c06c43db7
commit 6436f0c4e8
3 changed files with 116 additions and 1 deletions

View File

@@ -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

View File

@@ -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() {}

View File

@@ -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`.