@@ -4,9 +4,9 @@ use super::namespace::item_namespace;
4
4
use super :: CrateDebugContext ;
5
5
6
6
use rustc_hir:: def_id:: DefId ;
7
- use rustc_middle:: ty:: layout:: LayoutOf ;
7
+ use rustc_middle:: ty:: layout:: { HasParamEnv , LayoutOf } ;
8
8
use rustc_middle:: ty:: { self , DefIdTree , Ty } ;
9
- use rustc_target :: abi :: Variants ;
9
+ use tracing :: trace ;
10
10
11
11
use crate :: common:: CodegenCx ;
12
12
use crate :: llvm;
@@ -63,38 +63,37 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>(
63
63
cx : & CodegenCx < ' ll , ' tcx > ,
64
64
pointee_ty : Ty < ' tcx > ,
65
65
) -> Option < FatPtrKind > {
66
- let layout = cx. layout_of ( pointee_ty) ;
66
+ let pointee_tail_ty = cx. tcx . struct_tail_erasing_lifetimes ( pointee_ty, cx. param_env ( ) ) ;
67
+ let layout = cx. layout_of ( pointee_tail_ty) ;
68
+ trace ! (
69
+ "fat_pointer_kind: {:?} has layout {:?} (is_unsized? {})" ,
70
+ pointee_tail_ty,
71
+ layout,
72
+ layout. is_unsized( )
73
+ ) ;
67
74
68
75
if !layout. is_unsized ( ) {
69
76
return None ;
70
77
}
71
78
72
- match * pointee_ty . kind ( ) {
79
+ match * pointee_tail_ty . kind ( ) {
73
80
ty:: Str | ty:: Slice ( _) => Some ( FatPtrKind :: Slice ) ,
74
81
ty:: Dynamic ( ..) => Some ( FatPtrKind :: Dyn ) ,
75
- ty:: Adt ( ..) | ty:: Tuple ( ..) if matches ! ( layout. variants, Variants :: Single { .. } ) => {
76
- let last_field_index = layout. fields . count ( ) - 1 ;
77
- debug_assert ! (
78
- ( 0 ..last_field_index)
79
- . all( |field_index| { !layout. field( cx, field_index) . is_unsized( ) } )
80
- ) ;
81
-
82
- let unsized_field = layout. field ( cx, last_field_index) ;
83
- debug_assert ! ( unsized_field. is_unsized( ) ) ;
84
- fat_pointer_kind ( cx, unsized_field. ty )
85
- }
86
82
ty:: Foreign ( _) => {
87
83
// Assert that pointers to foreign types really are thin:
88
84
debug_assert_eq ! (
89
- cx. size_of( cx. tcx. mk_imm_ptr( pointee_ty ) ) ,
85
+ cx. size_of( cx. tcx. mk_imm_ptr( pointee_tail_ty ) ) ,
90
86
cx. size_of( cx. tcx. mk_imm_ptr( cx. tcx. types. u8 ) )
91
87
) ;
92
88
None
93
89
}
94
90
_ => {
95
91
// For all other pointee types we should already have returned None
96
92
// at the beginning of the function.
97
- panic ! ( "fat_pointer_kind() - Encountered unexpected `pointee_ty`: {:?}" , pointee_ty)
93
+ panic ! (
94
+ "fat_pointer_kind() - Encountered unexpected `pointee_tail_ty`: {:?}" ,
95
+ pointee_tail_ty
96
+ )
98
97
}
99
98
}
100
99
}
0 commit comments