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