Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,14 @@ fn expr_to_lit<'sess>(

// Suggest adding quotation marks to turn an identifier into a string literal
if let ExprKind::Path(None, ref path) = expr.kind
&& let [segment] = path.segments.as_slice()
&& let [_] = path.segments.as_slice()
{
err.span_suggestion(
expr.span,
"try adding quotation marks",
&format!("\"{}\"", segment.ident),
err.multipart_suggestion(
"you might have meant to write a string literal",
vec![
(expr.span.shrink_to_lo(), "\"".to_string()),
(expr.span.shrink_to_hi(), "\"".to_string()),
],
Applicability::MaybeIncorrect,
);
}
Expand Down
14 changes: 12 additions & 2 deletions tests/ui/attributes/crate-type-non-crate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ 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"`
| ^^^
|
help: you might have meant to write a string literal
|
LL | #[crate_type = "lib"]
| + +

error[E0539]: malformed `crate_type` attribute input
--> $DIR/crate-type-non-crate.rs:12:1
Expand Down Expand Up @@ -72,7 +77,12 @@ 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"`
| ^^^
|
help: you might have meant to write a string literal
|
LL | #[crate_type = "foo"]
| + +

error[E0539]: malformed `crate_type` attribute input
--> $DIR/crate-type-non-crate.rs:17:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ 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"`
| ^^^^^^^
|
help: you might have meant to write a string literal
|
LL | #[doc = "MyTrait"]
| + +

error: aborting due to 1 previous error

Loading