11//! Removes assignments to ZST places.
22
33use crate :: transform:: MirPass ;
4- use rustc_data_structures:: fx:: FxHashMap ;
54use rustc_middle:: mir:: { Body , StatementKind } ;
65use rustc_middle:: ty:: TyCtxt ;
76
@@ -10,35 +9,23 @@ pub struct RemoveZsts;
109impl < ' tcx > MirPass < ' tcx > for RemoveZsts {
1110 fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
1211 let param_env = tcx. param_env ( body. source . def_id ( ) ) ;
13-
1412 let ( basic_blocks, local_decls) = body. basic_blocks_and_local_decls_mut ( ) ;
15-
16- let mut is_zst_cache = FxHashMap :: default ( ) ;
17-
1813 for block in basic_blocks. iter_mut ( ) {
1914 for statement in block. statements . iter_mut ( ) {
2015 match statement. kind {
2116 StatementKind :: Assign ( box ( place, _) ) => {
2217 let place_ty = place. ty ( local_decls, tcx) . ty ;
23-
24- let is_inhabited_zst = * is_zst_cache. entry ( place_ty) . or_insert_with ( || {
25- if let Ok ( layout) = tcx. layout_of ( param_env. and ( place_ty) ) {
26- if layout. is_zst ( ) && !layout. abi . is_uninhabited ( ) {
27- return true ;
18+ if let Ok ( layout) = tcx. layout_of ( param_env. and ( place_ty) ) {
19+ if layout. is_zst ( ) && !layout. abi . is_uninhabited ( ) {
20+ if tcx. consider_optimizing ( || {
21+ format ! (
22+ "RemoveZsts - Place: {:?} SourceInfo: {:?}" ,
23+ place, statement. source_info
24+ )
25+ } ) {
26+ statement. make_nop ( ) ;
2827 }
2928 }
30- false
31- } ) ;
32-
33- if is_inhabited_zst {
34- if tcx. consider_optimizing ( || {
35- format ! (
36- "RemoveZsts - Place: {:?} SourceInfo: {:?}" ,
37- place, statement. source_info
38- )
39- } ) {
40- statement. make_nop ( ) ;
41- }
4229 }
4330 }
4431 _ => { }
0 commit comments