about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgaurikholkar <f2013002@goa.bits-pilani.ac.in>2018-03-02 10:46:01 +0530
committergaurikholkar <f2013002@goa.bits-pilani.ac.in>2018-03-10 20:52:22 +0530
commit3f0ce0858e4a07239ea6d38c14991bba46c413fc (patch)
tree7d5a388c688999d62b0b86d94c4852ac1c206ae5
parentf60788b9b2267eb9b0de742939207730f0b9b3e1 (diff)
downloadrust-3f0ce0858e4a07239ea6d38c14991bba46c413fc.tar.gz
rust-3f0ce0858e4a07239ea6d38c14991bba46c413fc.zip
minor refactorings to fix trait import issue
-rw-r--r--src/librustc_mir/borrow_check/mod.rs52
-rw-r--r--src/librustc_mir/util/mod.rs1
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 aa4a704254e..90e84a47809 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<Location>,
-    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<Location> 
-    { 
-        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 eebe5a86018..19cd3766886 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};