@@ -17,7 +17,7 @@ use rustc::hir::map::definitions::DefPathData;
17
17
use rustc:: infer:: InferCtxt ;
18
18
use rustc:: ty:: { self , ParamEnv , TyCtxt } ;
19
19
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 } ;
21
21
use rustc:: mir:: { Mir , Mutability , Operand , Projection , ProjectionElem , Rvalue } ;
22
22
use rustc:: mir:: { Field , Statement , StatementKind , Terminator , TerminatorKind } ;
23
23
use rustc:: mir:: ClosureRegionRequirements ;
@@ -43,6 +43,7 @@ use dataflow::indexes::BorrowIndex;
43
43
use dataflow:: move_paths:: { IllegalMoveOriginKind , MoveError } ;
44
44
use dataflow:: move_paths:: { HasMoveData , LookupResult , MoveData , MovePathIndex } ;
45
45
use util:: borrowck_errors:: { BorrowckErrors , Origin } ;
46
+ use util:: collect_writes:: FindAssignments ;
46
47
47
48
use std:: iter;
48
49
@@ -56,37 +57,6 @@ mod prefixes;
56
57
57
58
use std:: borrow:: Cow ;
58
59
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
-
90
60
pub ( crate ) mod nll;
91
61
92
62
pub fn provide ( providers : & mut Providers ) {
@@ -1587,7 +1557,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1587
1557
None => "immutable item" . to_owned ( ) ,
1588
1558
} ;
1589
1559
1590
- // call find_assignments() here
1591
1560
let mut err = self . tcx
1592
1561
. cannot_borrow_path_as_mutable ( span, & item_msg, Origin :: Mir ) ;
1593
1562
err. span_label ( span, "cannot borrow as mutable" ) ;
@@ -1604,6 +1573,14 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
1604
1573
if let Err ( place_err) = self . is_mutable ( place, is_local_mutation_allowed) {
1605
1574
error_reported = true ;
1606
1575
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
+
1607
1584
let item_msg = if error_reported{
1608
1585
if let Some ( name) = self . describe_place ( place_err) {
1609
1586
format ! ( "`&`-reference {}" , name)
@@ -2269,12 +2246,3 @@ impl ContextKind {
2269
2246
}
2270
2247
}
2271
2248
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
-
0 commit comments