From 3f0ce0858e4a07239ea6d38c14991bba46c413fc Mon Sep 17 00:00:00 2001 From: gaurikholkar Date: Fri, 2 Mar 2018 10:46:01 +0530 Subject: [PATCH] minor refactorings to fix trait import issue --- src/librustc_mir/borrow_check/mod.rs | 52 ++++++---------------------- src/librustc_mir/util/mod.rs | 1 + 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index aa4a704254e5..90e84a478095 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData; use rustc::infer::InferCtxt; use rustc::ty::{self, ParamEnv, TyCtxt}; use rustc::ty::maps::Providers; -use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place, Visitor}; +use rustc::mir::{AssertMessage, BasicBlock, BorrowKind, Local, Location, Place}; use rustc::mir::{Mir, Mutability, Operand, Projection, ProjectionElem, Rvalue}; use rustc::mir::{Field, Statement, StatementKind, Terminator, TerminatorKind}; use rustc::mir::ClosureRegionRequirements; @@ -43,6 +43,7 @@ use dataflow::indexes::BorrowIndex; use dataflow::move_paths::{IllegalMoveOriginKind, MoveError}; use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex}; use util::borrowck_errors::{BorrowckErrors, Origin}; +use util::collect_writes::FindAssignments; use std::iter; @@ -56,37 +57,6 @@ mod prefixes; use std::borrow::Cow; -struct FindLocalAssignmentVisitor { - needle: Local, - locations: Vec, - placectxt: PlaceContext, - location: Location, -} - -impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor { - fn visit_local(&mut self, - local: &Local, - place_context: PlaceContext<'tcx>, - location: Location) { - if self.needle != *local { - return; - } - - match place_context { - PlaceContext::Store | PlaceContext::Call => { - self.locations.push(location); - } - PlaceContext::AsmOutput | PlaceContext::Drop| PlaceContext::Inspect | - PlaceContext::Borrow| PlaceContext::Projection| PlaceContext::Copy| - PlaceContext::Move| PlaceContext::StorageLive| PlaceContext::StorageDead| - PlaceContext::Validate => { - } - } - - Visitor::visit_local(local,place_context,location) - } -} - pub(crate) mod nll; pub fn provide(providers: &mut Providers) { @@ -1587,7 +1557,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { None => "immutable item".to_owned(), }; - // call find_assignments() here let mut err = self.tcx .cannot_borrow_path_as_mutable(span, &item_msg, Origin::Mir); err.span_label(span, "cannot borrow as mutable"); @@ -1604,6 +1573,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { if let Err(place_err) = self.is_mutable(place, is_local_mutation_allowed) { error_reported = true; + match *place{ + Place::Local(local) => {let locations = self.mir.find_assignments(local); + + for n in &locations{ + debug!("locations ={:?}", n);} + } + _ => {}} + let item_msg = if error_reported{ if let Some(name) = self.describe_place(place_err) { format!("`&`-reference {}", name) @@ -2269,12 +2246,3 @@ impl ContextKind { } } -impl Mir { - fn find_assignments(&self, local: Local, place_context:PlaceContext, location:Location) -> Vec - { - let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![], location:location, place_context: }; - visitor.visit_mir(self); - visitor.locations - } -} - diff --git a/src/librustc_mir/util/mod.rs b/src/librustc_mir/util/mod.rs index eebe5a86018e..19cd37668862 100644 --- a/src/librustc_mir/util/mod.rs +++ b/src/librustc_mir/util/mod.rs @@ -17,6 +17,7 @@ mod alignment; mod graphviz; pub(crate) mod pretty; pub mod liveness; +pub mod collect_writes; pub use self::alignment::is_disaligned; pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};