Rollup merge of #156797 - ariagivens:suggest-quotes, r=JonathanBrouwer

Suggest adding quotation marks to identifiers in attributes

When the user provides an identifier when a literal was expected in an attribute value, suggest adding quotation marks to the identifier to make it a string literal.

For instance:
```
error: attribute value must be a literal
  --> $DIR/crate-type-non-crate.rs:9:16
   |
LL | #[crate_type = lib]
   |                ^^^ help: try adding quotation marks: `"lib"`
```
This commit is contained in:
Matthias Krüger
2026-05-28 07:53:36 +02:00
committed by GitHub
4 changed files with 22 additions and 9 deletions
@@ -40,7 +40,7 @@ error: attribute value must be a literal
--> $DIR/crate-type-non-crate.rs:9:16
|
LL | #[crate_type = lib]
| ^^^
| ^^^ help: try adding quotation marks: `"lib"`
error[E0539]: malformed `crate_type` attribute input
--> $DIR/crate-type-non-crate.rs:12:1
@@ -72,7 +72,7 @@ error: attribute value must be a literal
--> $DIR/crate-type-non-crate.rs:14:16
|
LL | #[crate_type = foo]
| ^^^
| ^^^ help: try adding quotation marks: `"foo"`
error[E0539]: malformed `crate_type` attribute input
--> $DIR/crate-type-non-crate.rs:17:1
@@ -2,7 +2,7 @@ error: attribute value must be a literal
--> $DIR/validation-on-associated-items-issue-121537.rs:2:13
|
LL | #[doc = MyTrait]
| ^^^^^^^
| ^^^^^^^ help: try adding quotation marks: `"MyTrait"`
error: aborting due to 1 previous error
@@ -2,13 +2,13 @@ error: attribute value must be a literal
--> $DIR/darwin-objc-bad-arg.rs:12:18
|
LL | objc::class!(s);
| ^
| ^ help: try adding quotation marks: `"s"`
error: attribute value must be a literal
--> $DIR/darwin-objc-bad-arg.rs:15:18
|
LL | objc::class!(NSObject);
| ^^^^^^^^
| ^^^^^^^^ help: try adding quotation marks: `"NSObject"`
error: `objc::class!` expected a string literal
--> $DIR/darwin-objc-bad-arg.rs:18:18
@@ -26,13 +26,13 @@ error: attribute value must be a literal
--> $DIR/darwin-objc-bad-arg.rs:25:21
|
LL | objc::selector!(s);
| ^
| ^ help: try adding quotation marks: `"s"`
error: attribute value must be a literal
--> $DIR/darwin-objc-bad-arg.rs:28:21
|
LL | objc::selector!(alloc);
| ^^^^^
| ^^^^^ help: try adding quotation marks: `"alloc"`
error: `objc::selector!` expected a string literal
--> $DIR/darwin-objc-bad-arg.rs:31:21