about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNadrieril <nadrieril+git@gmail.com>2019-11-29 12:51:34 +0000
committerNadrieril <nadrieril+git@gmail.com>2019-12-02 16:03:03 +0000
commita476af22e8f4ec6a95561f0243b2ebd2936ee557 (patch)
treed35f8fe513b591fe335bb5453fd2dc20bd99c116
parent5c7bd52a7824fd1177e0b5c65ad063a23657d8b4 (diff)
downloadrust-a476af22e8f4ec6a95561f0243b2ebd2936ee557.tar.gz
rust-a476af22e8f4ec6a95561f0243b2ebd2936ee557.zip
Correct error on partially unreachable or-pat in `if let`
-rw-r--r--src/librustc_mir/hair/pattern/check_match.rs22
-rw-r--r--src/test/ui/pattern/usefulness/top-level-alternation.rs3
-rw-r--r--src/test/ui/pattern/usefulness/top-level-alternation.stderr24
3 files changed, 24 insertions, 25 deletions
diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs
index a6a043c23dd..c65df62c824 100644
--- a/src/librustc_mir/hair/pattern/check_match.rs
+++ b/src/librustc_mir/hair/pattern/check_match.rs
@@ -414,16 +414,9 @@ fn check_arms<'p, 'tcx>(
                         hir::MatchSource::IfDesugar { .. } | hir::MatchSource::WhileDesugar => {
                             bug!()
                         }
-                        hir::MatchSource::IfLetDesugar { .. } => {
-                            cx.tcx.lint_hir(
-                                lint::builtin::IRREFUTABLE_LET_PATTERNS,
-                                hir_pat.hir_id,
-                                pat.span,
-                                "irrefutable if-let pattern",
-                            );
-                        }
 
-                        hir::MatchSource::WhileLetDesugar => {
+                        hir::MatchSource::IfLetDesugar { .. }
+                        | hir::MatchSource::WhileLetDesugar => {
                             // check which arm we're on.
                             match arm_index {
                                 // The arm with the user-specified pattern.
@@ -437,11 +430,20 @@ fn check_arms<'p, 'tcx>(
                                 }
                                 // The arm with the wildcard pattern.
                                 1 => {
+                                    let msg = match source {
+                                        hir::MatchSource::IfLetDesugar { .. } => {
+                                            "irrefutable if-let pattern"
+                                        }
+                                        hir::MatchSource::WhileLetDesugar => {
+                                            "irrefutable while-let pattern"
+                                        }
+                                        _ => bug!(),
+                                    };
                                     cx.tcx.lint_hir(
                                         lint::builtin::IRREFUTABLE_LET_PATTERNS,
                                         hir_pat.hir_id,
                                         pat.span,
-                                        "irrefutable while-let pattern",
+                                        msg,
                                     );
                                 }
                                 _ => bug!(),
diff --git a/src/test/ui/pattern/usefulness/top-level-alternation.rs b/src/test/ui/pattern/usefulness/top-level-alternation.rs
index 6ba9b458477..5a7f82063b8 100644
--- a/src/test/ui/pattern/usefulness/top-level-alternation.rs
+++ b/src/test/ui/pattern/usefulness/top-level-alternation.rs
@@ -2,8 +2,7 @@
 
 fn main() {
     while let 0..=2 | 1 = 0 {} //~ ERROR unreachable pattern
-    if let 0..=2 | 1 = 0 {} //~ WARN irrefutable if-let pattern
-    // this one ^ is incorrect
+    if let 0..=2 | 1 = 0 {} //~ ERROR unreachable pattern
 
     match 0u8 {
         0
diff --git a/src/test/ui/pattern/usefulness/top-level-alternation.stderr b/src/test/ui/pattern/usefulness/top-level-alternation.stderr
index ef732747121..772927f42f5 100644
--- a/src/test/ui/pattern/usefulness/top-level-alternation.stderr
+++ b/src/test/ui/pattern/usefulness/top-level-alternation.stderr
@@ -10,67 +10,65 @@ note: lint level defined here
 LL | #![deny(unreachable_patterns)]
    |         ^^^^^^^^^^^^^^^^^^^^
 
-warning: irrefutable if-let pattern
+error: unreachable pattern
   --> $DIR/top-level-alternation.rs:5:20
    |
 LL |     if let 0..=2 | 1 = 0 {}
    |                    ^
-   |
-   = note: `#[warn(irrefutable_let_patterns)]` on by default
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:10:15
+  --> $DIR/top-level-alternation.rs:9:15
    |
 LL |             | 0 => {}
    |               ^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:15:15
+  --> $DIR/top-level-alternation.rs:14:15
    |
 LL |             | Some(0) => {}
    |               ^^^^^^^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:20:9
+  --> $DIR/top-level-alternation.rs:19:9
    |
 LL |         (0, 0) => {}
    |         ^^^^^^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:40:9
+  --> $DIR/top-level-alternation.rs:39:9
    |
 LL |         _ => {}
    |         ^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:44:9
+  --> $DIR/top-level-alternation.rs:43:9
    |
 LL |         Some(_) => {}
    |         ^^^^^^^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:45:9
+  --> $DIR/top-level-alternation.rs:44:9
    |
 LL |         None => {}
    |         ^^^^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:50:9
+  --> $DIR/top-level-alternation.rs:49:9
    |
 LL |         None
    |         ^^^^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:51:15
+  --> $DIR/top-level-alternation.rs:50:15
    |
 LL |             | Some(_) => {}
    |               ^^^^^^^
 
 error: unreachable pattern
-  --> $DIR/top-level-alternation.rs:55:9
+  --> $DIR/top-level-alternation.rs:54:9
    |
 LL |         1..=2 => {},
    |         ^^^^^
 
-error: aborting due to 10 previous errors
+error: aborting due to 11 previous errors