@@ -86,7 +86,9 @@ use hir_ty::{
8686 method_resolution,
8787 mir:: { MutBorrowKind , interpret_mir} ,
8888 next_solver:: {
89- ClauseKind , DbInterner , GenericArgs , infer:: InferCtxt , mapping:: ChalkToNextSolver ,
89+ ClauseKind , DbInterner , GenericArgs ,
90+ infer:: InferCtxt ,
91+ mapping:: { ChalkToNextSolver , convert_ty_for_result} ,
9092 } ,
9193 primitive:: UintTy ,
9294 traits:: FnTrait ,
@@ -1346,19 +1348,12 @@ impl Field {
13461348 u32:: from ( self . id . into_raw ( ) ) as usize
13471349 }
13481350
1349- /// Returns the type as in the signature of the struct (i.e., with
1350- /// placeholder types for type parameters). Only use this in the context of
1351- /// the field definition.
1352- pub fn ty < ' db > ( & self , db : & ' db dyn HirDatabase ) -> Type < ' db > {
1351+ /// Returns the type as in the signature of the struct. Only use this in the
1352+ /// context of the field definition.
1353+ pub fn ty < ' db > ( & self , db : & ' db dyn HirDatabase ) -> TypeNs < ' db > {
13531354 let var_id = self . parent . into ( ) ;
1354- let generic_def_id: GenericDefId = match self . parent {
1355- VariantDef :: Struct ( it) => it. id . into ( ) ,
1356- VariantDef :: Union ( it) => it. id . into ( ) ,
1357- VariantDef :: Variant ( it) => it. id . lookup ( db) . parent . into ( ) ,
1358- } ;
1359- let substs = TyBuilder :: placeholder_subst ( db, generic_def_id) ;
1360- let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
1361- Type :: new ( db, var_id, ty)
1355+ let ty = db. field_types_ns ( var_id) [ self . id ] . skip_binder ( ) ;
1356+ TypeNs :: new ( db, var_id, ty)
13621357 }
13631358
13641359 // FIXME: Find better API to also handle const generics
@@ -1388,9 +1383,8 @@ impl Field {
13881383 }
13891384
13901385 pub fn layout ( & self , db : & dyn HirDatabase ) -> Result < Layout , LayoutError > {
1391- let interner = DbInterner :: new_with ( db, None , None ) ;
13921386 db. layout_of_ty (
1393- self . ty ( db) . ty . to_nextsolver ( interner ) ,
1387+ self . ty ( db) . ty ,
13941388 db. trait_environment ( match hir_def:: VariantId :: from ( self . parent ) {
13951389 hir_def:: VariantId :: EnumVariantId ( id) => {
13961390 GenericDefId :: AdtId ( id. lookup ( db) . parent . into ( ) )
@@ -5969,6 +5963,11 @@ impl<'db> TypeNs<'db> {
59695963 TypeNs { env : environment, ty, _pd : PhantomCovariantLifetime :: new ( ) }
59705964 }
59715965
5966+ pub fn to_type ( & self , db : & ' db dyn HirDatabase ) -> Type < ' db > {
5967+ let interner = DbInterner :: new_with ( db, Some ( self . env . krate ) , self . env . block ) ;
5968+ Type { env : self . env . clone ( ) , ty : convert_ty_for_result ( interner, self . ty ) , _pd : self . _pd }
5969+ }
5970+
59725971 // FIXME: Find better API that also handles const generics
59735972 pub fn impls_trait ( & self , infcx : InferCtxt < ' db > , trait_ : Trait , args : & [ TypeNs < ' db > ] ) -> bool {
59745973 let args = GenericArgs :: new_from_iter (
@@ -5992,6 +5991,10 @@ impl<'db> TypeNs<'db> {
59925991 let res = hir_ty:: traits:: next_trait_solve_in_ctxt ( & infcx, goal) ;
59935992 res. map_or ( false , |res| matches ! ( res. 1 , rustc_type_ir:: solve:: Certainty :: Yes ) )
59945993 }
5994+
5995+ pub fn is_bool ( & self ) -> bool {
5996+ matches ! ( self . ty. kind( ) , rustc_type_ir:: TyKind :: Bool )
5997+ }
59955998}
59965999
59976000#[ derive( Debug , PartialEq , Eq , Copy , Clone , Hash ) ]
0 commit comments