@@ -4,7 +4,7 @@ use rustc_errors::struct_span_err;
4
4
use rustc_hir as hir;
5
5
use rustc_index:: vec:: Idx ;
6
6
use rustc_middle:: ty:: layout:: { LayoutError , SizeSkeleton } ;
7
- use rustc_middle:: ty:: { self , Article , FloatTy , InferTy , IntTy , Ty , TyCtxt , TypeFoldable , UintTy } ;
7
+ use rustc_middle:: ty:: { self , Article , FloatTy , IntTy , Ty , TyCtxt , TypeFoldable , UintTy } ;
8
8
use rustc_session:: lint;
9
9
use rustc_span:: { Span , Symbol , DUMMY_SP } ;
10
10
use rustc_target:: abi:: { Pointer , VariantIdx } ;
@@ -99,8 +99,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
99
99
err. emit ( ) ;
100
100
}
101
101
102
+ // FIXME(compiler-errors): This could use `<$ty as Pointee>::Metadata == ()`
102
103
fn is_thin_ptr_ty ( & self , ty : Ty < ' tcx > ) -> bool {
103
- if ty. is_sized ( self . tcx . at ( DUMMY_SP ) , self . param_env ) {
104
+ // Type still may have region variables, but `Sized` does not depend
105
+ // on those, so just erase them before querying.
106
+ if self . tcx . erase_regions ( ty) . is_sized ( self . tcx . at ( DUMMY_SP ) , self . param_env ) {
104
107
return true ;
105
108
}
106
109
if let ty:: Foreign ( ..) = ty. kind ( ) {
@@ -128,30 +131,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
128
131
64 => InlineAsmType :: I64 ,
129
132
_ => unreachable ! ( ) ,
130
133
} ;
134
+
135
+ // Expect types to be fully resolved, no const or type variables.
136
+ if ty. has_infer_types_or_consts ( ) {
137
+ assert ! ( self . is_tainted_by_errors( ) ) ;
138
+ return None ;
139
+ }
140
+
131
141
let asm_ty = match * ty. kind ( ) {
132
142
// `!` is allowed for input but not for output (issue #87802)
133
143
ty:: Never if is_input => return None ,
134
144
ty:: Error ( _) => return None ,
135
145
ty:: Int ( IntTy :: I8 ) | ty:: Uint ( UintTy :: U8 ) => Some ( InlineAsmType :: I8 ) ,
136
146
ty:: Int ( IntTy :: I16 ) | ty:: Uint ( UintTy :: U16 ) => Some ( InlineAsmType :: I16 ) ,
137
- // Somewhat of a hack: fallback in the presence of errors does not actually
138
- // fall back to i32, but to ty::Error. For integer inference variables this
139
- // means that they don't get any fallback and stay as `{integer}`.
140
- // Since compilation can't succeed anyway, it's fine to use this to avoid printing
141
- // "cannot use value of type `{integer}`", even though that would absolutely
142
- // work due due i32 fallback if the current function had no other errors.
143
- ty:: Infer ( InferTy :: IntVar ( _) ) => {
144
- assert ! ( self . is_tainted_by_errors( ) ) ;
145
- Some ( InlineAsmType :: I32 )
146
- }
147
147
ty:: Int ( IntTy :: I32 ) | ty:: Uint ( UintTy :: U32 ) => Some ( InlineAsmType :: I32 ) ,
148
148
ty:: Int ( IntTy :: I64 ) | ty:: Uint ( UintTy :: U64 ) => Some ( InlineAsmType :: I64 ) ,
149
149
ty:: Int ( IntTy :: I128 ) | ty:: Uint ( UintTy :: U128 ) => Some ( InlineAsmType :: I128 ) ,
150
150
ty:: Int ( IntTy :: Isize ) | ty:: Uint ( UintTy :: Usize ) => Some ( asm_ty_isize) ,
151
- ty:: Infer ( InferTy :: FloatVar ( _) ) => {
152
- assert ! ( self . is_tainted_by_errors( ) ) ;
153
- Some ( InlineAsmType :: F32 )
154
- }
155
151
ty:: Float ( FloatTy :: F32 ) => Some ( InlineAsmType :: F32 ) ,
156
152
ty:: Float ( FloatTy :: F64 ) => Some ( InlineAsmType :: F64 ) ,
157
153
ty:: FnPtr ( _) => Some ( asm_ty_isize) ,
@@ -191,6 +187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
191
187
_ => None ,
192
188
}
193
189
}
190
+ ty:: Infer ( _) => unreachable ! ( ) ,
194
191
_ => None ,
195
192
} ;
196
193
let Some ( asm_ty) = asm_ty else {
@@ -204,11 +201,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
204
201
return None ;
205
202
} ;
206
203
207
- if ty. has_infer_types_or_consts ( ) {
208
- assert ! ( self . is_tainted_by_errors( ) ) ;
209
- return None ;
210
- }
211
-
212
204
// Check that the type implements Copy. The only case where this can
213
205
// possibly fail is for SIMD types which don't #[derive(Copy)].
214
206
if !self . infcx . type_is_copy_modulo_regions ( self . param_env , ty, DUMMY_SP ) {
0 commit comments