Skip to content

emit the constant pattern note for raw identifier bindings - #163106

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Albab-Hasan:const-pattern-note-raw-idents
Sep 22, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Albab-Hasan:const-pattern-note-raw-idents

Conversation

@Albab-Hasan

Copy link
Copy Markdown
Contributor

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

`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
@rustbot

rustbot commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in match checking

cc @Nadrieril

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 21, 2026

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ill keep that in mind. thanks for the approval.

@rust-bors

rust-bors Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 5e86855 has been approved by oli-obk

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2026
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
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
rust-bors Bot merged commit 72ccf9b into rust-lang:main Sep 22, 2026
13 checks passed
@rustbot rustbot added this to the 1.100.0 milestone Sep 22, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing "interpreted as a constant pattern" note for raw identifiers in local bindings

3 participants