-
Notifications
You must be signed in to change notification settings - Fork 12.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: suggest quotes only for ident attribute values
When encountering code like: ``` #[cfg(key = ["foo", "bar"])] fn main() {} ``` the parser incorrectly suggests: ``` error: expected unsuffixed literal, found `[` --> ../pg/src/main.rs:1:13 | 1 | #[cfg(key = ["foo", "bar"])] | ^ | help: surround the identifier with quotation marks to parse it as a string | 1 | #[cfg(key =" "["foo", "bar"])] | + + error: aborting due to 1 previous error ``` This commit modifies the parser to check if an attribute value is an ident before suggesting.
- Loading branch information
Showing
3 changed files
with
36 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
tests/ui/attributes/suggest_quoting_values_only_for_idents.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Ensures to suggest quoting attribute values only when they are identifiers. | ||
|
||
#[doc(alias = "val")] | ||
#[doc(alias = val)] //~ ERROR expected unsuffixed literal, found `val` | ||
#[doc(alias = ["va", "al"])] //~ ERROR expected unsuffixed literal or identifier, found `[` | ||
#[doc(alias = &["va", "al"])] //~ ERROR expected unsuffixed literal or identifier, found `&` | ||
fn main() {} |
25 changes: 25 additions & 0 deletions
25
tests/ui/attributes/suggest_quoting_values_only_for_idents.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
error: expected unsuffixed literal, found `val` | ||
--> $DIR/suggest_quoting_values_only_for_idents.rs:4:15 | ||
| | ||
LL | #[doc(alias = val)] | ||
| ^^^ | ||
| | ||
help: surround the identifier with quotation marks to parse it as a string | ||
| | ||
LL | #[doc(alias = "val")] | ||
| + + | ||
|
||
error: expected unsuffixed literal or identifier, found `[` | ||
--> $DIR/suggest_quoting_values_only_for_idents.rs:5:15 | ||
| | ||
LL | #[doc(alias = ["va", "al"])] | ||
| ^ | ||
|
||
error: expected unsuffixed literal or identifier, found `&` | ||
--> $DIR/suggest_quoting_values_only_for_idents.rs:6:15 | ||
| | ||
LL | #[doc(alias = &["va", "al"])] | ||
| ^ | ||
|
||
error: aborting due to 3 previous errors | ||
|