]> git.lizzy.rs Git - rust.git/commitdiff
Fix another return-const ICE
authorvarkor <github@varkor.com>
Sun, 1 Jul 2018 16:40:36 +0000 (17:40 +0100)
committervarkor <github@varkor.com>
Mon, 2 Jul 2018 18:43:16 +0000 (19:43 +0100)
src/librustc_mir/hair/pattern/check_match.rs
src/test/ui/issue-51714.rs
src/test/ui/issue-51714.stderr

index e04cdcfa02773f520d4d0c1c06b78b133f78b775..a7806131f2c8947d1233a8ba90ec1b6c5dc789d1 100644 (file)
@@ -309,33 +309,32 @@ fn check_irrefutable(&self, pat: &'tcx Pat, origin: &str) {
 fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
     pat.walk(|p| {
         if let PatKind::Binding(_, _, ident, None) = p.node {
-            let bm = *cx.tables
-                        .pat_binding_modes()
-                        .get(p.hir_id)
-                        .expect("missing binding mode");
-
-            if bm != ty::BindByValue(hir::MutImmutable) {
-                // Nothing to check.
-                return true;
-            }
-            let pat_ty = cx.tables.pat_ty(p);
-            if let ty::TyAdt(edef, _) = pat_ty.sty {
-                if edef.is_enum() && edef.variants.iter().any(|variant| {
-                    variant.name == ident.name && variant.ctor_kind == CtorKind::Const
-                }) {
-                    let ty_path = cx.tcx.item_path_str(edef.did);
-                    let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
-                        "pattern binding `{}` is named the same as one \
-                         of the variants of the type `{}`",
-                        ident, ty_path);
-                    err.span_suggestion_with_applicability(
-                        p.span,
-                        "to match on the variant, qualify the path",
-                        format!("{}::{}", ty_path, ident),
-                        Applicability::MachineApplicable
-                    );
-                    err.emit();
+            if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
+                if bm != ty::BindByValue(hir::MutImmutable) {
+                    // Nothing to check.
+                    return true;
+                }
+                let pat_ty = cx.tables.pat_ty(p);
+                if let ty::TyAdt(edef, _) = pat_ty.sty {
+                    if edef.is_enum() && edef.variants.iter().any(|variant| {
+                        variant.name == ident.name && variant.ctor_kind == CtorKind::Const
+                    }) {
+                        let ty_path = cx.tcx.item_path_str(edef.did);
+                        let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
+                            "pattern binding `{}` is named the same as one \
+                            of the variants of the type `{}`",
+                            ident, ty_path);
+                        err.span_suggestion_with_applicability(
+                            p.span,
+                            "to match on the variant, qualify the path",
+                            format!("{}::{}", ty_path, ident),
+                            Applicability::MachineApplicable
+                        );
+                        err.emit();
+                    }
                 }
+            } else {
+                cx.tcx.sess.delay_span_bug(p.span, "missing binding mode");
             }
         }
         true
index c0e62dcc9cefe3e007645cf8903e72dc41f5cf72..f8d12b991eaef37d8752c4693d81a5cbda741ee4 100644 (file)
@@ -9,16 +9,15 @@
 // except according to those terms.
 
 fn main() {
-    |_:  [_; return || {}] | {}
+    |_:  [_; return || {}] | {};
     //~^ ERROR return statement outside of function body
-}
 
-fn foo() {
     [(); return || {}];
     //~^ ERROR return statement outside of function body
-}
 
-fn bar() {
     [(); return |ice| {}];
     //~^ ERROR return statement outside of function body
+
+    [(); return while let Some(n) = Some(0) {}];
+    //~^ ERROR return statement outside of function body
 }
index 3e61df8062d1de3a2abb0f913f5f252d53fcd1d4..c8764564dca38a3622fe22ad99bbedd46cb7ade9 100644 (file)
@@ -1,21 +1,27 @@
 error[E0572]: return statement outside of function body
   --> $DIR/issue-51714.rs:12:14
    |
-LL |     |_:  [_; return || {}] | {}
+LL |     |_:  [_; return || {}] | {};
    |              ^^^^^^^^^^^^
 
 error[E0572]: return statement outside of function body
-  --> $DIR/issue-51714.rs:17:10
+  --> $DIR/issue-51714.rs:15:10
    |
 LL |     [(); return || {}];
    |          ^^^^^^^^^^^^
 
 error[E0572]: return statement outside of function body
-  --> $DIR/issue-51714.rs:22:10
+  --> $DIR/issue-51714.rs:18:10
    |
 LL |     [(); return |ice| {}];
    |          ^^^^^^^^^^^^^^^
 
-error: aborting due to 3 previous errors
+error[E0572]: return statement outside of function body
+  --> $DIR/issue-51714.rs:21:10
+   |
+LL |     [(); return while let Some(n) = Some(0) {}];
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0572`.