@@ -86,7 +86,9 @@ use hir_ty::{
86
86
method_resolution,
87
87
mir:: { MutBorrowKind , interpret_mir} ,
88
88
next_solver:: {
89
- ClauseKind , DbInterner , GenericArgs , infer:: InferCtxt , mapping:: ChalkToNextSolver ,
89
+ ClauseKind , DbInterner , GenericArgs ,
90
+ infer:: InferCtxt ,
91
+ mapping:: { ChalkToNextSolver , convert_ty_for_result} ,
90
92
} ,
91
93
primitive:: UintTy ,
92
94
traits:: FnTrait ,
@@ -1346,19 +1348,12 @@ impl Field {
1346
1348
u32:: from ( self . id . into_raw ( ) ) as usize
1347
1349
}
1348
1350
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 > {
1353
1354
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)
1362
1357
}
1363
1358
1364
1359
// FIXME: Find better API to also handle const generics
@@ -1388,9 +1383,8 @@ impl Field {
1388
1383
}
1389
1384
1390
1385
pub fn layout ( & self , db : & dyn HirDatabase ) -> Result < Layout , LayoutError > {
1391
- let interner = DbInterner :: new_with ( db, None , None ) ;
1392
1386
db. layout_of_ty (
1393
- self . ty ( db) . ty . to_nextsolver ( interner ) ,
1387
+ self . ty ( db) . ty ,
1394
1388
db. trait_environment ( match hir_def:: VariantId :: from ( self . parent ) {
1395
1389
hir_def:: VariantId :: EnumVariantId ( id) => {
1396
1390
GenericDefId :: AdtId ( id. lookup ( db) . parent . into ( ) )
@@ -5969,6 +5963,11 @@ impl<'db> TypeNs<'db> {
5969
5963
TypeNs { env : environment, ty, _pd : PhantomCovariantLifetime :: new ( ) }
5970
5964
}
5971
5965
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
+
5972
5971
// FIXME: Find better API that also handles const generics
5973
5972
pub fn impls_trait ( & self , infcx : InferCtxt < ' db > , trait_ : Trait , args : & [ TypeNs < ' db > ] ) -> bool {
5974
5973
let args = GenericArgs :: new_from_iter (
@@ -5992,6 +5991,10 @@ impl<'db> TypeNs<'db> {
5992
5991
let res = hir_ty:: traits:: next_trait_solve_in_ctxt ( & infcx, goal) ;
5993
5992
res. map_or ( false , |res| matches ! ( res. 1 , rustc_type_ir:: solve:: Certainty :: Yes ) )
5994
5993
}
5994
+
5995
+ pub fn is_bool ( & self ) -> bool {
5996
+ matches ! ( self . ty. kind( ) , rustc_type_ir:: TyKind :: Bool )
5997
+ }
5995
5998
}
5996
5999
5997
6000
#[ derive( Debug , PartialEq , Eq , Copy , Clone , Hash ) ]
0 commit comments