Skip to content

Commit 341e5e3

Browse files
committed
Use MirBorrowckCtxt while reporting move errors
1 parent 942b384 commit 341e5e3

File tree

2 files changed

+21
-39
lines changed

2 files changed

+21
-39
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use std::rc::Rc;
3434
use syntax_pos::Span;
3535

3636
use dataflow::indexes::BorrowIndex;
37-
use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
37+
use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MoveError, MovePathIndex};
3838
use dataflow::Borrows;
3939
use dataflow::DataflowResultsConsumer;
4040
use dataflow::FlowAtLocation;
@@ -148,13 +148,11 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
148148
let mir = &mir; // no further changes
149149
let location_table = &LocationTable::new(mir);
150150

151-
let move_data: MoveData<'tcx> = match MoveData::gather_moves(mir, tcx) {
152-
Ok(move_data) => move_data,
153-
Err((move_data, move_errors)) => {
154-
move_errors::report_move_errors(&mir, tcx, move_errors, &move_data);
155-
move_data
156-
}
157-
};
151+
let (move_data, move_errors): (MoveData<'tcx>, Option<Vec<MoveError<'tcx>>>) =
152+
match MoveData::gather_moves(mir, tcx) {
153+
Ok(move_data) => (move_data, None),
154+
Err((move_data, move_errors)) => (move_data, Some(move_errors)),
155+
};
158156

159157
let mdpe = MoveDataParamEnv {
160158
move_data: move_data,
@@ -271,6 +269,9 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
271269
polonius_output,
272270
);
273271

272+
if let Some(errors) = move_errors {
273+
mbcx.report_move_errors(errors);
274+
}
274275
mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer
275276

276277
// For each non-user used mutable variable, check if it's been assigned from
@@ -1975,7 +1976,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19751976
ProjectionElem::Field(field, _ty) => {
19761977
let base_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
19771978

1978-
if base_ty.is_closure() || base_ty.is_generator() {
1979+
if base_ty.is_closure() || base_ty.is_generator() {
19791980
Some(field)
19801981
} else {
19811982
None

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,15 @@
1010

1111
use rustc::hir;
1212
use rustc::mir::*;
13-
use rustc::ty::{self, TyCtxt};
13+
use rustc::ty;
1414
use rustc_errors::DiagnosticBuilder;
1515
use syntax_pos::Span;
1616

17-
use dataflow::move_paths::{IllegalMoveOrigin, IllegalMoveOriginKind, MoveData};
17+
use borrow_check::MirBorrowckCtxt;
18+
use dataflow::move_paths::{IllegalMoveOrigin, IllegalMoveOriginKind};
1819
use dataflow::move_paths::{LookupResult, MoveError, MovePathIndex};
1920
use util::borrowck_errors::{BorrowckErrors, Origin};
2021

21-
pub(crate) fn report_move_errors<'gcx, 'tcx>(
22-
mir: &Mir<'tcx>,
23-
tcx: TyCtxt<'_, 'gcx, 'tcx>,
24-
move_errors: Vec<MoveError<'tcx>>,
25-
move_data: &MoveData<'tcx>,
26-
) {
27-
MoveErrorCtxt {
28-
mir,
29-
tcx,
30-
move_data,
31-
}.report_errors(move_errors);
32-
}
33-
34-
#[derive(Copy, Clone)]
35-
struct MoveErrorCtxt<'a, 'gcx: 'tcx, 'tcx: 'a> {
36-
mir: &'a Mir<'tcx>,
37-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
38-
move_data: &'a MoveData<'tcx>,
39-
}
40-
4122
// Often when desugaring a pattern match we may have many individual moves in
4223
// MIR that are all part of one operation from the user's point-of-view. For
4324
// example:
@@ -76,15 +57,15 @@ enum GroupedMoveError<'tcx> {
7657
},
7758
}
7859

79-
impl<'a, 'gcx, 'tcx> MoveErrorCtxt<'a, 'gcx, 'tcx> {
80-
fn report_errors(self, move_errors: Vec<MoveError<'tcx>>) {
60+
impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
61+
pub(crate) fn report_move_errors(&self, move_errors: Vec<MoveError<'tcx>>) {
8162
let grouped_errors = self.group_move_errors(move_errors);
8263
for error in grouped_errors {
8364
self.report(error);
8465
}
8566
}
8667

87-
fn group_move_errors(self, errors: Vec<MoveError<'tcx>>) -> Vec<GroupedMoveError<'tcx>> {
68+
fn group_move_errors(&self, errors: Vec<MoveError<'tcx>>) -> Vec<GroupedMoveError<'tcx>> {
8869
let mut grouped_errors = Vec::new();
8970
for error in errors {
9071
self.append_to_grouped_errors(&mut grouped_errors, error);
@@ -93,7 +74,7 @@ impl<'a, 'gcx, 'tcx> MoveErrorCtxt<'a, 'gcx, 'tcx> {
9374
}
9475

9576
fn append_to_grouped_errors(
96-
self,
77+
&self,
9778
grouped_errors: &mut Vec<GroupedMoveError<'tcx>>,
9879
error: MoveError<'tcx>,
9980
) {
@@ -158,7 +139,7 @@ impl<'a, 'gcx, 'tcx> MoveErrorCtxt<'a, 'gcx, 'tcx> {
158139
}
159140

160141
fn append_binding_error(
161-
self,
142+
&self,
162143
grouped_errors: &mut Vec<GroupedMoveError<'tcx>>,
163144
kind: IllegalMoveOriginKind<'tcx>,
164145
move_from: &Place<'tcx>,
@@ -236,7 +217,7 @@ impl<'a, 'gcx, 'tcx> MoveErrorCtxt<'a, 'gcx, 'tcx> {
236217
};
237218
}
238219

239-
fn report(self, error: GroupedMoveError<'tcx>) {
220+
fn report(&self, error: GroupedMoveError<'tcx>) {
240221
let (mut err, err_span) = {
241222
let (span, kind): (Span, &IllegalMoveOriginKind) = match error {
242223
GroupedMoveError::MovesFromMatchPlace { span, ref kind, .. }
@@ -279,7 +260,7 @@ impl<'a, 'gcx, 'tcx> MoveErrorCtxt<'a, 'gcx, 'tcx> {
279260
}
280261

281262
fn add_move_hints(
282-
self,
263+
&self,
283264
error: GroupedMoveError<'tcx>,
284265
err: &mut DiagnosticBuilder<'a>,
285266
span: Span,
@@ -365,7 +346,7 @@ impl<'a, 'gcx, 'tcx> MoveErrorCtxt<'a, 'gcx, 'tcx> {
365346
}
366347
}
367348

368-
fn suitable_to_remove_deref(self, proj: &PlaceProjection<'tcx>, snippet: &str) -> bool {
349+
fn suitable_to_remove_deref(&self, proj: &PlaceProjection<'tcx>, snippet: &str) -> bool {
369350
let is_shared_ref = |ty: ty::Ty| match ty.sty {
370351
ty::TypeVariants::TyRef(.., hir::Mutability::MutImmutable) => true,
371352
_ => false,

0 commit comments

Comments
 (0)