Skip to content

Commit c3a998e

Browse files
committed
Do not suggest let_else if no bindings would be introduced
1 parent 0d92752 commit c3a998e

7 files changed

+1
-45
lines changed

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {
330330
],
331331
Applicability::HasPlaceholders,
332332
);
333-
if cx.tcx.sess.is_nightly_build() {
333+
if !bindings.is_empty() && cx.tcx.sess.is_nightly_build() {
334334
err.span_suggestion_verbose(
335335
semi_span.shrink_to_lo(),
336336
&format!(

src/test/ui/consts/const-match-check.eval1.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
1111
|
1212
LL | A = { if let 0 = 0 { todo!() } 0 },
1313
| ++ ~~~~~~~~~~~
14-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
15-
|
16-
LL | A = { let 0 = 0 else { todo!() }; 0 },
17-
| ++++++++++++++++
1814

1915
error: aborting due to previous error
2016

src/test/ui/consts/const-match-check.eval2.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
1111
|
1212
LL | let x: [i32; { if let 0 = 0 { todo!() } 0 }] = [];
1313
| ++ ~~~~~~~~~~~
14-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
15-
|
16-
LL | let x: [i32; { let 0 = 0 else { todo!() }; 0 }] = [];
17-
| ++++++++++++++++
1814

1915
error: aborting due to previous error
2016

src/test/ui/consts/const-match-check.matchck.stderr

-16
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
1111
|
1212
LL | const X: i32 = { if let 0 = 0 { todo!() } 0 };
1313
| ++ ~~~~~~~~~~~
14-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
15-
|
16-
LL | const X: i32 = { let 0 = 0 else { todo!() }; 0 };
17-
| ++++++++++++++++
1814

1915
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered
2016
--> $DIR/const-match-check.rs:8:23
@@ -29,10 +25,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
2925
|
3026
LL | static Y: i32 = { if let 0 = 0 { todo!() } 0 };
3127
| ++ ~~~~~~~~~~~
32-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
33-
|
34-
LL | static Y: i32 = { let 0 = 0 else { todo!() }; 0 };
35-
| ++++++++++++++++
3628

3729
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered
3830
--> $DIR/const-match-check.rs:13:26
@@ -47,10 +39,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
4739
|
4840
LL | const X: i32 = { if let 0 = 0 { todo!() } 0 };
4941
| ++ ~~~~~~~~~~~
50-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
51-
|
52-
LL | const X: i32 = { let 0 = 0 else { todo!() }; 0 };
53-
| ++++++++++++++++
5442

5543
error[E0005]: refutable pattern in local binding: `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered
5644
--> $DIR/const-match-check.rs:19:26
@@ -65,10 +53,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
6553
|
6654
LL | const X: i32 = { if let 0 = 0 { todo!() } 0 };
6755
| ++ ~~~~~~~~~~~
68-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
69-
|
70-
LL | const X: i32 = { let 0 = 0 else { todo!() }; 0 };
71-
| ++++++++++++++++
7256

7357
error: aborting due to 4 previous errors
7458

src/test/ui/or-patterns/issue-69875-should-have-been-expanded-earlier-non-exhaustive.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
1111
|
1212
LL | if let (0 | (1 | 2)) = 0 { todo!() }
1313
| ++ ~~~~~~~~~~~
14-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
15-
|
16-
LL | let (0 | (1 | 2)) = 0 else { todo!() };
17-
| ++++++++++++++++
1814

1915
error[E0004]: non-exhaustive patterns: `i32::MIN..=-1_i32` and `3_i32..=i32::MAX` not covered
2016
--> $DIR/issue-69875-should-have-been-expanded-earlier-non-exhaustive.rs:3:11

src/test/ui/pattern/usefulness/non-exhaustive-defined-here.stderr

-12
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
4646
|
4747
LL | if let E::A = e { todo!() }
4848
| ++ ~~~~~~~~~~~
49-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
50-
|
51-
LL | let E::A = e else { todo!() };
52-
| ++++++++++++++++
5349

5450
error[E0004]: non-exhaustive patterns: `&B` and `&C` not covered
5551
--> $DIR/non-exhaustive-defined-here.rs:52:11
@@ -99,10 +95,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
9995
|
10096
LL | if let E::A = e { todo!() }
10197
| ++ ~~~~~~~~~~~
102-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
103-
|
104-
LL | let E::A = e else { todo!() };
105-
| ++++++++++++++++
10698

10799
error[E0004]: non-exhaustive patterns: `&&mut &B` and `&&mut &C` not covered
108100
--> $DIR/non-exhaustive-defined-here.rs:66:11
@@ -152,10 +144,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
152144
|
153145
LL | if let E::A = e { todo!() }
154146
| ++ ~~~~~~~~~~~
155-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
156-
|
157-
LL | let E::A = e else { todo!() };
158-
| ++++++++++++++++
159147

160148
error[E0004]: non-exhaustive patterns: `None` not covered
161149
--> $DIR/non-exhaustive-defined-here.rs:92:11

src/test/ui/pattern/usefulness/refutable-pattern-errors.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ help: you might want to use `if let` to ignore the variants that aren't matched
1919
|
2020
LL | if let (1, (Some(1), 2..=3)) = (1, (None, 2)) { todo!() }
2121
| ++ ~~~~~~~~~~~
22-
help: alternatively, on nightly, you might want to use `#![feature(let_else)]` to handle the variants that aren't matched
23-
|
24-
LL | let (1, (Some(1), 2..=3)) = (1, (None, 2)) else { todo!() };
25-
| ++++++++++++++++
2622

2723
error: aborting due to 2 previous errors
2824

0 commit comments

Comments
 (0)