Skip to content

Commit

Permalink
Fix a bug with return in anonymous consts
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Jul 2, 2018
1 parent b58b721 commit c6bbee8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
12 changes: 5 additions & 7 deletions src/librustc_typeck/check/writeback.rs
Expand Up @@ -257,13 +257,11 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> {
fn visit_pat(&mut self, p: &'gcx hir::Pat) {
match p.node {
hir::PatKind::Binding(..) => {
let bm = *self.fcx
.tables
.borrow()
.pat_binding_modes()
.get(p.hir_id)
.expect("missing binding mode");
self.tables.pat_binding_modes_mut().insert(p.hir_id, bm);
if let Some(&bm) = self.fcx.tables.borrow().pat_binding_modes().get(p.hir_id) {
self.tables.pat_binding_modes_mut().insert(p.hir_id, bm);
} else {
self.tcx().sess.delay_span_bug(p.span, "missing binding mode");
}
}
hir::PatKind::Struct(_, ref fields, _) => {
for field in fields {
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/issue-51714.rs
Expand Up @@ -17,3 +17,8 @@ fn foo() {
[(); return || {}];
//~^ ERROR return statement outside of function body
}

fn bar() {
[(); return |ice| {}];
//~^ ERROR return statement outside of function body
}
8 changes: 7 additions & 1 deletion src/test/ui/issue-51714.stderr
Expand Up @@ -10,6 +10,12 @@ error[E0572]: return statement outside of function body
LL | [(); return || {}];
| ^^^^^^^^^^^^

error: aborting due to 2 previous errors
error[E0572]: return statement outside of function body
--> $DIR/issue-51714.rs:22:10
|
LL | [(); return |ice| {}];
| ^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

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

0 comments on commit c6bbee8

Please sign in to comment.