Rollup merge of #122217 - estebank:issue-119685, r=fmease
Handle str literals written with `'` lexed as lifetime Given `'hello world'` and `'1 str', provide a structured suggestion for a valid string literal: ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-3.rs:2:26 | LL | println!('hello world'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("hello world"); | ~ ~ ``` ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-1.rs:2:20 | LL | println!('1 + 1'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("1 + 1"); | ~ ~ ``` Fix #119685.
This commit is contained in:
commit
1164c2725e
30 changed files with 250 additions and 70 deletions
|
@ -1987,6 +1987,17 @@ pub enum UnknownPrefixSugg {
|
|||
style = "verbose"
|
||||
)]
|
||||
Whitespace(#[primary_span] Span),
|
||||
#[multipart_suggestion(
|
||||
parse_suggestion_str,
|
||||
applicability = "maybe-incorrect",
|
||||
style = "verbose"
|
||||
)]
|
||||
MeantStr {
|
||||
#[suggestion_part(code = "\"")]
|
||||
start: Span,
|
||||
#[suggestion_part(code = "\"")]
|
||||
end: Span,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
@ -2198,12 +2209,21 @@ pub enum MoreThanOneCharSugg {
|
|||
ch: String,
|
||||
},
|
||||
#[suggestion(parse_use_double_quotes, code = "{sugg}", applicability = "machine-applicable")]
|
||||
Quotes {
|
||||
QuotesFull {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
is_byte: bool,
|
||||
sugg: String,
|
||||
},
|
||||
#[multipart_suggestion(parse_use_double_quotes, applicability = "machine-applicable")]
|
||||
Quotes {
|
||||
#[suggestion_part(code = "{prefix}\"")]
|
||||
start: Span,
|
||||
#[suggestion_part(code = "\"")]
|
||||
end: Span,
|
||||
is_byte: bool,
|
||||
prefix: &'static str,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue