You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 72ccf9b
Browse filesBrowse the repository at this point in the historyBrowse files
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
Copy file name to clipboardExpand all lines: tests/ui/consts/const-pattern-irrefutable.stderr
+42-6Lines changed: 42 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
error[E0005]: refutable pattern in local binding
2
-
--> $DIR/const-pattern-irrefutable.rs:26:9
2
+
--> $DIR/const-pattern-irrefutable.rs:32:9
3
3
|
4
4
LL | const a: u8 = 2;
5
5
| ----------- missing patterns are not covered because `a` is interpreted as a constant pattern, not a new variable
@@ -16,7 +16,7 @@ LL | let a_var = 4;
16
16
| ++++
17
17
18
18
error[E0005]: refutable pattern in local binding
19
-
--> $DIR/const-pattern-irrefutable.rs:30:9
19
+
--> $DIR/const-pattern-irrefutable.rs:36:9
20
20
|
21
21
LL | pub const b: u8 = 2;
22
22
| --------------- missing patterns are not covered because `b` is interpreted as a constant pattern, not a new variable
@@ -34,7 +34,7 @@ LL + let b_var = 4;
34
34
|
35
35
36
36
error[E0005]: refutable pattern in local binding
37
-
--> $DIR/const-pattern-irrefutable.rs:34:9
37
+
--> $DIR/const-pattern-irrefutable.rs:40:9
38
38
|
39
39
LL | pub const d: (u8, u8) = (2, 1);
40
40
| --------------------- missing patterns are not covered because `d` is interpreted as a constant pattern, not a new variable
@@ -51,7 +51,7 @@ LL | let d_var = (4, 4);
51
51
| ++++
52
52
53
53
error[E0005]: refutable pattern in local binding
54
-
--> $DIR/const-pattern-irrefutable.rs:38:9
54
+
--> $DIR/const-pattern-irrefutable.rs:44:9
55
55
|
56
56
LL | const e: S = S {
57
57
| ---------- missing patterns are not covered because `e` is interpreted as a constant pattern, not a new variable
@@ -62,7 +62,7 @@ LL | let e = S {
62
62
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
63
63
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
64
64
note: `S` defined here
65
-
--> $DIR/const-pattern-irrefutable.rs:17:8
65
+
--> $DIR/const-pattern-irrefutable.rs:23:8
66
66
|
67
67
LL | struct S {
68
68
| ^
@@ -72,6 +72,42 @@ help: introduce a variable instead
72
72
LL | let e_var = S {
73
73
| ++++
74
74
75
-
error: aborting due to 4 previous errors
75
+
error[E0005]: refutable pattern in local binding
76
+
--> $DIR/const-pattern-irrefutable.rs:50:9
77
+
|
78
+
LL | const g: u8 = 2;
79
+
| ----------- missing patterns are not covered because `g` is interpreted as a constant pattern, not a new variable
80
+
...
81
+
LL | let r#g = 4;
82
+
| ^^^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
83
+
|
84
+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
85
+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
86
+
= note: the matched value is of type `u8`
87
+
help: introduce a variable instead
88
+
|
89
+
LL - let r#g = 4;
90
+
LL + let g_var = 4;
91
+
|
92
+
93
+
error[E0005]: refutable pattern in local binding
94
+
--> $DIR/const-pattern-irrefutable.rs:54:9
95
+
|
96
+
LL | const r#fn: u8 = 2;
97
+
| -------------- missing patterns are not covered because `r#fn` is interpreted as a constant pattern, not a new variable
98
+
...
99
+
LL | let r#fn = 4;
100
+
| ^^^^ patterns `0_u8..=1_u8` and `3_u8..=u8::MAX` not covered
101
+
|
102
+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
103
+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
104
+
= note: the matched value is of type `u8`
105
+
help: introduce a variable instead
106
+
|
107
+
LL - let r#fn = 4;
108
+
LL + let fn_var = 4;
109
+
|
110
+
111
+
error: aborting due to 6 previous errors
76
112
77
113
For more information about this error, try `rustc --explain E0005`.
0 commit comments