@@ -110,21 +110,34 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
110
110
}
111
111
112
112
fn visit_statement ( & mut self , statement : & mut Statement < ' tcx > , loc : Location ) {
113
- if let StatementKind :: Assign ( box ( place, _) ) | StatementKind :: Deinit ( box place) =
114
- statement. kind
115
- {
116
- let place_ty = place. ty ( self . local_decls , self . tcx ) . ty ;
117
- if self . known_to_be_zst ( place_ty)
118
- && self . tcx . consider_optimizing ( || {
119
- format ! (
120
- "RemoveZsts - Place: {:?} SourceInfo: {:?}" ,
121
- place, statement. source_info
122
- )
123
- } )
124
- {
125
- statement. make_nop ( ) ;
113
+ let place_for_ty = match statement. kind {
114
+ StatementKind :: Assign ( box ( place, ref rvalue) ) => {
115
+ rvalue. is_safe_to_remove ( ) . then_some ( place)
116
+ }
117
+ StatementKind :: Deinit ( box place)
118
+ | StatementKind :: SetDiscriminant { box place, variant_index : _ }
119
+ | StatementKind :: AscribeUserType ( box ( place, _) , _)
120
+ | StatementKind :: Retag ( _, box place)
121
+ | StatementKind :: PlaceMention ( box place)
122
+ | StatementKind :: FakeRead ( box ( _, place) ) => Some ( place) ,
123
+ StatementKind :: StorageLive ( local) | StatementKind :: StorageDead ( local) => {
124
+ Some ( local. into ( ) )
126
125
}
126
+ StatementKind :: Coverage ( _)
127
+ | StatementKind :: Intrinsic ( _)
128
+ | StatementKind :: Nop
129
+ | StatementKind :: ConstEvalCounter => None ,
130
+ } ;
131
+ if let Some ( place_for_ty) = place_for_ty
132
+ && let ty = place_for_ty. ty ( self . local_decls , self . tcx ) . ty
133
+ && self . known_to_be_zst ( ty)
134
+ && self . tcx . consider_optimizing ( || {
135
+ format ! ( "RemoveZsts - Place: {:?} SourceInfo: {:?}" , place_for_ty, statement. source_info)
136
+ } )
137
+ {
138
+ statement. make_nop ( ) ;
139
+ } else {
140
+ self . super_statement ( statement, loc) ;
127
141
}
128
- self . super_statement ( statement, loc) ;
129
142
}
130
143
}
0 commit comments