14
14
//! but is not as ugly as it is right now.
15
15
16
16
use rustc:: mir:: { BasicBlock , Location } ;
17
+ use rustc:: ty:: RegionVid ;
17
18
use rustc_data_structures:: indexed_set:: Iter ;
18
19
19
- use dataflow:: { MaybeInitializedPlaces , MaybeUninitializedPlaces } ;
20
+ use borrow_check:: location:: LocationIndex ;
21
+
22
+ use polonius_engine:: Output ;
23
+
24
+ use dataflow:: move_paths:: indexes:: BorrowIndex ;
25
+ use dataflow:: move_paths:: HasMoveData ;
26
+ use dataflow:: Borrows ;
20
27
use dataflow:: { EverInitializedPlaces , MovingOutStatements } ;
21
- use dataflow:: { Borrows } ;
22
28
use dataflow:: { FlowAtLocation , FlowsAtLocation } ;
23
- use dataflow:: move_paths :: HasMoveData ;
24
- use dataflow :: move_paths :: indexes :: BorrowIndex ;
29
+ use dataflow:: { MaybeInitializedPlaces , MaybeUninitializedPlaces } ;
30
+ use either :: Either ;
25
31
use std:: fmt;
32
+ use std:: rc:: Rc ;
26
33
27
34
// (forced to be `pub` due to its use as an associated type below.)
28
35
crate struct Flows < ' b , ' gcx : ' tcx , ' tcx : ' b > {
@@ -31,6 +38,9 @@ crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
31
38
pub uninits : FlowAtLocation < MaybeUninitializedPlaces < ' b , ' gcx , ' tcx > > ,
32
39
pub move_outs : FlowAtLocation < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
33
40
pub ever_inits : FlowAtLocation < EverInitializedPlaces < ' b , ' gcx , ' tcx > > ,
41
+
42
+ /// Polonius Output
43
+ pub polonius_output : Option < Rc < Output < RegionVid , BorrowIndex , LocationIndex > > > ,
34
44
}
35
45
36
46
impl < ' b , ' gcx , ' tcx > Flows < ' b , ' gcx , ' tcx > {
@@ -40,18 +50,27 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
40
50
uninits : FlowAtLocation < MaybeUninitializedPlaces < ' b , ' gcx , ' tcx > > ,
41
51
move_outs : FlowAtLocation < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
42
52
ever_inits : FlowAtLocation < EverInitializedPlaces < ' b , ' gcx , ' tcx > > ,
53
+ polonius_output : Option < Rc < Output < RegionVid , BorrowIndex , LocationIndex > > > ,
43
54
) -> Self {
44
55
Flows {
45
56
borrows,
46
57
inits,
47
58
uninits,
48
59
move_outs,
49
60
ever_inits,
61
+ polonius_output,
50
62
}
51
63
}
52
64
53
- crate fn borrows_in_scope ( & self ) -> impl Iterator < Item = BorrowIndex > + ' _ {
54
- self . borrows . iter_incoming ( )
65
+ crate fn borrows_in_scope (
66
+ & self ,
67
+ location : LocationIndex ,
68
+ ) -> impl Iterator < Item = BorrowIndex > + ' _ {
69
+ if let Some ( ref polonius) = self . polonius_output {
70
+ Either :: Left ( polonius. errors_at ( location) . iter ( ) . cloned ( ) )
71
+ } else {
72
+ Either :: Right ( self . borrows . iter_incoming ( ) )
73
+ }
55
74
}
56
75
57
76
crate fn with_outgoing_borrows ( & self , op : impl FnOnce ( Iter < BorrowIndex > ) ) {
@@ -66,7 +85,7 @@ macro_rules! each_flow {
66
85
FlowAtLocation :: $meth( & mut $this. uninits, $arg) ;
67
86
FlowAtLocation :: $meth( & mut $this. move_outs, $arg) ;
68
87
FlowAtLocation :: $meth( & mut $this. ever_inits, $arg) ;
69
- }
88
+ } ;
70
89
}
71
90
72
91
impl < ' b , ' gcx , ' tcx > FlowsAtLocation for Flows < ' b , ' gcx , ' tcx > {
@@ -134,8 +153,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
134
153
s. push_str ( ", " ) ;
135
154
} ;
136
155
saw_one = true ;
137
- let move_path =
138
- & self . uninits . operator ( ) . move_data ( ) . move_paths [ mpi_uninit] ;
156
+ let move_path = & self . uninits . operator ( ) . move_data ( ) . move_paths [ mpi_uninit] ;
139
157
s. push_str ( & format ! ( "{}" , move_path) ) ;
140
158
} ) ;
141
159
s. push_str ( "] " ) ;
@@ -159,8 +177,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
159
177
s. push_str ( ", " ) ;
160
178
} ;
161
179
saw_one = true ;
162
- let ever_init =
163
- & self . ever_inits . operator ( ) . move_data ( ) . inits [ mpi_ever_init] ;
180
+ let ever_init = & self . ever_inits . operator ( ) . move_data ( ) . inits [ mpi_ever_init] ;
164
181
s. push_str ( & format ! ( "{:?}" , ever_init) ) ;
165
182
} ) ;
166
183
s. push_str ( "]" ) ;
0 commit comments