@@ -4,7 +4,7 @@ use rustc_errors::struct_span_err;
44use rustc_hir as hir;
55use rustc_index:: vec:: Idx ;
66use rustc_middle:: ty:: layout:: { LayoutError , SizeSkeleton } ;
7- use rustc_middle:: ty:: { self , Article , FloatTy , InferTy , IntTy , Ty , TyCtxt , TypeVisitable , UintTy } ;
7+ use rustc_middle:: ty:: { self , Article , FloatTy , IntTy , Ty , TyCtxt , TypeVisitable , UintTy } ;
88use rustc_session:: lint;
99use rustc_span:: { Span , Symbol , DUMMY_SP } ;
1010use rustc_target:: abi:: { Pointer , VariantIdx } ;
@@ -99,8 +99,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9999 err. emit ( ) ;
100100 }
101101
102+ // FIXME(compiler-errors): This could use `<$ty as Pointee>::Metadata == ()`
102103 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 ) {
104107 return true ;
105108 }
106109 if let ty:: Foreign ( ..) = ty. kind ( ) {
@@ -128,30 +131,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
128131 64 => InlineAsmType :: I64 ,
129132 _ => unreachable ! ( ) ,
130133 } ;
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+
131141 let asm_ty = match * ty. kind ( ) {
132142 // `!` is allowed for input but not for output (issue #87802)
133143 ty:: Never if is_input => return None ,
134144 ty:: Error ( _) => return None ,
135145 ty:: Int ( IntTy :: I8 ) | ty:: Uint ( UintTy :: U8 ) => Some ( InlineAsmType :: I8 ) ,
136146 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- }
147147 ty:: Int ( IntTy :: I32 ) | ty:: Uint ( UintTy :: U32 ) => Some ( InlineAsmType :: I32 ) ,
148148 ty:: Int ( IntTy :: I64 ) | ty:: Uint ( UintTy :: U64 ) => Some ( InlineAsmType :: I64 ) ,
149149 ty:: Int ( IntTy :: I128 ) | ty:: Uint ( UintTy :: U128 ) => Some ( InlineAsmType :: I128 ) ,
150150 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- }
155151 ty:: Float ( FloatTy :: F32 ) => Some ( InlineAsmType :: F32 ) ,
156152 ty:: Float ( FloatTy :: F64 ) => Some ( InlineAsmType :: F64 ) ,
157153 ty:: FnPtr ( _) => Some ( asm_ty_isize) ,
@@ -191,6 +187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
191187 _ => None ,
192188 }
193189 }
190+ ty:: Infer ( _) => unreachable ! ( ) ,
194191 _ => None ,
195192 } ;
196193 let Some ( asm_ty) = asm_ty else {
@@ -204,11 +201,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
204201 return None ;
205202 } ;
206203
207- if ty. has_infer_types_or_consts ( ) {
208- assert ! ( self . is_tainted_by_errors( ) ) ;
209- return None ;
210- }
211-
212204 // Check that the type implements Copy. The only case where this can
213205 // possibly fail is for SIMD types which don't #[derive(Copy)].
214206 if !self . infcx . type_is_copy_modulo_regions ( self . param_env , ty, DUMMY_SP ) {
0 commit comments