1
+ use std:: { cell:: RefCell , iter, rc:: Rc } ;
2
+
3
+ use log:: { debug, info} ;
4
+ use rustc_data_structures:: fx:: FxHashMap as HashMap ;
5
+ use rustc_hir:: { def_id:: DefId , BodyId } ;
6
+ use rustc_middle:: {
7
+ mir:: { visit:: Visitor , * } ,
8
+ ty:: { subst:: GenericArgKind , ClosureKind , TyCtxt , TyKind } ,
9
+ } ;
10
+ use rustc_mir_dataflow:: { Analysis , AnalysisDomain , Forward , JoinSemiLattice } ;
11
+
1
12
use super :: { FlowResults , BODY_STACK } ;
2
13
use crate :: {
3
14
extensions:: { is_extension_active, ContextMode , MutabilityMode , REACHED_LIBRARY } ,
@@ -12,15 +23,6 @@ use crate::{
12
23
utils:: { self , OperandExt , PlaceCollector , PlaceExt } ,
13
24
} ,
14
25
} ;
15
- use log:: { debug, info} ;
16
- use rustc_data_structures:: fx:: FxHashMap as HashMap ;
17
- use rustc_hir:: { def_id:: DefId , BodyId } ;
18
- use rustc_middle:: {
19
- mir:: { visit:: Visitor , * } ,
20
- ty:: { subst:: GenericArgKind , ClosureKind , TyCtxt , TyKind } ,
21
- } ;
22
- use rustc_mir_dataflow:: { Analysis , AnalysisDomain , Forward , JoinSemiLattice } ;
23
- use std:: { cell:: RefCell , iter, rc:: Rc } ;
24
26
25
27
pub type FlowDomain < ' tcx > = IndexMatrix < Place < ' tcx > , Location > ;
26
28
@@ -103,7 +105,8 @@ impl TransferFunction<'_, '_, 'tcx> {
103
105
104
106
// Remove any conflicts that aren't actually mutable, e.g. if x : &T ends up
105
107
// as an alias of y: &mut T
106
- let ignore_mut = is_extension_active ( |mode| mode. mutability_mode == MutabilityMode :: IgnoreMut ) ;
108
+ let ignore_mut =
109
+ is_extension_active ( |mode| mode. mutability_mode == MutabilityMode :: IgnoreMut ) ;
107
110
if !ignore_mut {
108
111
let body = self . analysis . body ;
109
112
let tcx = self . analysis . tcx ;
@@ -126,7 +129,11 @@ impl TransferFunction<'_, '_, 'tcx> {
126
129
}
127
130
}
128
131
129
- fn recurse_into_call ( & mut self , call : & TerminatorKind < ' tcx > , location : Location ) -> bool {
132
+ fn recurse_into_call (
133
+ & mut self ,
134
+ call : & TerminatorKind < ' tcx > ,
135
+ location : Location ,
136
+ ) -> bool {
130
137
let tcx = self . analysis . tcx ;
131
138
let ( func, parent_args, destination) = match call {
132
139
TerminatorKind :: Call {
@@ -248,7 +255,9 @@ impl TransferFunction<'_, '_, 'tcx> {
248
255
let parent_aliases = & self . analysis . aliases ;
249
256
let child_domain = flow. analysis . place_domain ( ) ;
250
257
251
- let translate_child_to_parent = |child : Place < ' tcx > , mutated : bool | -> Option < Place < ' tcx > > {
258
+ let translate_child_to_parent = |child : Place < ' tcx > ,
259
+ mutated : bool |
260
+ -> Option < Place < ' tcx > > {
252
261
if child. local == RETURN_PLACE && child. projection . len ( ) == 0 {
253
262
if child. ty ( body. local_decls ( ) , tcx) . ty . is_unit ( ) {
254
263
return None ;
@@ -279,13 +288,16 @@ impl TransferFunction<'_, '_, 'tcx> {
279
288
let parent_arg_projected = Place :: make ( parent_toplevel_arg. local , & projection, tcx) ;
280
289
281
290
let parent_arg_accessible = {
282
- let mut sub_places = ( 0 ..=parent_arg_projected. projection . len ( ) ) . rev ( ) . map ( |i| {
283
- Place :: make (
284
- parent_arg_projected. local ,
285
- & parent_arg_projected. projection [ ..i] ,
286
- tcx,
287
- )
288
- } ) ;
291
+ let mut sub_places =
292
+ ( 0 ..= parent_arg_projected. projection . len ( ) )
293
+ . rev ( )
294
+ . map ( |i| {
295
+ Place :: make (
296
+ parent_arg_projected. local ,
297
+ & parent_arg_projected. projection [ .. i] ,
298
+ tcx,
299
+ )
300
+ } ) ;
289
301
290
302
sub_places
291
303
. find ( |sub_place| {
@@ -314,7 +326,9 @@ impl TransferFunction<'_, '_, 'tcx> {
314
326
let parent_deps = return_state
315
327
. rows ( )
316
328
. filter ( |( _, deps) | child_deps. is_superset ( deps) )
317
- . filter_map ( |( row, _) | translate_child_to_parent ( * child_domain. value ( row) , false ) )
329
+ . filter_map ( |( row, _) | {
330
+ translate_child_to_parent ( * child_domain. value ( row) , false )
331
+ } )
318
332
. collect :: < Vec < _ > > ( ) ;
319
333
320
334
debug ! (
@@ -331,7 +345,12 @@ impl TransferFunction<'_, '_, 'tcx> {
331
345
}
332
346
333
347
impl Visitor < ' tcx > for TransferFunction < ' a , ' b , ' tcx > {
334
- fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
348
+ fn visit_assign (
349
+ & mut self ,
350
+ place : & Place < ' tcx > ,
351
+ rvalue : & Rvalue < ' tcx > ,
352
+ location : Location ,
353
+ ) {
335
354
debug ! ( "Checking {:?}: {:?} = {:?}" , location, place, rvalue) ;
336
355
let mut collector = PlaceCollector :: default ( ) ;
337
356
collector. visit_rvalue ( rvalue, location) ;
0 commit comments