@@ -879,7 +879,7 @@ fn sanitize_witness<'tcx>(
879
879
880
880
let mut mismatches = Vec :: new ( ) ;
881
881
for fty in & layout. field_tys {
882
- if fty. is_static_ptr {
882
+ if fty. ignore_for_traits {
883
883
continue ;
884
884
}
885
885
let decl_ty = tcx. normalize_erasing_regions ( param_env, fty. ty ) ;
@@ -904,6 +904,7 @@ fn sanitize_witness<'tcx>(
904
904
}
905
905
906
906
fn compute_layout < ' tcx > (
907
+ tcx : TyCtxt < ' tcx > ,
907
908
liveness : LivenessInfo ,
908
909
body : & Body < ' tcx > ,
909
910
) -> (
@@ -923,15 +924,33 @@ fn compute_layout<'tcx>(
923
924
let mut locals = IndexVec :: < GeneratorSavedLocal , _ > :: new ( ) ;
924
925
let mut tys = IndexVec :: < GeneratorSavedLocal , _ > :: new ( ) ;
925
926
for ( saved_local, local) in saved_locals. iter_enumerated ( ) {
927
+ debug ! ( "generator saved local {:?} => {:?}" , saved_local, local) ;
928
+
926
929
locals. push ( local) ;
927
930
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
932
948
} ;
949
+ let decl =
950
+ GeneratorSavedTy { ty : decl. ty , source_info : decl. source_info , ignore_for_traits } ;
951
+ debug ! ( ?decl) ;
952
+
933
953
tys. push ( decl) ;
934
- debug ! ( "generator saved local {:?} => {:?}" , saved_local, local) ;
935
954
}
936
955
937
956
// Leave empty variants for the UNRESUMED, RETURNED, and POISONED states.
@@ -1401,7 +1420,7 @@ pub(crate) fn mir_generator_witnesses<'tcx>(
1401
1420
// Extract locals which are live across suspension point into `layout`
1402
1421
// `remap` gives a mapping from local indices onto generator struct indices
1403
1422
// `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) ;
1405
1424
1406
1425
if tcx. sess . opts . unstable_opts . drop_tracking_mir {
1407
1426
check_suspend_tys ( tcx, & generator_layout, & body) ;
@@ -1503,7 +1522,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform {
1503
1522
// Extract locals which are live across suspension point into `layout`
1504
1523
// `remap` gives a mapping from local indices onto generator struct indices
1505
1524
// `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) ;
1507
1526
1508
1527
let can_return = can_return ( tcx, body, tcx. param_env ( body. source . def_id ( ) ) ) ;
1509
1528
@@ -1700,7 +1719,7 @@ fn check_suspend_tys<'tcx>(tcx: TyCtxt<'tcx>, layout: &GeneratorLayout<'tcx>, bo
1700
1719
let decl = & layout. field_tys [ local] ;
1701
1720
debug ! ( ?decl) ;
1702
1721
1703
- if !decl. is_static_ptr && linted_tys. insert ( decl. ty ) {
1722
+ if !decl. ignore_for_traits && linted_tys. insert ( decl. ty ) {
1704
1723
let Some ( hir_id) = decl. source_info . scope . lint_root ( & body. source_scopes ) else { continue } ;
1705
1724
1706
1725
check_must_not_suspend_ty (
0 commit comments