1414//! but is not as ugly as it is right now.
1515
1616use rustc:: mir:: { BasicBlock , Location } ;
17+ use rustc:: ty:: RegionVid ;
1718use rustc_data_structures:: indexed_set:: Iter ;
1819
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 ;
2027use dataflow:: { EverInitializedPlaces , MovingOutStatements } ;
21- use dataflow:: { Borrows } ;
2228use 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 ;
2531use std:: fmt;
32+ use std:: rc:: Rc ;
2633
2734// (forced to be `pub` due to its use as an associated type below.)
2835crate struct Flows < ' b , ' gcx : ' tcx , ' tcx : ' b > {
@@ -31,6 +38,9 @@ crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
3138 pub uninits : FlowAtLocation < MaybeUninitializedPlaces < ' b , ' gcx , ' tcx > > ,
3239 pub move_outs : FlowAtLocation < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
3340 pub ever_inits : FlowAtLocation < EverInitializedPlaces < ' b , ' gcx , ' tcx > > ,
41+
42+ /// Polonius Output
43+ pub polonius_output : Option < Rc < Output < RegionVid , BorrowIndex , LocationIndex > > > ,
3444}
3545
3646impl < ' b , ' gcx , ' tcx > Flows < ' b , ' gcx , ' tcx > {
@@ -40,18 +50,27 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
4050 uninits : FlowAtLocation < MaybeUninitializedPlaces < ' b , ' gcx , ' tcx > > ,
4151 move_outs : FlowAtLocation < MovingOutStatements < ' b , ' gcx , ' tcx > > ,
4252 ever_inits : FlowAtLocation < EverInitializedPlaces < ' b , ' gcx , ' tcx > > ,
53+ polonius_output : Option < Rc < Output < RegionVid , BorrowIndex , LocationIndex > > > ,
4354 ) -> Self {
4455 Flows {
4556 borrows,
4657 inits,
4758 uninits,
4859 move_outs,
4960 ever_inits,
61+ polonius_output,
5062 }
5163 }
5264
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+ }
5574 }
5675
5776 crate fn with_outgoing_borrows ( & self , op : impl FnOnce ( Iter < BorrowIndex > ) ) {
@@ -66,7 +85,7 @@ macro_rules! each_flow {
6685 FlowAtLocation :: $meth( & mut $this. uninits, $arg) ;
6786 FlowAtLocation :: $meth( & mut $this. move_outs, $arg) ;
6887 FlowAtLocation :: $meth( & mut $this. ever_inits, $arg) ;
69- }
88+ } ;
7089}
7190
7291impl < ' b , ' gcx , ' tcx > FlowsAtLocation for Flows < ' b , ' gcx , ' tcx > {
@@ -134,8 +153,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
134153 s. push_str ( ", " ) ;
135154 } ;
136155 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] ;
139157 s. push_str ( & format ! ( "{}" , move_path) ) ;
140158 } ) ;
141159 s. push_str ( "] " ) ;
@@ -159,8 +177,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
159177 s. push_str ( ", " ) ;
160178 } ;
161179 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] ;
164181 s. push_str ( & format ! ( "{:?}" , ever_init) ) ;
165182 } ) ;
166183 s. push_str ( "]" ) ;
0 commit comments