Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject raw lifetime followed by ', like regular lifetimes do #132341

Merged
merged 1 commit into from
Nov 9, 2024
Merged
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: 11 additions & 1 deletion compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,17 @@ impl Cursor<'_> {
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
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/lifetimes/raw/immediately-followed-by-lt.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 13 additions & 0 deletions tests/ui/lifetimes/raw/immediately-followed-by-lt.stderr
Original file line number Diff line number Diff line change
@@ -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