-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Fix and improve diagnostics for lint rust_2021_prefixes_incompatible_syntax
#161792
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
Merged
rust-bors
merged 3 commits into
rust-lang:main
from
fmease:fix-reserved-prefixes-lint-diags
Aug 31, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,12 +1,18 @@ | ||
| //@ edition: 2015 | ||
| // Ensure that we parse `'r#lt` as three tokens pre Rust 2021. | ||
| // Moreover, make sure we emit the relevant migration lint. | ||
|
|
||
| //@ edition: 2015..2021 | ||
| //@ check-pass | ||
| // Ensure that we parse `'r#lt` as three tokens in edition 2015. | ||
|
|
||
| macro_rules! ed2015 { | ||
| #![warn(rust_2021_prefixes_incompatible_syntax)] | ||
|
|
||
| macro_rules! check { | ||
| ('r # lt) => {}; | ||
| ($lt:lifetime) => { compile_error!() }; | ||
| } | ||
|
|
||
| ed2015!('r#lt); | ||
| check!('r#lt); | ||
| //~^ WARNING parsed as a prefix in Rust 2021 and onward | ||
| //~| WARNING this changes meaning in Rust 2021 | ||
|
|
||
| fn main() {} |
This file contains hidden or 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,20 @@ | ||
| warning: `r` is parsed as a prefix in Rust 2021 and onward | ||
| --> $DIR/three-tokens.rs:14:8 | ||
| | | ||
| LL | check!('r#lt); | ||
| | ^^ | ||
| | | ||
| = warning: this changes meaning in Rust 2021 | ||
| = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/reserving-syntax.html> | ||
| note: the lint level is defined here | ||
| --> $DIR/three-tokens.rs:7:9 | ||
| | | ||
| LL | #![warn(rust_2021_prefixes_incompatible_syntax)] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| help: consider inserting whitespace here to avoid this | ||
| | | ||
| LL | check!('r #lt); | ||
| | + | ||
|
|
||
| warning: 1 warning emitted | ||
|
|
24 changes: 0 additions & 24 deletions
24
tests/ui/rfcs/rfc-3348-c-string-literals/edition-2015-2018-lexing.rs
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
tests/ui/rfcs/rfc-3348-c-string-literals/pre-2021-lexing.rs
This file contains hidden or 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,38 @@ | ||
| // Prefixes including `c` as used by C string literals are only reserved in Rust 2021 and onward. | ||
| // Exercise what happens pre Rust 2021 with C string literal "lookalikes". | ||
|
|
||
| //@ check-pass | ||
| //@ edition: 2015..2021 | ||
|
|
||
| #![warn(rust_2021_prefixes_incompatible_syntax)] | ||
|
|
||
| fn main() { | ||
| // Make sure that pre Rust 2021 editions we continue to parse the snippet | ||
| // `c"hello"` as an identifier followed by a (normal) string literal and | ||
| // allow the code below to compile. | ||
| // | ||
| // issue: <https://github.com/rust-lang/rust/issues/113235> | ||
|
|
||
| // Moreover, make sure we emit the relevant edition migration lint with an appropriate | ||
| // diagnostic (for a period of time we used to incorrectly state prefix `c` was unknown and | ||
| // that the token sequence would unconditionally lead to a hard error in the next edition). | ||
|
|
||
| macro_rules! parse { | ||
| (c $e:expr) => { | ||
| $e | ||
| }; | ||
| } | ||
|
|
||
| let _: &'static str = parse!(c"hello"); | ||
| //~^ WARNING parsed as a C string literal in Rust 2021 and onward | ||
| //~| WARNING this changes meaning in Rust 2021 | ||
|
|
||
| macro_rules! indifferent { | ||
| ($e:expr) => {}; | ||
| (c $e:expr) => {}; | ||
| } | ||
|
|
||
| indifferent!(c"..."); | ||
| //~^ WARNING parsed as a C string literal in Rust 2021 and onward | ||
| //~| WARNING this changes meaning in Rust 2021 | ||
| } |
33 changes: 33 additions & 0 deletions
33
tests/ui/rfcs/rfc-3348-c-string-literals/pre-2021-lexing.stderr
This file contains hidden or 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,33 @@ | ||
| warning: this is parsed as a C string literal in Rust 2021 and onward | ||
| --> $DIR/pre-2021-lexing.rs:26:34 | ||
| | | ||
| LL | let _: &'static str = parse!(c"hello"); | ||
| | ^^^^^^^^ | ||
| | | ||
| = warning: this changes meaning in Rust 2021 | ||
| = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/reserving-syntax.html> | ||
| note: the lint level is defined here | ||
| --> $DIR/pre-2021-lexing.rs:7:9 | ||
| | | ||
| LL | #![warn(rust_2021_prefixes_incompatible_syntax)] | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| help: consider inserting whitespace here to avoid this | ||
| | | ||
| LL | let _: &'static str = parse!(c "hello"); | ||
| | + | ||
|
|
||
| warning: this is parsed as a C string literal in Rust 2021 and onward | ||
| --> $DIR/pre-2021-lexing.rs:35:18 | ||
| | | ||
| LL | indifferent!(c"..."); | ||
| | ^^^^^^ | ||
| | | ||
| = warning: this changes meaning in Rust 2021 | ||
| = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/reserving-syntax.html> | ||
| help: consider inserting whitespace here to avoid this | ||
| | | ||
| LL | indifferent!(c "..."); | ||
| | + | ||
|
|
||
| warning: 2 warnings emitted | ||
|
|
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.