Files
rust/tests/ui/consts/const-pattern-irrefutable.stderr
albab-hasan 5e86855354 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 https://github.com/rust-lang/rust/issues/162949
2026-09-21 17:13:27 +06:00

114 lines
4.3 KiB
Plaintext

error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:32:9
|
LL | const a: u8 = 2;
| ----------- missing patterns are not covered because `a` is interpreted as a constant pattern, not a new variable
...
LL | let a = 4;
| ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
= note: the matched value is of type `u8`
help: introduce a variable instead
|
LL | let a_var = 4;
| ++++
error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:36:9
|
LL | pub const b: u8 = 2;
| --------------- missing patterns are not covered because `b` is interpreted as a constant pattern, not a new variable
...
LL | let c = 4;
| ^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
= note: the matched value is of type `u8`
help: introduce a variable instead
|
LL - let c = 4;
LL + let b_var = 4;
|
error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:40:9
|
LL | pub const d: (u8, u8) = (2, 1);
| --------------------- missing patterns are not covered because `d` is interpreted as a constant pattern, not a new variable
...
LL | let d = (4, 4);
| ^ patterns `(0_u8..=1_u8, _)` and `(3_u8..=u8::MAX, _)` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
= note: the matched value is of type `(u8, u8)`
help: introduce a variable instead
|
LL | let d_var = (4, 4);
| ++++
error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:44:9
|
LL | const e: S = S {
| ---------- missing patterns are not covered because `e` is interpreted as a constant pattern, not a new variable
...
LL | let e = S {
| ^ pattern `S { foo: 1_u8..=u8::MAX }` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
note: `S` defined here
--> $DIR/const-pattern-irrefutable.rs:23:8
|
LL | struct S {
| ^
= note: the matched value is of type `S`
help: introduce a variable instead
|
LL | let e_var = S {
| ++++
error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:50:9
|
LL | const g: u8 = 2;
| ----------- missing patterns are not covered because `g` is interpreted as a constant pattern, not a new variable
...
LL | let r#g = 4;
| ^^^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
= note: the matched value is of type `u8`
help: introduce a variable instead
|
LL - let r#g = 4;
LL + let g_var = 4;
|
error[E0005]: refutable pattern in local binding
--> $DIR/const-pattern-irrefutable.rs:54:9
|
LL | const r#fn: u8 = 2;
| -------------- missing patterns are not covered because `r#fn` is interpreted as a constant pattern, not a new variable
...
LL | let r#fn = 4;
| ^^^^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
|
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
= note: the matched value is of type `u8`
help: introduce a variable instead
|
LL - let r#fn = 4;
LL + let fn_var = 4;
|
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0005`.