Skip to content

Commit 7aae563

Browse files
committedMar 22, 2018
Have the HIR borrowck force the MIR borrowck
Fixes rust-lang#48697
1 parent b176285 commit 7aae563

File tree

2 files changed

+32
-9
lines changed

2 files changed

+32
-9
lines changed
 

‎src/librustc_borrowck/borrowck/mod.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,12 @@ fn borrowck<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, owner_def_id: DefId)
120120
used_mut_nodes: RefCell::new(FxHashSet()),
121121
};
122122

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

133130
// option dance because you can't capture an uninitialized variable
134131
// by mut-ref.

‎src/test/ui/nll/issue-48697.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that we do not ICE when we have suppressed a lexical region
12+
// error that would otherwise cause AST borrowck to die.
13+
//
14+
// Regression test for #48697.
15+
16+
#![feature(nll)]
17+
#![allow(warnings)]
18+
19+
fn foo(x: &i32) -> &i32 {
20+
let z = 4;
21+
let f = &|y| { y };
22+
let k = f(&z);
23+
f(x)
24+
}
25+
26+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.