Reject raw lifetime followed by \' as well
This commit is contained in:
parent
3f1be1ec7e
commit
1990f15608
@ -715,7 +715,17 @@ fn lifetime_or_char(&mut self) -> TokenKind {
|
||||
self.bump();
|
||||
self.bump();
|
||||
self.eat_while(is_id_continue);
|
||||
return RawLifetime;
|
||||
match self.first() {
|
||||
'\'' => {
|
||||
// Check if after skipping literal contents we've met a closing
|
||||
// single quote (which means that user attempted to create a
|
||||
// string with single quotes).
|
||||
self.bump();
|
||||
let kind = Char { terminated: true };
|
||||
return Literal { kind, suffix_start: self.pos_within_token() };
|
||||
}
|
||||
_ => return RawLifetime,
|
||||
}
|
||||
}
|
||||
|
||||
// Either a lifetime or a character literal with
|
||||
|
14
tests/ui/lifetimes/raw/immediately-followed-by-lt.rs
Normal file
14
tests/ui/lifetimes/raw/immediately-followed-by-lt.rs
Normal file
@ -0,0 +1,14 @@
|
||||
//@ edition: 2021
|
||||
|
||||
// Make sure we reject the case where a raw lifetime is immediately followed by another
|
||||
// lifetime. This reserves a modest amount of space for changing lexing to, for example,
|
||||
// delay rejection of overlong char literals like `'r#long'id`.
|
||||
|
||||
macro_rules! w {
|
||||
($($tt:tt)*) => {}
|
||||
}
|
||||
|
||||
w!('r#long'id);
|
||||
//~^ ERROR character literal may only contain one codepoint
|
||||
|
||||
fn main() {}
|
13
tests/ui/lifetimes/raw/immediately-followed-by-lt.stderr
Normal file
13
tests/ui/lifetimes/raw/immediately-followed-by-lt.stderr
Normal file
@ -0,0 +1,13 @@
|
||||
error: character literal may only contain one codepoint
|
||||
--> $DIR/immediately-followed-by-lt.rs:11:4
|
||||
|
|
||||
LL | w!('r#long'id);
|
||||
| ^^^^^^^^
|
||||
|
|
||||
help: if you meant to write a string literal, use double quotes
|
||||
|
|
||||
LL | w!("r#long"id);
|
||||
| ~ ~
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
Loading…
Reference in New Issue
Block a user