Skip to content

Commit

Permalink
Have the HIR borrowck force the MIR borrowck
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Mar 22, 2018
1 parent b176285 commit 7aae563
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,12 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
used_mut_nodes: RefCell::new(FxHashSet()),
};

// Eventually, borrowck will always read the MIR, but at the
// moment we do not. So, for now, we always force MIR to be
// constructed for a given fn, since this may result in errors
// being reported and we want that to happen.
//
// Note that `mir_validated` is a "stealable" result; the
// thief, `optimized_mir()`, forces borrowck, so we know that
// is not yet stolen.
tcx.mir_validated(owner_def_id).borrow();
// Force the MIR-based borrow checker to run; this also forces the
// MIR to be built. This may lead to errors being reported,
// particularly in NLL mode, where some ordinary region errors are
// suppressed. It's important that those errors get reported to
// avoid ICEs like #48697.
let _ = tcx.mir_borrowck(owner_def_id);

// option dance because you can't capture an uninitialized variable
// by mut-ref.
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/nll/issue-48697.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that we do not ICE when we have suppressed a lexical region
// error that would otherwise cause AST borrowck to die.
//
// Regression test for #48697.

#![feature(nll)]
#![allow(warnings)]

fn foo(x: &i32) -> &i32 {
let z = 4;
let f = &|y| { y };
let k = f(&z);
f(x)
}

fn main() {}

0 comments on commit 7aae563

Please sign in to comment.