33use rustc_middle:: mir:: visit:: Visitor ;
44use rustc_middle:: mir:: {
55 Body , Local , Location , Place , PlaceRef , ProjectionElem , Rvalue , Statement , StatementKind ,
6- Terminator , TerminatorKind , UserTypeProjection ,
6+ Terminator , TerminatorKind ,
77} ;
8- use rustc_middle:: ty:: { TyCtxt , Variance } ;
8+ use rustc_middle:: ty:: TyCtxt ;
99
1010use crate :: { borrow_set:: BorrowSet , facts:: AllFacts , location:: LocationTable , places_conflict} ;
1111
12- pub ( super ) fn generate_constraints < ' tcx > (
12+ /// Emit `loan_killed_at` and `cfg_edge` facts at the same time.
13+ pub ( super ) fn emit_loan_kills < ' tcx > (
1314 tcx : TyCtxt < ' tcx > ,
1415 all_facts : & mut AllFacts ,
1516 location_table : & LocationTable ,
1617 body : & Body < ' tcx > ,
1718 borrow_set : & BorrowSet < ' tcx > ,
1819) {
1920 let _prof_timer = tcx. prof . generic_activity ( "polonius_fact_generation" ) ;
20- let mut cg = ConstraintGeneration { borrow_set, tcx, location_table, all_facts, body } ;
21+ let mut visitor = LoanKillsGenerator { borrow_set, tcx, location_table, all_facts, body } ;
2122 for ( bb, data) in body. basic_blocks . iter_enumerated ( ) {
22- cg . visit_basic_block_data ( bb, data) ;
23+ visitor . visit_basic_block_data ( bb, data) ;
2324 }
2425}
2526
26- /// 'cg = the duration of the constraint generation process itself.
27- struct ConstraintGeneration < ' cg , ' tcx > {
27+ struct LoanKillsGenerator < ' cx , ' tcx > {
2828 tcx : TyCtxt < ' tcx > ,
29- all_facts : & ' cg mut AllFacts ,
30- location_table : & ' cg LocationTable ,
31- borrow_set : & ' cg BorrowSet < ' tcx > ,
32- body : & ' cg Body < ' tcx > ,
29+ all_facts : & ' cx mut AllFacts ,
30+ location_table : & ' cx LocationTable ,
31+ borrow_set : & ' cx BorrowSet < ' tcx > ,
32+ body : & ' cx Body < ' tcx > ,
3333}
3434
35- impl < ' cg , ' tcx > Visitor < ' tcx > for ConstraintGeneration < ' cg , ' tcx > {
35+ impl < ' cx , ' tcx > Visitor < ' tcx > for LoanKillsGenerator < ' cx , ' tcx > {
3636 fn visit_statement ( & mut self , statement : & Statement < ' tcx > , location : Location ) {
37+ // Also record CFG facts here.
3738 self . all_facts . cfg_edge . push ( (
3839 self . location_table . start_index ( location) ,
3940 self . location_table . mid_index ( location) ,
@@ -56,11 +57,11 @@ impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
5657 // When we see `X = ...`, then kill borrows of
5758 // `(*X).foo` and so forth.
5859 self . record_killed_borrows_for_place ( * place, location) ;
59-
6060 self . super_assign ( place, rvalue, location) ;
6161 }
6262
6363 fn visit_terminator ( & mut self , terminator : & Terminator < ' tcx > , location : Location ) {
64+ // Also record CFG facts here.
6465 self . all_facts . cfg_edge . push ( (
6566 self . location_table . start_index ( location) ,
6667 self . location_table . mid_index ( location) ,
@@ -83,20 +84,11 @@ impl<'cg, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'tcx> {
8384
8485 self . super_terminator ( terminator, location) ;
8586 }
86-
87- fn visit_ascribe_user_ty (
88- & mut self ,
89- _place : & Place < ' tcx > ,
90- _variance : Variance ,
91- _user_ty : & UserTypeProjection ,
92- _location : Location ,
93- ) {
94- }
9587}
9688
97- impl < ' cx , ' tcx > ConstraintGeneration < ' cx , ' tcx > {
98- /// When recording facts for Polonius, records the borrows on the specified place
99- /// as `killed`. For example, when assigning to a local, or on a call's return destination.
89+ impl < ' tcx > LoanKillsGenerator < ' _ , ' tcx > {
90+ /// Records the borrows on the specified place as `killed`. For example, when assigning to a
91+ /// local, or on a call's return destination.
10092 fn record_killed_borrows_for_place ( & mut self , place : Place < ' tcx > , location : Location ) {
10193 // Depending on the `Place` we're killing:
10294 // - if it's a local, or a single deref of a local,
@@ -143,7 +135,7 @@ impl<'cx, 'tcx> ConstraintGeneration<'cx, 'tcx> {
143135 }
144136 }
145137
146- /// When recording facts for Polonius, records the borrows on the specified local as `killed`.
138+ /// Records the borrows on the specified local as `killed`.
147139 fn record_killed_borrows_for_local ( & mut self , local : Local , location : Location ) {
148140 if let Some ( borrow_indices) = self . borrow_set . local_map . get ( & local) {
149141 let location_index = self . location_table . mid_index ( location) ;
0 commit comments