@@ -12,6 +12,7 @@ use rustc_middle::mir::{
1212 Statement , StatementKind , Terminator , TerminatorKind , UnOp , START_BLOCK ,
1313} ;
1414use rustc_middle:: ty:: fold:: BottomUpFolder ;
15+ use rustc_middle:: ty:: subst:: Subst ;
1516use rustc_middle:: ty:: { self , InstanceDef , ParamEnv , Ty , TyCtxt , TypeFoldable , TypeVisitable } ;
1617use rustc_mir_dataflow:: impls:: MaybeStorageLive ;
1718use rustc_mir_dataflow:: storage:: always_live_locals;
@@ -275,7 +276,14 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
275276 }
276277 } ;
277278
278- match parent_ty. ty . kind ( ) {
279+ let kind = match parent_ty. ty . kind ( ) {
280+ & ty:: Opaque ( def_id, substs) => {
281+ self . tcx . bound_type_of ( def_id) . subst ( self . tcx , substs) . kind ( )
282+ }
283+ kind => kind,
284+ } ;
285+
286+ match kind {
279287 ty:: Tuple ( fields) => {
280288 let Some ( f_ty) = fields. get ( f. as_usize ( ) ) else {
281289 fail_out_of_bounds ( self , location) ;
@@ -299,12 +307,39 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
299307 } ;
300308 check_equal ( self , location, f_ty) ;
301309 }
302- ty:: Generator ( _, substs, _) => {
303- let substs = substs. as_generator ( ) ;
304- let Some ( f_ty) = substs. upvar_tys ( ) . nth ( f. as_usize ( ) ) else {
305- fail_out_of_bounds ( self , location) ;
306- return ;
310+ & ty:: Generator ( def_id, substs, _) => {
311+ let f_ty = if let Some ( var) = parent_ty. variant_index {
312+ let gen_body = if def_id == self . body . source . def_id ( ) {
313+ self . body
314+ } else {
315+ self . tcx . optimized_mir ( def_id)
316+ } ;
317+
318+ let Some ( layout) = gen_body. generator_layout ( ) else {
319+ self . fail ( location, format ! ( "No generator layout for {:?}" , parent_ty) ) ;
320+ return ;
321+ } ;
322+
323+ let Some ( & local) = layout. variant_fields [ var] . get ( f) else {
324+ fail_out_of_bounds ( self , location) ;
325+ return ;
326+ } ;
327+
328+ let Some ( & f_ty) = layout. field_tys . get ( local) else {
329+ self . fail ( location, format ! ( "Out of bounds local {:?} for {:?}" , local, parent_ty) ) ;
330+ return ;
331+ } ;
332+
333+ f_ty
334+ } else {
335+ let Some ( f_ty) = substs. as_generator ( ) . prefix_tys ( ) . nth ( f. index ( ) ) else {
336+ fail_out_of_bounds ( self , location) ;
337+ return ;
338+ } ;
339+
340+ f_ty
307341 } ;
342+
308343 check_equal ( self , location, f_ty) ;
309344 }
310345 _ => {
@@ -328,6 +363,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
328363 {
329364 self . fail ( location, format ! ( "{:?}, has deref at the wrong place" , place) ) ;
330365 }
366+
367+ self . super_place ( place, cntxt, location) ;
331368 }
332369
333370 fn visit_rvalue ( & mut self , rvalue : & Rvalue < ' tcx > , location : Location ) {
0 commit comments