@@ -879,7 +879,7 @@ fn sanitize_witness<'tcx>(
879879
880880 let mut mismatches = Vec :: new ( ) ;
881881 for fty in & layout. field_tys {
882- if fty. is_static_ptr {
882+ if fty. ignore_for_traits {
883883 continue ;
884884 }
885885 let decl_ty = tcx. normalize_erasing_regions ( param_env, fty. ty ) ;
@@ -904,6 +904,7 @@ fn sanitize_witness<'tcx>(
904904}
905905
906906fn compute_layout < ' tcx > (
907+ tcx : TyCtxt < ' tcx > ,
907908 liveness : LivenessInfo ,
908909 body : & Body < ' tcx > ,
909910) -> (
@@ -923,15 +924,33 @@ fn compute_layout<'tcx>(
923924 let mut locals = IndexVec :: < GeneratorSavedLocal , _ > :: new ( ) ;
924925 let mut tys = IndexVec :: < GeneratorSavedLocal , _ > :: new ( ) ;
925926 for ( saved_local, local) in saved_locals. iter_enumerated ( ) {
927+ debug ! ( "generator saved local {:?} => {:?}" , saved_local, local) ;
928+
926929 locals. push ( local) ;
927930 let decl = & body. local_decls [ local] ;
928- let decl = GeneratorSavedTy {
929- ty : decl. ty ,
930- source_info : decl. source_info ,
931- is_static_ptr : decl. internal ,
931+ debug ! ( ?decl) ;
932+
933+ let ignore_for_traits = if tcx. sess . opts . unstable_opts . drop_tracking_mir {
934+ match decl. local_info {
935+ // Do not include raw pointers created from accessing `static` items, as those could
936+ // well be re-created by another access to the same static.
937+ Some ( box LocalInfo :: StaticRef { is_thread_local, .. } ) => !is_thread_local,
938+ // Fake borrows are only read by fake reads, so do not have any reality in
939+ // post-analysis MIR.
940+ Some ( box LocalInfo :: FakeBorrow ) => true ,
941+ _ => false ,
942+ }
943+ } else {
944+ // FIXME(#105084) HIR-based drop tracking does not account for all the temporaries that
945+ // MIR building may introduce. This leads to wrongly ignored types, but this is
946+ // necessary for internal consistency and to avoid ICEs.
947+ decl. internal
932948 } ;
949+ let decl =
950+ GeneratorSavedTy { ty : decl. ty , source_info : decl. source_info , ignore_for_traits } ;
951+ debug ! ( ?decl) ;
952+
933953 tys. push ( decl) ;
934- debug ! ( "generator saved local {:?} => {:?}" , saved_local, local) ;
935954 }
936955
937956 // Leave empty variants for the UNRESUMED, RETURNED, and POISONED states.
@@ -1401,7 +1420,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
14011420 // Extract locals which are live across suspension point into `layout`
14021421 // `remap` gives a mapping from local indices onto generator struct indices
14031422 // `storage_liveness` tells us which locals have live storage at suspension points
1404- let ( _, generator_layout, _) = compute_layout ( liveness_info, body) ;
1423+ let ( _, generator_layout, _) = compute_layout ( tcx , liveness_info, body) ;
14051424
14061425 if tcx. sess . opts . unstable_opts . drop_tracking_mir {
14071426 check_suspend_tys ( tcx, & generator_layout, & body) ;
@@ -1503,7 +1522,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
15031522 // Extract locals which are live across suspension point into `layout`
15041523 // `remap` gives a mapping from local indices onto generator struct indices
15051524 // `storage_liveness` tells us which locals have live storage at suspension points
1506- let ( remap, layout, storage_liveness) = compute_layout ( liveness_info, body) ;
1525+ let ( remap, layout, storage_liveness) = compute_layout ( tcx , liveness_info, body) ;
15071526
15081527 let can_return = can_return ( tcx, body, tcx. param_env ( body. source . def_id ( ) ) ) ;
15091528
@@ -1700,7 +1719,7 @@ fn check_suspend_tys<'tcx>(tcx: TyCtxt<'tcx>, layout: &GeneratorLayout<'tcx>, bo
17001719 let decl = & layout. field_tys [ local] ;
17011720 debug ! ( ?decl) ;
17021721
1703- if !decl. is_static_ptr && linted_tys. insert ( decl. ty ) {
1722+ if !decl. ignore_for_traits && linted_tys. insert ( decl. ty ) {
17041723 let Some ( hir_id) = decl. source_info . scope . lint_root ( & body. source_scopes ) else { continue } ;
17051724
17061725 check_must_not_suspend_ty (
0 commit comments