attrs with curlys are not allowed
Summary
see https://doc.rust-lang.org/reference/attributes.html
Reproducer
I tried this code:
#![allow{ unused }]
fn main() {}
Does the code make use of any (1.49) nightly feature ?
- [ ] Nightly
Godbolt link
No response
Actual behavior
The current behavior is...
no error with ~/vcs/github/gccrs/gccrs-build/gcc/crab1 -frust-incomplete-and-experimental-compiler-do-not-use "-frust-crate-attr=no_core" "-frust-crate-attr=feature(no_core)"
Expected behavior
I expected to see...
code should be rejected.
rustc:
error: wrong meta list delimiters
--> 1771152754800445475.rs:1:9
|
1 | #![allow{ unused }]
| ^^^^^^^^^^^
|
help: the delimiters should be `(` and `)`
|
1 - #![allow{ unused }]
1 + #![allow( unused )]
|
error: aborting due to 1 previous error
GCC Version
0c3711b3e1a7771032351e99db617e27c719deae
I tried the examples below for comparing rustc and crab1:
crab1 version rustc version: 1.98.0
Example 1
#![allow<unused>]
fn main() {}
Example 2:
#![allow{unused}]
fn main() {}
Tried with both rustc and crab1:
rustc expects one of the following:
rustc attrs.rs
error: expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `<`
--> attrs.rs:1:9
|
1 | #![allow<unused>]
| ^ expected one of `(`, `::`, `=`, `[`, `]`, or `{`
crab1:
./gcc/crab1 ../tests/attrs.rs -frust-incomplete-and-experimental-compiler-do-not-use "-frust-crate-attr=no_core" "-frust-crate-attr=feature(no_core)"
If any other token is used like in Example 1, it gives us
error: unknown token '<' in attribute body - attribute input or none expected
It continues "parsing" until the EOL and gives us another error `error: unrecognized token ']' for start of item
rustc stops parsing on the '<' itself while crab1 continues parsing. While for wrong braces ( '{' or '[' ) rustc mentions the correct braces to be used while crab1 doesn't error.
Conclusion:
AFAIK 2 cases need to be handled:
- parse only the correct brace i.e. '(' and notify the correct pattern to be used for other types of brace ( '[' and '{' )
- for anything other than the specified tokens, provide the correct info on the expected characters
Some notes:
- During AST creation, rustc takes the delimiter '{' without any error. During the AST validation check is where we get the error for wrong delimiter. It is handled in validate_attrs.rs
- The rust grammar also allows curly as it expects a DelimTokenTree. Grammar