@@ -90,62 +90,59 @@ pub(super) struct ElaborateBoxDerefs;
90
90
91
91
impl < ' tcx > MirPass < ' tcx > for ElaborateBoxDerefs {
92
92
fn run_pass ( & self , tcx : TyCtxt < ' tcx > , body : & mut Body < ' tcx > ) {
93
- if let Some ( def_id ) = tcx . lang_items ( ) . owned_box ( ) {
94
- let unique_did = tcx. adt_def ( def_id ) . non_enum_variant ( ) . fields [ FieldIdx :: ZERO ] . did ;
93
+ // If box is not present, this pass doesn't need to do anything.
94
+ let Some ( def_id ) = tcx. lang_items ( ) . owned_box ( ) else { return } ;
95
95
96
- let Some ( nonnull_def) = tcx. type_of ( unique_did) . instantiate_identity ( ) . ty_adt_def ( )
97
- else {
98
- span_bug ! ( tcx. def_span( unique_did) , "expected Box to contain Unique" )
99
- } ;
96
+ let unique_did = tcx. adt_def ( def_id) . non_enum_variant ( ) . fields [ FieldIdx :: ZERO ] . did ;
100
97
101
- let nonnull_did = nonnull_def. non_enum_variant ( ) . fields [ FieldIdx :: ZERO ] . did ;
98
+ let Some ( nonnull_def) = tcx. type_of ( unique_did) . instantiate_identity ( ) . ty_adt_def ( ) else {
99
+ span_bug ! ( tcx. def_span( unique_did) , "expected Box to contain Unique" )
100
+ } ;
102
101
103
- let patch = MirPatch :: new ( body ) ;
102
+ let nonnull_did = nonnull_def . non_enum_variant ( ) . fields [ FieldIdx :: ZERO ] . did ;
104
103
105
- let local_decls = & mut body. local_decls ;
104
+ let patch = MirPatch :: new ( body) ;
106
105
107
- let mut visitor =
108
- ElaborateBoxDerefVisitor { tcx, unique_did, nonnull_did, local_decls, patch } ;
106
+ let local_decls = & mut body. local_decls ;
109
107
110
- for ( block, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
111
- visitor. visit_basic_block_data ( block, data) ;
112
- }
108
+ let mut visitor =
109
+ ElaborateBoxDerefVisitor { tcx, unique_did, nonnull_did, local_decls, patch } ;
113
110
114
- visitor. patch . apply ( body) ;
111
+ for ( block, data) in body. basic_blocks . as_mut_preserves_cfg ( ) . iter_enumerated_mut ( ) {
112
+ visitor. visit_basic_block_data ( block, data) ;
113
+ }
115
114
116
- for debug_info in body. var_debug_info . iter_mut ( ) {
117
- if let VarDebugInfoContents :: Place ( place) = & mut debug_info. value {
118
- let mut new_projections: Option < Vec < _ > > = None ;
115
+ visitor. patch . apply ( body) ;
119
116
120
- for ( base, elem) in place. iter_projections ( ) {
121
- let base_ty = base. ty ( & body. local_decls , tcx) . ty ;
117
+ for debug_info in body. var_debug_info . iter_mut ( ) {
118
+ if let VarDebugInfoContents :: Place ( place) = & mut debug_info. value {
119
+ let mut new_projections: Option < Vec < _ > > = None ;
122
120
123
- if elem == PlaceElem :: Deref && base_ty. is_box ( ) {
124
- // Clone the projections before us, since now we need to mutate them.
125
- let new_projections =
126
- new_projections. get_or_insert_with ( || base. projection . to_vec ( ) ) ;
121
+ for ( base, elem) in place. iter_projections ( ) {
122
+ let base_ty = base. ty ( & body. local_decls , tcx) . ty ;
127
123
128
- let ( unique_ty, nonnull_ty, ptr_ty) =
129
- build_ptr_tys ( tcx, base_ty. boxed_ty ( ) , unique_did, nonnull_did) ;
124
+ if elem == PlaceElem :: Deref && base_ty. is_box ( ) {
125
+ // Clone the projections before us, since now we need to mutate them.
126
+ let new_projections =
127
+ new_projections. get_or_insert_with ( || base. projection . to_vec ( ) ) ;
130
128
131
- new_projections. extend_from_slice ( & build_projection (
132
- unique_ty, nonnull_ty, ptr_ty,
133
- ) ) ;
134
- new_projections. push ( PlaceElem :: Deref ) ;
135
- } else if let Some ( new_projections) = new_projections. as_mut ( ) {
136
- // Keep building up our projections list once we've started it.
137
- new_projections. push ( elem) ;
138
- }
139
- }
129
+ let ( unique_ty, nonnull_ty, ptr_ty) =
130
+ build_ptr_tys ( tcx, base_ty. boxed_ty ( ) , unique_did, nonnull_did) ;
140
131
141
- // Store the mutated projections if we actually changed something.
142
- if let Some ( new_projections) = new_projections {
143
- place. projection = tcx. mk_place_elems ( & new_projections) ;
132
+ new_projections
133
+ . extend_from_slice ( & build_projection ( unique_ty, nonnull_ty, ptr_ty) ) ;
134
+ new_projections. push ( PlaceElem :: Deref ) ;
135
+ } else if let Some ( new_projections) = new_projections. as_mut ( ) {
136
+ // Keep building up our projections list once we've started it.
137
+ new_projections. push ( elem) ;
144
138
}
145
139
}
140
+
141
+ // Store the mutated projections if we actually changed something.
142
+ if let Some ( new_projections) = new_projections {
143
+ place. projection = tcx. mk_place_elems ( & new_projections) ;
144
+ }
146
145
}
147
- } else {
148
- // box is not present, this pass doesn't need to do anything
149
146
}
150
147
}
151
148
}
0 commit comments