Skip to content

Commit 87e729f

Browse files
committed
thread the errors_buffer down into nll::type_check.
Right now its solely used for `check_local`, which ... I guess is not surprising?
1 parent 3d3e0aa commit 87e729f

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

src/librustc_mir/borrow_check/nll/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
122122
flow_inits,
123123
move_data,
124124
elements,
125+
errors_buffer,
125126
);
126127

127128
if let Some(all_facts) = &mut all_facts {

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use std::rc::Rc;
4141
use syntax_pos::{Span, DUMMY_SP};
4242
use transform::{MirPass, MirSource};
4343
use util::liveness::LivenessResults;
44+
use rustc_errors::Diagnostic;
4445

4546
use rustc_data_structures::fx::FxHashSet;
4647
use rustc_data_structures::indexed_vec::Idx;
@@ -102,6 +103,7 @@ mod liveness;
102103
/// constraints for the regions in the types of variables
103104
/// - `flow_inits` -- results of a maybe-init dataflow analysis
104105
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
106+
/// - `errors_buffer` -- errors are sent here for future reporting
105107
pub(crate) fn type_check<'gcx, 'tcx>(
106108
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
107109
param_env: ty::ParamEnv<'gcx>,
@@ -115,6 +117,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
115117
flow_inits: &mut FlowAtLocation<MaybeInitializedPlaces<'_, 'gcx, 'tcx>>,
116118
move_data: &MoveData<'tcx>,
117119
elements: &Rc<RegionValueElements>,
120+
errors_buffer: &mut Vec<Diagnostic>,
118121
) -> MirTypeckRegionConstraints<'tcx> {
119122
let implicit_region_bound = infcx.tcx.mk_region(ty::ReVar(universal_regions.fr_fn_body));
120123
let mut constraints = MirTypeckRegionConstraints {
@@ -140,14 +143,13 @@ pub(crate) fn type_check<'gcx, 'tcx>(
140143
&universal_regions.region_bound_pairs,
141144
Some(implicit_region_bound),
142145
Some(&mut borrowck_context),
146+
Some(errors_buffer),
143147
|cx| {
144148
liveness::generate(cx, mir, liveness, flow_inits, move_data);
145-
146149
cx.equate_inputs_and_outputs(mir, mir_def_id, universal_regions);
147150
},
148151
);
149152
}
150-
151153
constraints
152154
}
153155

@@ -159,6 +161,7 @@ fn type_check_internal<'a, 'gcx, 'tcx, F>(
159161
region_bound_pairs: &'a [(ty::Region<'tcx>, GenericKind<'tcx>)],
160162
implicit_region_bound: Option<ty::Region<'tcx>>,
161163
borrowck_context: Option<&'a mut BorrowCheckContext<'a, 'tcx>>,
164+
errors_buffer: Option<&mut Vec<Diagnostic>>,
162165
mut extra: F,
163166
)
164167
where F: FnMut(&mut TypeChecker<'a, 'gcx, 'tcx>)
@@ -180,7 +183,7 @@ fn type_check_internal<'a, 'gcx, 'tcx, F>(
180183

181184
if !errors_reported {
182185
// if verifier failed, don't do further checks to avoid ICEs
183-
checker.typeck_mir(mir);
186+
checker.typeck_mir(mir, errors_buffer);
184187
}
185188

186189
extra(&mut checker);
@@ -1227,7 +1230,12 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12271230
}
12281231
}
12291232

1230-
fn check_local(&mut self, mir: &Mir<'tcx>, local: Local, local_decl: &LocalDecl<'tcx>) {
1233+
fn check_local(&mut self,
1234+
mir: &Mir<'tcx>,
1235+
local: Local,
1236+
local_decl: &LocalDecl<'tcx>,
1237+
errors_buffer: &mut Option<&mut Vec<Diagnostic>>)
1238+
{
12311239
match mir.local_kind(local) {
12321240
LocalKind::ReturnPointer | LocalKind::Arg => {
12331241
// return values of normal functions are required to be
@@ -1255,14 +1263,21 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12551263
// slot or local, so to find all unsized rvalues it is enough
12561264
// to check all temps, return slots and locals.
12571265
if let None = self.reported_errors.replace((ty, span)) {
1258-
span_err!(
1259-
self.tcx().sess,
1260-
span,
1261-
E0161,
1262-
"cannot move a value of type {0}: the size of {0} \
1263-
cannot be statically determined",
1264-
ty
1265-
);
1266+
let mut diag = struct_span_err!(self.tcx().sess,
1267+
span,
1268+
E0161,
1269+
"cannot move a value of type {0}: the size of {0} \
1270+
cannot be statically determined",
1271+
ty);
1272+
if let Some(ref mut errors_buffer) = *errors_buffer {
1273+
diag.buffer(errors_buffer);
1274+
} else {
1275+
// we're allowed to use emit() here because the
1276+
// NLL migration will be turned on (and thus
1277+
// errors will need to be buffered) *only if*
1278+
// errors_buffer is Some.
1279+
diag.emit();
1280+
}
12661281
}
12671282
}
12681283
}
@@ -1742,12 +1757,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
17421757
})
17431758
}
17441759

1745-
fn typeck_mir(&mut self, mir: &Mir<'tcx>) {
1760+
fn typeck_mir(&mut self,
1761+
mir: &Mir<'tcx>,
1762+
mut errors_buffer: Option<&mut Vec<Diagnostic>>)
1763+
{
17461764
self.last_span = mir.span;
17471765
debug!("run_on_mir: {:?}", mir.span);
17481766

17491767
for (local, local_decl) in mir.local_decls.iter_enumerated() {
1750-
self.check_local(mir, local, local_decl);
1768+
self.check_local(mir, local, local_decl, &mut errors_buffer);
17511769
}
17521770

17531771
for (block, block_data) in mir.basic_blocks().iter_enumerated() {
@@ -1812,7 +1830,7 @@ impl MirPass for TypeckMir {
18121830

18131831
let param_env = tcx.param_env(def_id);
18141832
tcx.infer_ctxt().enter(|infcx| {
1815-
type_check_internal(&infcx, def_id, param_env, mir, &[], None, None, |_| ());
1833+
type_check_internal(&infcx, def_id, param_env, mir, &[], None, None, None, |_| ());
18161834

18171835
// For verification purposes, we just ignore the resulting
18181836
// region constraint sets. Not our problem. =)

0 commit comments

Comments
 (0)