Skip to content

Commit 998141f

Browse files
committed
Fix another return-const ICE
1 parent 7ad1c62 commit 998141f

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

src/librustc_mir/hair/pattern/check_match.rs

+25-26
Original file line numberDiff line numberDiff line change
@@ -309,33 +309,32 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
309309
fn check_for_bindings_named_the_same_as_variants(cx: &MatchVisitor, pat: &Pat) {
310310
pat.walk(|p| {
311311
if let PatKind::Binding(_, _, ident, None) = p.node {
312-
let bm = *cx.tables
313-
.pat_binding_modes()
314-
.get(p.hir_id)
315-
.expect("missing binding mode");
316-
317-
if bm != ty::BindByValue(hir::MutImmutable) {
318-
// Nothing to check.
319-
return true;
320-
}
321-
let pat_ty = cx.tables.pat_ty(p);
322-
if let ty::TyAdt(edef, _) = pat_ty.sty {
323-
if edef.is_enum() && edef.variants.iter().any(|variant| {
324-
variant.name == ident.name && variant.ctor_kind == CtorKind::Const
325-
}) {
326-
let ty_path = cx.tcx.item_path_str(edef.did);
327-
let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
328-
"pattern binding `{}` is named the same as one \
329-
of the variants of the type `{}`",
330-
ident, ty_path);
331-
err.span_suggestion_with_applicability(
332-
p.span,
333-
"to match on the variant, qualify the path",
334-
format!("{}::{}", ty_path, ident),
335-
Applicability::MachineApplicable
336-
);
337-
err.emit();
312+
if let Some(&bm) = cx.tables.pat_binding_modes().get(p.hir_id) {
313+
if bm != ty::BindByValue(hir::MutImmutable) {
314+
// Nothing to check.
315+
return true;
316+
}
317+
let pat_ty = cx.tables.pat_ty(p);
318+
if let ty::TyAdt(edef, _) = pat_ty.sty {
319+
if edef.is_enum() && edef.variants.iter().any(|variant| {
320+
variant.name == ident.name && variant.ctor_kind == CtorKind::Const
321+
}) {
322+
let ty_path = cx.tcx.item_path_str(edef.did);
323+
let mut err = struct_span_warn!(cx.tcx.sess, p.span, E0170,
324+
"pattern binding `{}` is named the same as one \
325+
of the variants of the type `{}`",
326+
ident, ty_path);
327+
err.span_suggestion_with_applicability(
328+
p.span,
329+
"to match on the variant, qualify the path",
330+
format!("{}::{}", ty_path, ident),
331+
Applicability::MachineApplicable
332+
);
333+
err.emit();
334+
}
338335
}
336+
} else {
337+
cx.tcx.sess.delay_span_bug(p.span, "missing binding mode");
339338
}
340339
}
341340
true

src/test/ui/issue-51714.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
|_: [_; return || {}] | {}
12+
|_: [_; return || {}] | {};
1313
//~^ ERROR return statement outside of function body
14-
}
1514

16-
fn foo() {
1715
[(); return || {}];
1816
//~^ ERROR return statement outside of function body
19-
}
2017

21-
fn bar() {
2218
[(); return |ice| {}];
2319
//~^ ERROR return statement outside of function body
20+
21+
[(); return while let Some(n) = Some(0) {}];
22+
//~^ ERROR return statement outside of function body
2423
}

src/test/ui/issue-51714.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
error[E0572]: return statement outside of function body
22
--> $DIR/issue-51714.rs:12:14
33
|
4-
LL | |_: [_; return || {}] | {}
4+
LL | |_: [_; return || {}] | {};
55
| ^^^^^^^^^^^^
66

77
error[E0572]: return statement outside of function body
8-
--> $DIR/issue-51714.rs:17:10
8+
--> $DIR/issue-51714.rs:15:10
99
|
1010
LL | [(); return || {}];
1111
| ^^^^^^^^^^^^
1212

1313
error[E0572]: return statement outside of function body
14-
--> $DIR/issue-51714.rs:22:10
14+
--> $DIR/issue-51714.rs:18:10
1515
|
1616
LL | [(); return |ice| {}];
1717
| ^^^^^^^^^^^^^^^
1818

19-
error: aborting due to 3 previous errors
19+
error[E0572]: return statement outside of function body
20+
--> $DIR/issue-51714.rs:21:10
21+
|
22+
LL | [(); return while let Some(n) = Some(0) {}];
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
2026

2127
For more information about this error, try `rustc --explain E0572`.

0 commit comments

Comments
 (0)