Skip to content

Commit 3f0ce08

Browse files
committed
minor refactorings to fix trait import issue
1 parent f60788b commit 3f0ce08

File tree

2 files changed

+11
-42
lines changed

2 files changed

+11
-42
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData;
1717
use rustc::infer::InferCtxt;
1818
use rustc::ty::{self, ParamEnv, TyCtxt};
1919
use rustc::ty::maps::Providers;
20-
use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place, Visitor};
20+
use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place};
2121
use rustc::mir::{Mir, Mutability, Operand, Projection, ProjectionElem, Rvalue};
2222
use rustc::mir::{Field, Statement, StatementKind, Terminator, TerminatorKind};
2323
use rustc::mir::ClosureRegionRequirements;
@@ -43,6 +43,7 @@ use dataflow::indexes::BorrowIndex;
4343
use dataflow::move_paths::{IllegalMoveOriginKind, MoveError};
4444
use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex};
4545
use util::borrowck_errors::{BorrowckErrors, Origin};
46+
use util::collect_writes::FindAssignments;
4647

4748
use std::iter;
4849

@@ -56,37 +57,6 @@ mod prefixes;
5657

5758
use std::borrow::Cow;
5859

59-
struct FindLocalAssignmentVisitor {
60-
needle: Local,
61-
locations: Vec<Location>,
62-
placectxt: PlaceContext,
63-
location: Location,
64-
}
65-
66-
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
67-
fn visit_local(&mut self,
68-
local: &Local,
69-
place_context: PlaceContext<'tcx>,
70-
location: Location) {
71-
if self.needle != *local {
72-
return;
73-
}
74-
75-
match place_context {
76-
PlaceContext::Store | PlaceContext::Call => {
77-
self.locations.push(location);
78-
}
79-
PlaceContext::AsmOutput | PlaceContext::Drop| PlaceContext::Inspect |
80-
PlaceContext::Borrow| PlaceContext::Projection| PlaceContext::Copy|
81-
PlaceContext::Move| PlaceContext::StorageLive| PlaceContext::StorageDead|
82-
PlaceContext::Validate => {
83-
}
84-
}
85-
86-
Visitor::visit_local(local,place_context,location)
87-
}
88-
}
89-
9060
pub(crate) mod nll;
9161

9262
pub fn provide(providers: &mut Providers) {
@@ -1587,7 +1557,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
15871557
None => "immutable item".to_owned(),
15881558
};
15891559

1590-
// call find_assignments() here
15911560
let mut err = self.tcx
15921561
.cannot_borrow_path_as_mutable(span, &item_msg, Origin::Mir);
15931562
err.span_label(span, "cannot borrow as mutable");
@@ -1604,6 +1573,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
16041573
if let Err(place_err) = self.is_mutable(place, is_local_mutation_allowed) {
16051574
error_reported = true;
16061575

1576+
match *place{
1577+
Place::Local(local) => {let locations = self.mir.find_assignments(local);
1578+
1579+
for n in &locations{
1580+
debug!("locations ={:?}", n);}
1581+
}
1582+
_ => {}}
1583+
16071584
let item_msg = if error_reported{
16081585
if let Some(name) = self.describe_place(place_err) {
16091586
format!("`&`-reference {}", name)
@@ -2269,12 +2246,3 @@ impl ContextKind {
22692246
}
22702247
}
22712248

2272-
impl Mir {
2273-
fn find_assignments(&self, local: Local, place_context:PlaceContext, location:Location) -> Vec<Location>
2274-
{
2275-
let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![], location:location, place_context: };
2276-
visitor.visit_mir(self);
2277-
visitor.locations
2278-
}
2279-
}
2280-

src/librustc_mir/util/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ mod alignment;
1717
mod graphviz;
1818
pub(crate) mod pretty;
1919
pub mod liveness;
20+
pub mod collect_writes;
2021

2122
pub use self::alignment::is_disaligned;
2223
pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};

0 commit comments

Comments
 (0)