emit the constant pattern note for raw identifier bindings - #163106
Merged
rust-bors[bot] merged 1 commit intoSep 22, 2026
Merged
Conversation
`is_const_pat_that_looks_like_binding` matched the pattern snippet against a plain identifier so the `#` in `let r#x = 0` rejected it and the binding lost both the label pointing at `const x` and the `introduce a variable instead` suggestion. strip a leading `r#` before the check and render the const name with `to_ident_string` in the label so a keyword name prints as `r#fn`. fixes rust-lang#162949
Collaborator
|
Some changes occurred in match checking cc @Nadrieril |
oli-obk
approved these changes
Sep 22, 2026
Comment on lines
+16
to
+21
| const g: u8 = 2; | ||
| //~^ NOTE missing patterns are not covered because `g` is interpreted as a constant pattern, not a new variable | ||
|
|
||
| const r#fn: u8 = 2; | ||
| //~^ NOTE missing patterns are not covered because `r#fn` is interpreted as a constant pattern, not a new variable | ||
|
|
Contributor
There was a problem hiding this comment.
not necessary to fix here, but in the future, you can first create a commit that shows the old diagnostic behaviour with a test like this, and then, in a second commit fix it, showing what changes with your fix.
Contributor
Author
There was a problem hiding this comment.
ill keep that in mind. thanks for the approval.
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Sep 22, 2026
…-idents, r=oli-obk emit the constant pattern note for raw identifier bindings `is_const_pat_that_looks_like_binding` matched the pattern snippet against a plain identifier so the `#` in `let r#x = 0` rejected it and the binding lost both the label pointing at `const x` and the `introduce a variable instead` suggestion. strip a leading `r#` before the check and render the const name with `to_ident_string` in the label so a keyword name prints as `r#fn`. fixes rust-lang#162949 r? @oli-obk
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Sep 22, 2026
…-idents, r=oli-obk emit the constant pattern note for raw identifier bindings `is_const_pat_that_looks_like_binding` matched the pattern snippet against a plain identifier so the `#` in `let r#x = 0` rejected it and the binding lost both the label pointing at `const x` and the `introduce a variable instead` suggestion. strip a leading `r#` before the check and render the const name with `to_ident_string` in the label so a keyword name prints as `r#fn`. fixes rust-lang#162949 r? @oli-obk
This was referenced Sep 22, 2026
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 22, 2026
…uwer Rollup of 7 pull requests Successful merges: - #147876 (Check tainted_by_error in LateLint) - #162998 (Avoid generating overlapping assignments in DSE) - #163136 (library: prune allowed lints) - #163102 (remove unnecessary restriction with next-solver) - #163106 (emit the constant pattern note for raw identifier bindings) - #163118 (add `feature(field_projections)` fixme) - #163148 (Clean up diagnostic hashing)
rust-bors Bot
pushed a commit
that referenced
this pull request
Sep 22, 2026
Rollup merge of #163106 - Albab-Hasan:const-pattern-note-raw-idents, r=oli-obk emit the constant pattern note for raw identifier bindings `is_const_pat_that_looks_like_binding` matched the pattern snippet against a plain identifier so the `#` in `let r#x = 0` rejected it and the binding lost both the label pointing at `const x` and the `introduce a variable instead` suggestion. strip a leading `r#` before the check and render the const name with `to_ident_string` in the label so a keyword name prints as `r#fn`. fixes #162949 r? @oli-obk
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
is_const_pat_that_looks_like_bindingmatched the pattern snippet against a plain identifier so the#inlet r#x = 0rejected it and the binding lost both the label pointing atconst xand theintroduce a variable insteadsuggestion. strip a leadingr#before the check and render the const name withto_ident_stringin the label so a keyword name prints asr#fn.fixes #162949
r? @oli-obk