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:
parent
22e241e32e
commit
982918f493
13 changed files with 130 additions and 5 deletions
|
@ -46,7 +46,7 @@ impl<'a> Cursor<'a> {
|
|||
/// If requested position doesn't exist, `EOF_CHAR` is returned.
|
||||
/// However, getting `EOF_CHAR` doesn't always mean actual end of file,
|
||||
/// it should be checked with `is_eof` method.
|
||||
pub(crate) fn first(&self) -> char {
|
||||
pub fn first(&self) -> char {
|
||||
// `.next()` optimizes better than `.nth(0)`
|
||||
self.chars.clone().next().unwrap_or(EOF_CHAR)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue