Skip to content

Commit c6bbee8

Browse files
committed
Fix a bug with return in anonymous consts
1 parent b58b721 commit c6bbee8

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/librustc_typeck/check/writeback.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,11 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
257257
fn visit_pat(&mut self, p: &'gcx hir::Pat) {
258258
match p.node {
259259
hir::PatKind::Binding(..) => {
260-
let bm = *self.fcx
261-
.tables
262-
.borrow()
263-
.pat_binding_modes()
264-
.get(p.hir_id)
265-
.expect("missing binding mode");
266-
self.tables.pat_binding_modes_mut().insert(p.hir_id, bm);
260+
if let Some(&bm) = self.fcx.tables.borrow().pat_binding_modes().get(p.hir_id) {
261+
self.tables.pat_binding_modes_mut().insert(p.hir_id, bm);
262+
} else {
263+
self.tcx().sess.delay_span_bug(p.span, "missing binding mode");
264+
}
267265
}
268266
hir::PatKind::Struct(_, ref fields, _) => {
269267
for field in fields {

src/test/ui/issue-51714.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ fn foo() {
1717
[(); return || {}];
1818
//~^ ERROR return statement outside of function body
1919
}
20+
21+
fn bar() {
22+
[(); return |ice| {}];
23+
//~^ ERROR return statement outside of function body
24+
}

src/test/ui/issue-51714.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ error[E0572]: return statement outside of function body
1010
LL | [(); return || {}];
1111
| ^^^^^^^^^^^^
1212

13-
error: aborting due to 2 previous errors
13+
error[E0572]: return statement outside of function body
14+
--> $DIR/issue-51714.rs:22:10
15+
|
16+
LL | [(); return |ice| {}];
17+
| ^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
1420

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

0 commit comments

Comments
 (0)