From 998141f8ef8225704f8641ef0372c686bcbd2c5f Mon Sep 17 00:00:00 2001 From: varkor Date: Sun, 1 Jul 2018 17:40:36 +0100 Subject: [PATCH] Fix another return-const ICE --- src/librustc_mir/hair/pattern/check_match.rs | 51 ++++++++++---------- src/test/ui/issue-51714.rs | 9 ++-- src/test/ui/issue-51714.stderr | 14 ++++-- 3 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index e04cdcfa027..a7806131f2c 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -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 diff --git a/src/test/ui/issue-51714.rs b/src/test/ui/issue-51714.rs index c0e62dcc9ce..f8d12b991ea 100644 --- a/src/test/ui/issue-51714.rs +++ b/src/test/ui/issue-51714.rs @@ -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 } diff --git a/src/test/ui/issue-51714.stderr b/src/test/ui/issue-51714.stderr index 3e61df8062d..c8764564dca 100644 --- a/src/test/ui/issue-51714.stderr +++ b/src/test/ui/issue-51714.stderr @@ -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`. -- 2.44.0