Skip to content

Commit e4c8672

Browse files
authored
Rollup merge of #123847 - eggyal:issue-123844, r=fmease
Suppress `let else` suggestion for uninitialized refutable `let`s Fixes #123844 r? `@CAD97`
2 parents 1524fe0 + ddcfb94 commit e4c8672

6 files changed

+22
-48
lines changed

Diff for: compiler/rustc_mir_build/src/thir/pattern/check_match.rs

+1
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> {
674674
if let Some(span) = sp
675675
&& self.tcx.sess.source_map().is_span_accessible(span)
676676
&& interpreted_as_const.is_none()
677+
&& scrut.is_some()
677678
{
678679
let mut bindings = vec![];
679680
pat.each_binding(|name, _, _, _| bindings.push(name));

Diff for: tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ LL | mac!(0);
4646
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
4747
= note: the matched value is of type `i32`
4848
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
49-
help: you might want to use `if let` to ignore the variant that isn't matched
50-
|
51-
LL | if let ...$e; { todo!() }
52-
| ++ +++++++++++
5349

5450
error: aborting due to 6 previous errors
5551

Diff for: tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ LL | mac!(0);
6767
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
6868
= note: the matched value is of type `i32`
6969
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
70-
help: you might want to use `if let` to ignore the variant that isn't matched
71-
|
72-
LL | if let $e...; { todo!() }
73-
| ++ +++++++++++
7470

7571
error[E0005]: refutable pattern in local binding
7672
--> $DIR/half-open-range-pats-inclusive-no-end.rs:20:17
@@ -85,10 +81,6 @@ LL | mac!(0);
8581
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
8682
= note: the matched value is of type `i32`
8783
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
88-
help: you might want to use `if let` to ignore the variant that isn't matched
89-
|
90-
LL | if let $e..=; { todo!() }
91-
| ++ +++++++++++
9284

9385
error: aborting due to 8 previous errors
9486

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// https://github.com/rust-lang/rust/issues/123844
2+
// An uninitialized refutable let should not suggest `let else`, as it can't be used with deferred
3+
// initialization.
4+
5+
fn main() {
6+
let Some(x); //~ ERROR refutable pattern in local binding
7+
x = 1;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0005]: refutable pattern in local binding
2+
--> $DIR/uninitialized-refutable-let-issue-123844.rs:6:9
3+
|
4+
LL | let Some(x);
5+
| ^^^^^^^ pattern `None` not covered
6+
|
7+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
8+
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
9+
= note: the matched value is of type `Option<i32>`
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0005`.

Diff for: tests/ui/parser/recover/recover-range-pats.stderr

-36
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,6 @@ LL | mac2!(0, 1);
491491
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
492492
= note: the matched value is of type `i32`
493493
= note: this error originates in the macro `mac2` (in Nightly builds, run with -Z macro-backtrace for more info)
494-
help: you might want to use `if let` to ignore the variants that aren't matched
495-
|
496-
LL | if let $e1..$e2; { todo!() }
497-
| ++ +++++++++++
498494

499495
error[E0005]: refutable pattern in local binding
500496
--> $DIR/recover-range-pats.rs:138:17
@@ -509,10 +505,6 @@ LL | mac2!(0, 1);
509505
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
510506
= note: the matched value is of type `i32`
511507
= note: this error originates in the macro `mac2` (in Nightly builds, run with -Z macro-backtrace for more info)
512-
help: you might want to use `if let` to ignore the variants that aren't matched
513-
|
514-
LL | if let $e1...$e2; { todo!() }
515-
| ++ +++++++++++
516508

517509
error[E0005]: refutable pattern in local binding
518510
--> $DIR/recover-range-pats.rs:142:17
@@ -527,10 +519,6 @@ LL | mac2!(0, 1);
527519
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
528520
= note: the matched value is of type `i32`
529521
= note: this error originates in the macro `mac2` (in Nightly builds, run with -Z macro-backtrace for more info)
530-
help: you might want to use `if let` to ignore the variants that aren't matched
531-
|
532-
LL | if let $e1..=$e2; { todo!() }
533-
| ++ +++++++++++
534522

535523
error[E0005]: refutable pattern in local binding
536524
--> $DIR/recover-range-pats.rs:151:17
@@ -545,10 +533,6 @@ LL | mac!(0);
545533
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
546534
= note: the matched value is of type `i32`
547535
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
548-
help: you might want to use `if let` to ignore the variant that isn't matched
549-
|
550-
LL | if let ..$e; { todo!() }
551-
| ++ +++++++++++
552536

553537
error[E0005]: refutable pattern in local binding
554538
--> $DIR/recover-range-pats.rs:153:17
@@ -563,10 +547,6 @@ LL | mac!(0);
563547
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
564548
= note: the matched value is of type `i32`
565549
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
566-
help: you might want to use `if let` to ignore the variant that isn't matched
567-
|
568-
LL | if let ...$e; { todo!() }
569-
| ++ +++++++++++
570550

571551
error[E0005]: refutable pattern in local binding
572552
--> $DIR/recover-range-pats.rs:156:17
@@ -581,10 +561,6 @@ LL | mac!(0);
581561
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
582562
= note: the matched value is of type `i32`
583563
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
584-
help: you might want to use `if let` to ignore the variant that isn't matched
585-
|
586-
LL | if let ..=$e; { todo!() }
587-
| ++ +++++++++++
588564

589565
error[E0005]: refutable pattern in local binding
590566
--> $DIR/recover-range-pats.rs:158:17
@@ -599,10 +575,6 @@ LL | mac!(0);
599575
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
600576
= note: the matched value is of type `i32`
601577
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
602-
help: you might want to use `if let` to ignore the variant that isn't matched
603-
|
604-
LL | if let $e..; { todo!() }
605-
| ++ +++++++++++
606578

607579
error[E0005]: refutable pattern in local binding
608580
--> $DIR/recover-range-pats.rs:160:17
@@ -617,10 +589,6 @@ LL | mac!(0);
617589
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
618590
= note: the matched value is of type `i32`
619591
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
620-
help: you might want to use `if let` to ignore the variant that isn't matched
621-
|
622-
LL | if let $e...; { todo!() }
623-
| ++ +++++++++++
624592

625593
error[E0005]: refutable pattern in local binding
626594
--> $DIR/recover-range-pats.rs:162:17
@@ -635,10 +603,6 @@ LL | mac!(0);
635603
= note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html
636604
= note: the matched value is of type `i32`
637605
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
638-
help: you might want to use `if let` to ignore the variant that isn't matched
639-
|
640-
LL | if let $e..=; { todo!() }
641-
| ++ +++++++++++
642606

643607
error: aborting due to 69 previous errors
644608

0 commit comments

Comments
 (0)