forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#132341 - compiler-errors:raw-lt-prefix-id, …
…r=chenyukang Reject raw lifetime followed by `'`, like regular lifetimes do See comment. We want to reject cases like `'r#long'id`, which currently gets interpreted as a raw lifetime (`'r#long`) followed by a lifetime (`'id`). This could have alternative lexes, such as an overlong char literal (`'r#long'`) followed by an identifier (`id`). To avoid committing to this in any case, let's reject the whole thing. `@mattheww,` is this what you were looking for in rust-lang/reference#1603 (comment)? I'd say ignore the details about the specific error message (the fact that this gets reinterpreted as a char literal is 🤷), just that because this causes a lexer error we're effectively saving syntactical space like you wanted.
- Loading branch information
Showing
3 changed files
with
38 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|