Skip to content

Commit 23bcea4

Browse files
committed
Add help suggesting matches to let_chains lint
1 parent e62a543 commit 23bcea4

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,11 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
639639
};
640640
}
641641
gate_all!(if_let_guard, "`if let` guards are experimental");
642-
gate_all!(let_chains, "`let` expressions in this position are experimental");
642+
gate_all!(
643+
let_chains,
644+
"`let` expressions in this position are experimental",
645+
"you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`"
646+
);
643647
gate_all!(
644648
async_closure,
645649
"async closures are unstable",

src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ LL | () if (let 0 = 1) => {}
3333
|
3434
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
3535
= help: add `#![feature(let_chains)]` to the crate attributes to enable
36+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
3637

3738
error[E0658]: `let` expressions in this position are experimental
3839
--> $DIR/feature-gate.rs:14:18
@@ -42,6 +43,7 @@ LL | () if (((let 0 = 1))) => {}
4243
|
4344
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
4445
= help: add `#![feature(let_chains)]` to the crate attributes to enable
46+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
4547

4648
error[E0658]: `let` expressions in this position are experimental
4749
--> $DIR/feature-gate.rs:18:23
@@ -51,6 +53,7 @@ LL | () if true && let 0 = 1 => {}
5153
|
5254
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
5355
= help: add `#![feature(let_chains)]` to the crate attributes to enable
56+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
5457

5558
error[E0658]: `let` expressions in this position are experimental
5659
--> $DIR/feature-gate.rs:22:15
@@ -60,6 +63,7 @@ LL | () if let 0 = 1 && true => {}
6063
|
6164
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
6265
= help: add `#![feature(let_chains)]` to the crate attributes to enable
66+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
6367

6468
error[E0658]: `let` expressions in this position are experimental
6569
--> $DIR/feature-gate.rs:26:16
@@ -69,6 +73,7 @@ LL | () if (let 0 = 1) && true => {}
6973
|
7074
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
7175
= help: add `#![feature(let_chains)]` to the crate attributes to enable
76+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
7277

7378
error[E0658]: `let` expressions in this position are experimental
7479
--> $DIR/feature-gate.rs:30:24
@@ -78,6 +83,7 @@ LL | () if true && (let 0 = 1) => {}
7883
|
7984
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
8085
= help: add `#![feature(let_chains)]` to the crate attributes to enable
86+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
8187

8288
error[E0658]: `let` expressions in this position are experimental
8389
--> $DIR/feature-gate.rs:34:16
@@ -87,6 +93,7 @@ LL | () if (let 0 = 1) && (let 0 = 1) => {}
8793
|
8894
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
8995
= help: add `#![feature(let_chains)]` to the crate attributes to enable
96+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
9097

9198
error[E0658]: `let` expressions in this position are experimental
9299
--> $DIR/feature-gate.rs:34:31
@@ -96,6 +103,7 @@ LL | () if (let 0 = 1) && (let 0 = 1) => {}
96103
|
97104
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
98105
= help: add `#![feature(let_chains)]` to the crate attributes to enable
106+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
99107

100108
error[E0658]: `let` expressions in this position are experimental
101109
--> $DIR/feature-gate.rs:40:15
@@ -105,6 +113,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
105113
|
106114
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
107115
= help: add `#![feature(let_chains)]` to the crate attributes to enable
116+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
108117

109118
error[E0658]: `let` expressions in this position are experimental
110119
--> $DIR/feature-gate.rs:40:28
@@ -114,6 +123,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
114123
|
115124
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
116125
= help: add `#![feature(let_chains)]` to the crate attributes to enable
126+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
117127

118128
error[E0658]: `let` expressions in this position are experimental
119129
--> $DIR/feature-gate.rs:40:42
@@ -123,6 +133,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
123133
|
124134
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
125135
= help: add `#![feature(let_chains)]` to the crate attributes to enable
136+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
126137

127138
error[E0658]: `let` expressions in this position are experimental
128139
--> $DIR/feature-gate.rs:40:55
@@ -132,6 +143,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
132143
|
133144
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
134145
= help: add `#![feature(let_chains)]` to the crate attributes to enable
146+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
135147

136148
error[E0658]: `let` expressions in this position are experimental
137149
--> $DIR/feature-gate.rs:40:68
@@ -141,6 +153,7 @@ LL | () if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 =
141153
|
142154
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
143155
= help: add `#![feature(let_chains)]` to the crate attributes to enable
156+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
144157

145158
error[E0658]: `let` expressions in this position are experimental
146159
--> $DIR/feature-gate.rs:52:15
@@ -150,6 +163,7 @@ LL | () if let Range { start: _, end: _ } = (true..true) && false => {}
150163
|
151164
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
152165
= help: add `#![feature(let_chains)]` to the crate attributes to enable
166+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
153167

154168
error[E0658]: `let` expressions in this position are experimental
155169
--> $DIR/feature-gate.rs:68:16
@@ -159,6 +173,7 @@ LL | use_expr!((let 0 = 1 && 0 == 0));
159173
|
160174
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
161175
= help: add `#![feature(let_chains)]` to the crate attributes to enable
176+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
162177

163178
error[E0658]: `let` expressions in this position are experimental
164179
--> $DIR/feature-gate.rs:71:16
@@ -168,6 +183,7 @@ LL | use_expr!((let 0 = 1));
168183
|
169184
= note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information
170185
= help: add `#![feature(let_chains)]` to the crate attributes to enable
186+
= help: you can write `matches!(<expr>, <pattern>)` instead of `let <pattern> = <expr>`
171187

172188
error: `let` expressions are not supported here
173189
--> $DIR/feature-gate.rs:10:16

0 commit comments

Comments
 (0)