Skip to content

Commit 1990f15

Browse files
Reject raw lifetime followed by \' as well
1 parent 3f1be1e commit 1990f15

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

compiler/rustc_lexer/src/lib.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,17 @@ impl Cursor<'_> {
715715
self.bump();
716716
self.bump();
717717
self.eat_while(is_id_continue);
718-
return RawLifetime;
718+
match self.first() {
719+
'\'' => {
720+
// Check if after skipping literal contents we've met a closing
721+
// single quote (which means that user attempted to create a
722+
// string with single quotes).
723+
self.bump();
724+
let kind = Char { terminated: true };
725+
return Literal { kind, suffix_start: self.pos_within_token() };
726+
}
727+
_ => return RawLifetime,
728+
}
719729
}
720730

721731
// Either a lifetime or a character literal with
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//@ edition: 2021
2+
3+
// Make sure we reject the case where a raw lifetime is immediately followed by another
4+
// lifetime. This reserves a modest amount of space for changing lexing to, for example,
5+
// delay rejection of overlong char literals like `'r#long'id`.
6+
7+
macro_rules! w {
8+
($($tt:tt)*) => {}
9+
}
10+
11+
w!('r#long'id);
12+
//~^ ERROR character literal may only contain one codepoint
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error: character literal may only contain one codepoint
2+
--> $DIR/immediately-followed-by-lt.rs:11:4
3+
|
4+
LL | w!('r#long'id);
5+
| ^^^^^^^^
6+
|
7+
help: if you meant to write a string literal, use double quotes
8+
|
9+
LL | w!("r#long"id);
10+
| ~ ~
11+
12+
error: aborting due to 1 previous error
13+

0 commit comments

Comments
 (0)