@@ -4,7 +4,7 @@ use rustc_index::vec::IndexVec;
44use rustc_middle:: mir:: patch:: MirPatch ;
55use rustc_middle:: mir:: visit:: * ;
66use rustc_middle:: mir:: * ;
7- use rustc_middle:: ty:: { Ty , TyCtxt } ;
7+ use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
88use rustc_mir_dataflow:: value_analysis:: { excluded_locals, iter_fields} ;
99
1010pub struct ScalarReplacementOfAggregates ;
@@ -18,11 +18,12 @@ impl<'tcx> MirPass<'tcx> for ScalarReplacementOfAggregates {
1818 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
1919 debug ! ( def_id = ?body. source. def_id( ) ) ;
2020 let mut excluded = excluded_locals ( body) ;
21+ let param_env = tcx. param_env_reveal_all_normalized ( body. source . def_id ( ) ) ;
2122 loop {
2223 debug ! ( ?excluded) ;
2324 let escaping = escaping_locals ( & excluded, body) ;
2425 debug ! ( ?escaping) ;
25- let replacements = compute_flattening ( tcx, body, escaping) ;
26+ let replacements = compute_flattening ( tcx, param_env , body, escaping) ;
2627 debug ! ( ?replacements) ;
2728 let all_dead_locals = replace_flattened_locals ( tcx, body, replacements) ;
2829 if !all_dead_locals. is_empty ( ) {
@@ -144,6 +145,7 @@ impl<'tcx> ReplacementMap<'tcx> {
144145/// The replacement will be done later in `ReplacementVisitor`.
145146fn compute_flattening < ' tcx > (
146147 tcx : TyCtxt < ' tcx > ,
148+ param_env : ty:: ParamEnv < ' tcx > ,
147149 body : & mut Body < ' tcx > ,
148150 escaping : BitSet < Local > ,
149151) -> ReplacementMap < ' tcx > {
@@ -155,7 +157,7 @@ fn compute_flattening<'tcx>(
155157 }
156158 let decl = body. local_decls [ local] . clone ( ) ;
157159 let ty = decl. ty ;
158- iter_fields ( ty, tcx, |variant, field, field_ty| {
160+ iter_fields ( ty, tcx, param_env , |variant, field, field_ty| {
159161 if variant. is_some ( ) {
160162 // Downcasts are currently not supported.
161163 return ;
0 commit comments