@@ -102,6 +102,8 @@ fn convert_to_hir_projections_and_truncate_for_capture<'tcx>(
102
102
variant = Some ( * idx) ;
103
103
continue ;
104
104
}
105
+ // These do not affect anything, they just make sure we know the right type.
106
+ ProjectionElem :: OpaqueCast ( _) => continue ,
105
107
ProjectionElem :: Index ( ..)
106
108
| ProjectionElem :: ConstantIndex { .. }
107
109
| ProjectionElem :: Subslice { .. } => {
@@ -168,7 +170,7 @@ fn find_capture_matching_projections<'a, 'tcx>(
168
170
/// `PlaceBuilder` now starts from `PlaceBase::Local`.
169
171
///
170
172
/// Returns a Result with the error being the PlaceBuilder (`from_builder`) that was not found.
171
- #[ instrument( level = "trace" , skip( cx) ) ]
173
+ #[ instrument( level = "trace" , skip( cx) , ret ) ]
172
174
fn to_upvars_resolved_place_builder < ' tcx > (
173
175
from_builder : PlaceBuilder < ' tcx > ,
174
176
cx : & Builder < ' _ , ' tcx > ,
@@ -213,7 +215,6 @@ fn to_upvars_resolved_place_builder<'tcx>(
213
215
& capture. captured_place . place . projections ,
214
216
) ;
215
217
upvar_resolved_place_builder. projection . extend ( remaining_projections) ;
216
- trace ! ( ?upvar_resolved_place_builder) ;
217
218
218
219
Ok ( upvar_resolved_place_builder)
219
220
}
@@ -232,16 +233,21 @@ fn strip_prefix<'tcx>(
232
233
prefix_projections : & [ HirProjection < ' tcx > ] ,
233
234
) -> impl Iterator < Item = PlaceElem < ' tcx > > {
234
235
let mut iter = projections. into_iter ( ) ;
236
+ let mut next = || match iter. next ( ) ? {
237
+ // Filter out opaque casts, they are unnecessary in the prefix.
238
+ ProjectionElem :: OpaqueCast ( ..) => iter. next ( ) ,
239
+ other => Some ( other) ,
240
+ } ;
235
241
for projection in prefix_projections {
236
242
match projection. kind {
237
243
HirProjectionKind :: Deref => {
238
- assert ! ( matches!( iter . next( ) , Some ( ProjectionElem :: Deref ) ) ) ;
244
+ assert ! ( matches!( next( ) , Some ( ProjectionElem :: Deref ) ) ) ;
239
245
}
240
246
HirProjectionKind :: Field ( ..) => {
241
247
if base_ty. is_enum ( ) {
242
- assert ! ( matches!( iter . next( ) , Some ( ProjectionElem :: Downcast ( ..) ) ) ) ;
248
+ assert ! ( matches!( next( ) , Some ( ProjectionElem :: Downcast ( ..) ) ) ) ;
243
249
}
244
- assert ! ( matches!( iter . next( ) , Some ( ProjectionElem :: Field ( ..) ) ) ) ;
250
+ assert ! ( matches!( next( ) , Some ( ProjectionElem :: Field ( ..) ) ) ) ;
245
251
}
246
252
HirProjectionKind :: Index | HirProjectionKind :: Subslice => {
247
253
bug ! ( "unexpected projection kind: {:?}" , projection) ;
@@ -711,6 +717,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
711
717
}
712
718
ProjectionElem :: Field ( ..)
713
719
| ProjectionElem :: Downcast ( ..)
720
+ | ProjectionElem :: OpaqueCast ( ..)
714
721
| ProjectionElem :: ConstantIndex { .. }
715
722
| ProjectionElem :: Subslice { .. } => ( ) ,
716
723
}
0 commit comments