@@ -809,7 +809,7 @@ impl Field {
809
809
} ;
810
810
let substs = TyBuilder :: placeholder_subst ( db, generic_def_id) ;
811
811
let ty = db. field_types ( var_id) [ self . id ] . clone ( ) . substitute ( Interner , & substs) ;
812
- Type :: new ( db, self . parent . module ( db ) . id . krate ( ) , var_id, ty)
812
+ Type :: new ( db, var_id, ty)
813
813
}
814
814
815
815
pub fn parent_def ( & self , _db : & dyn HirDatabase ) -> VariantDef {
@@ -850,7 +850,7 @@ impl Struct {
850
850
}
851
851
852
852
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
853
- Type :: from_def ( db, self . id . lookup ( db . upcast ( ) ) . container . krate ( ) , self . id )
853
+ Type :: from_def ( db, self . id )
854
854
}
855
855
856
856
pub fn repr ( self , db : & dyn HirDatabase ) -> Option < ReprKind > {
@@ -887,7 +887,7 @@ impl Union {
887
887
}
888
888
889
889
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
890
- Type :: from_def ( db, self . id . lookup ( db . upcast ( ) ) . container . krate ( ) , self . id )
890
+ Type :: from_def ( db, self . id )
891
891
}
892
892
893
893
pub fn fields ( self , db : & dyn HirDatabase ) -> Vec < Field > {
@@ -929,7 +929,7 @@ impl Enum {
929
929
}
930
930
931
931
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
932
- Type :: from_def ( db, self . id . lookup ( db . upcast ( ) ) . container . krate ( ) , self . id )
932
+ Type :: from_def ( db, self . id )
933
933
}
934
934
}
935
935
@@ -1005,7 +1005,7 @@ impl Adt {
1005
1005
/// general set of completions, but will not look very nice when printed.
1006
1006
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
1007
1007
let id = AdtId :: from ( self ) ;
1008
- Type :: from_def ( db, id. module ( db . upcast ( ) ) . krate ( ) , id )
1008
+ Type :: from_def ( db, id)
1009
1009
}
1010
1010
1011
1011
/// Turns this ADT into a type with the given type parameters. This isn't
@@ -1022,8 +1022,7 @@ impl Adt {
1022
1022
}
1023
1023
} )
1024
1024
. build ( ) ;
1025
- let krate = id. module ( db. upcast ( ) ) . krate ( ) ;
1026
- Type :: new ( db, krate, id, ty)
1025
+ Type :: new ( db, id, ty)
1027
1026
}
1028
1027
1029
1028
pub fn module ( self , db : & dyn HirDatabase ) -> Module {
@@ -1213,18 +1212,8 @@ impl DefWithBody {
1213
1212
acc. push (
1214
1213
TypeMismatch {
1215
1214
expr,
1216
- expected : Type :: new (
1217
- db,
1218
- krate,
1219
- DefWithBodyId :: from ( self ) ,
1220
- mismatch. expected . clone ( ) ,
1221
- ) ,
1222
- actual : Type :: new (
1223
- db,
1224
- krate,
1225
- DefWithBodyId :: from ( self ) ,
1226
- mismatch. actual . clone ( ) ,
1227
- ) ,
1215
+ expected : Type :: new ( db, DefWithBodyId :: from ( self ) , mismatch. expected . clone ( ) ) ,
1216
+ actual : Type :: new ( db, DefWithBodyId :: from ( self ) , mismatch. actual . clone ( ) ) ,
1228
1217
}
1229
1218
. into ( ) ,
1230
1219
) ;
@@ -1369,11 +1358,10 @@ impl Function {
1369
1358
/// Get this function's return type
1370
1359
pub fn ret_type ( self , db : & dyn HirDatabase ) -> Type {
1371
1360
let resolver = self . id . resolver ( db. upcast ( ) ) ;
1372
- let krate = self . krate_id ( db) ;
1373
1361
let ret_type = & db. function_data ( self . id ) . ret_type ;
1374
1362
let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
1375
1363
let ty = ctx. lower_ty ( ret_type) ;
1376
- Type :: new_with_resolver_inner ( db, krate , & resolver, ty)
1364
+ Type :: new_with_resolver_inner ( db, & resolver, ty)
1377
1365
}
1378
1366
1379
1367
pub fn self_param ( self , db : & dyn HirDatabase ) -> Option < SelfParam > {
@@ -1385,15 +1373,14 @@ impl Function {
1385
1373
1386
1374
pub fn assoc_fn_params ( self , db : & dyn HirDatabase ) -> Vec < Param > {
1387
1375
let resolver = self . id . resolver ( db. upcast ( ) ) ;
1388
- let krate = self . krate_id ( db) ;
1389
1376
let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
1390
1377
let environment = db. trait_environment ( self . id . into ( ) ) ;
1391
1378
db. function_data ( self . id )
1392
1379
. params
1393
1380
. iter ( )
1394
1381
. enumerate ( )
1395
1382
. map ( |( idx, ( _, type_ref) ) | {
1396
- let ty = Type { krate , env : environment. clone ( ) , ty : ctx. lower_ty ( type_ref) } ;
1383
+ let ty = Type { env : environment. clone ( ) , ty : ctx. lower_ty ( type_ref) } ;
1397
1384
Param { func : self , ty, idx }
1398
1385
} )
1399
1386
. collect ( )
@@ -1408,7 +1395,6 @@ impl Function {
1408
1395
1409
1396
pub fn params_without_self ( self , db : & dyn HirDatabase ) -> Vec < Param > {
1410
1397
let resolver = self . id . resolver ( db. upcast ( ) ) ;
1411
- let krate = self . krate_id ( db) ;
1412
1398
let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
1413
1399
let environment = db. trait_environment ( self . id . into ( ) ) ;
1414
1400
let skip = if db. function_data ( self . id ) . has_self_param ( ) { 1 } else { 0 } ;
@@ -1418,7 +1404,7 @@ impl Function {
1418
1404
. enumerate ( )
1419
1405
. skip ( skip)
1420
1406
. map ( |( idx, ( _, type_ref) ) | {
1421
- let ty = Type { krate , env : environment. clone ( ) , ty : ctx. lower_ty ( type_ref) } ;
1407
+ let ty = Type { env : environment. clone ( ) , ty : ctx. lower_ty ( type_ref) } ;
1422
1408
Param { func : self , ty, idx }
1423
1409
} )
1424
1410
. collect ( )
@@ -1470,10 +1456,6 @@ impl Function {
1470
1456
1471
1457
result
1472
1458
}
1473
-
1474
- fn krate_id ( self , db : & dyn HirDatabase ) -> CrateId {
1475
- self . id . lookup ( db. upcast ( ) ) . module ( db. upcast ( ) ) . krate ( )
1476
- }
1477
1459
}
1478
1460
1479
1461
// Note: logically, this belongs to `hir_ty`, but we are not using it there yet.
@@ -1575,11 +1557,10 @@ impl SelfParam {
1575
1557
1576
1558
pub fn ty ( & self , db : & dyn HirDatabase ) -> Type {
1577
1559
let resolver = self . func . resolver ( db. upcast ( ) ) ;
1578
- let krate = self . func . lookup ( db. upcast ( ) ) . container . module ( db. upcast ( ) ) . krate ( ) ;
1579
1560
let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
1580
1561
let environment = db. trait_environment ( self . func . into ( ) ) ;
1581
1562
1582
- Type { krate , env : environment, ty : ctx. lower_ty ( & db. function_data ( self . func ) . params [ 0 ] . 1 ) }
1563
+ Type { env : environment, ty : ctx. lower_ty ( & db. function_data ( self . func ) . params [ 0 ] . 1 ) }
1583
1564
}
1584
1565
}
1585
1566
@@ -1610,10 +1591,9 @@ impl Const {
1610
1591
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
1611
1592
let data = db. const_data ( self . id ) ;
1612
1593
let resolver = self . id . resolver ( db. upcast ( ) ) ;
1613
- let krate = self . id . lookup ( db. upcast ( ) ) . container . krate ( db) ;
1614
1594
let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
1615
1595
let ty = ctx. lower_ty ( & data. type_ref ) ;
1616
- Type :: new_with_resolver_inner ( db, krate . id , & resolver, ty)
1596
+ Type :: new_with_resolver_inner ( db, & resolver, ty)
1617
1597
}
1618
1598
1619
1599
pub fn eval ( self , db : & dyn HirDatabase ) -> Result < ComputedExpr , ConstEvalError > {
@@ -1652,10 +1632,9 @@ impl Static {
1652
1632
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
1653
1633
let data = db. static_data ( self . id ) ;
1654
1634
let resolver = self . id . resolver ( db. upcast ( ) ) ;
1655
- let krate = self . id . lookup ( db. upcast ( ) ) . container . module ( db. upcast ( ) ) . krate ( ) ;
1656
1635
let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
1657
1636
let ty = ctx. lower_ty ( & data. type_ref ) ;
1658
- Type :: new_with_resolver_inner ( db, krate , & resolver, ty)
1637
+ Type :: new_with_resolver_inner ( db, & resolver, ty)
1659
1638
}
1660
1639
}
1661
1640
@@ -1727,7 +1706,7 @@ impl TypeAlias {
1727
1706
}
1728
1707
1729
1708
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
1730
- Type :: from_def ( db, self . id . lookup ( db . upcast ( ) ) . module ( db . upcast ( ) ) . krate ( ) , self . id )
1709
+ Type :: from_def ( db, self . id )
1731
1710
}
1732
1711
1733
1712
pub fn name ( self , db : & dyn HirDatabase ) -> Name {
@@ -2185,8 +2164,7 @@ impl Local {
2185
2164
let def = self . parent ;
2186
2165
let infer = db. infer ( def) ;
2187
2166
let ty = infer[ self . pat_id ] . clone ( ) ;
2188
- let krate = def. module ( db. upcast ( ) ) . krate ( ) ;
2189
- Type :: new ( db, krate, def, ty)
2167
+ Type :: new ( db, def, ty)
2190
2168
}
2191
2169
2192
2170
pub fn associated_locals ( self , db : & dyn HirDatabase ) -> Box < [ Local ] > {
@@ -2373,10 +2351,9 @@ impl TypeParam {
2373
2351
2374
2352
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
2375
2353
let resolver = self . id . parent ( ) . resolver ( db. upcast ( ) ) ;
2376
- let krate = self . id . parent ( ) . module ( db. upcast ( ) ) . krate ( ) ;
2377
2354
let ty =
2378
2355
TyKind :: Placeholder ( hir_ty:: to_placeholder_idx ( db, self . id . into ( ) ) ) . intern ( Interner ) ;
2379
- Type :: new_with_resolver_inner ( db, krate , & resolver, ty)
2356
+ Type :: new_with_resolver_inner ( db, & resolver, ty)
2380
2357
}
2381
2358
2382
2359
/// FIXME: this only lists trait bounds from the item defining the type
@@ -2398,14 +2375,11 @@ impl TypeParam {
2398
2375
let params = db. generic_defaults ( self . id . parent ( ) ) ;
2399
2376
let local_idx = hir_ty:: param_idx ( db, self . id . into ( ) ) ?;
2400
2377
let resolver = self . id . parent ( ) . resolver ( db. upcast ( ) ) ;
2401
- let krate = self . id . parent ( ) . module ( db. upcast ( ) ) . krate ( ) ;
2402
2378
let ty = params. get ( local_idx) ?. clone ( ) ;
2403
2379
let subst = TyBuilder :: placeholder_subst ( db, self . id . parent ( ) ) ;
2404
2380
let ty = ty. substitute ( Interner , & subst_prefix ( & subst, local_idx) ) ;
2405
2381
match ty. data ( Interner ) {
2406
- GenericArgData :: Ty ( x) => {
2407
- Some ( Type :: new_with_resolver_inner ( db, krate, & resolver, x. clone ( ) ) )
2408
- }
2382
+ GenericArgData :: Ty ( x) => Some ( Type :: new_with_resolver_inner ( db, & resolver, x. clone ( ) ) ) ,
2409
2383
_ => None ,
2410
2384
}
2411
2385
}
@@ -2461,9 +2435,7 @@ impl ConstParam {
2461
2435
}
2462
2436
2463
2437
pub fn ty ( self , db : & dyn HirDatabase ) -> Type {
2464
- let def = self . id . parent ( ) ;
2465
- let krate = def. module ( db. upcast ( ) ) . krate ( ) ;
2466
- Type :: new ( db, krate, def, db. const_param_ty ( self . id ) )
2438
+ Type :: new ( db, self . id . parent ( ) , db. const_param_ty ( self . id ) )
2467
2439
}
2468
2440
}
2469
2441
@@ -2522,8 +2494,8 @@ impl Impl {
2522
2494
inherent. all_impls ( ) . chain ( trait_. all_impls ( ) ) . map ( Self :: from) . collect ( )
2523
2495
}
2524
2496
2525
- pub fn all_for_type ( db : & dyn HirDatabase , Type { krate , ty, .. } : Type ) -> Vec < Impl > {
2526
- let def_crates = match method_resolution:: def_crates ( db, & ty, krate) {
2497
+ pub fn all_for_type ( db : & dyn HirDatabase , Type { ty, env } : Type ) -> Vec < Impl > {
2498
+ let def_crates = match method_resolution:: def_crates ( db, & ty, env . krate ) {
2527
2499
Some ( def_crates) => def_crates,
2528
2500
None => return Vec :: new ( ) ,
2529
2501
} ;
@@ -2589,10 +2561,9 @@ impl Impl {
2589
2561
pub fn self_ty ( self , db : & dyn HirDatabase ) -> Type {
2590
2562
let impl_data = db. impl_data ( self . id ) ;
2591
2563
let resolver = self . id . resolver ( db. upcast ( ) ) ;
2592
- let krate = self . id . lookup ( db. upcast ( ) ) . container . krate ( ) ;
2593
2564
let ctx = hir_ty:: TyLoweringContext :: new ( db, & resolver) ;
2594
2565
let ty = ctx. lower_ty ( & impl_data. self_ty ) ;
2595
- Type :: new_with_resolver_inner ( db, krate , & resolver, ty)
2566
+ Type :: new_with_resolver_inner ( db, & resolver, ty)
2596
2567
}
2597
2568
2598
2569
pub fn items ( self , db : & dyn HirDatabase ) -> Vec < AssocItem > {
@@ -2615,31 +2586,29 @@ impl Impl {
2615
2586
2616
2587
#[ derive( Clone , PartialEq , Eq , Debug ) ]
2617
2588
pub struct Type {
2618
- krate : CrateId , // FIXME this is probably redundant with the TraitEnvironment
2619
2589
env : Arc < TraitEnvironment > ,
2620
2590
ty : Ty ,
2621
2591
}
2622
2592
2623
2593
impl Type {
2624
2594
pub ( crate ) fn new_with_resolver ( db : & dyn HirDatabase , resolver : & Resolver , ty : Ty ) -> Type {
2625
- let krate = resolver. krate ( ) ;
2626
- Type :: new_with_resolver_inner ( db, krate, resolver, ty)
2595
+ Type :: new_with_resolver_inner ( db, resolver, ty)
2627
2596
}
2628
2597
2629
2598
pub ( crate ) fn new_with_resolver_inner (
2630
2599
db : & dyn HirDatabase ,
2631
- krate : CrateId ,
2632
2600
resolver : & Resolver ,
2633
2601
ty : Ty ,
2634
2602
) -> Type {
2635
- let environment = resolver
2636
- . generic_def ( )
2637
- . map_or_else ( || Arc :: new ( TraitEnvironment :: empty ( krate) ) , |d| db. trait_environment ( d) ) ;
2638
- Type { krate, env : environment, ty }
2603
+ let environment = resolver. generic_def ( ) . map_or_else (
2604
+ || Arc :: new ( TraitEnvironment :: empty ( resolver. krate ( ) ) ) ,
2605
+ |d| db. trait_environment ( d) ,
2606
+ ) ;
2607
+ Type { env : environment, ty }
2639
2608
}
2640
2609
2641
2610
pub ( crate ) fn new_for_crate ( krate : CrateId , ty : Ty ) -> Type {
2642
- Type { krate , env : Arc :: new ( TraitEnvironment :: empty ( krate) ) , ty }
2611
+ Type { env : Arc :: new ( TraitEnvironment :: empty ( krate) ) , ty }
2643
2612
}
2644
2613
2645
2614
pub fn reference ( inner : & Type , m : Mutability ) -> Type {
@@ -2653,25 +2622,22 @@ impl Type {
2653
2622
)
2654
2623
}
2655
2624
2656
- fn new ( db : & dyn HirDatabase , krate : CrateId , lexical_env : impl HasResolver , ty : Ty ) -> Type {
2625
+ fn new ( db : & dyn HirDatabase , lexical_env : impl HasResolver , ty : Ty ) -> Type {
2657
2626
let resolver = lexical_env. resolver ( db. upcast ( ) ) ;
2658
- let environment = resolver
2659
- . generic_def ( )
2660
- . map_or_else ( || Arc :: new ( TraitEnvironment :: empty ( krate) ) , |d| db. trait_environment ( d) ) ;
2661
- Type { krate, env : environment, ty }
2627
+ let environment = resolver. generic_def ( ) . map_or_else (
2628
+ || Arc :: new ( TraitEnvironment :: empty ( resolver. krate ( ) ) ) ,
2629
+ |d| db. trait_environment ( d) ,
2630
+ ) ;
2631
+ Type { env : environment, ty }
2662
2632
}
2663
2633
2664
- fn from_def (
2665
- db : & dyn HirDatabase ,
2666
- krate : CrateId ,
2667
- def : impl HasResolver + Into < TyDefId > ,
2668
- ) -> Type {
2634
+ fn from_def ( db : & dyn HirDatabase , def : impl HasResolver + Into < TyDefId > ) -> Type {
2669
2635
let ty = TyBuilder :: def_ty ( db, def. into ( ) ) . fill_with_unknown ( ) . build ( ) ;
2670
- Type :: new ( db, krate , def, ty)
2636
+ Type :: new ( db, def, ty)
2671
2637
}
2672
2638
2673
2639
pub fn new_slice ( ty : Type ) -> Type {
2674
- Type { krate : ty . krate , env : ty. env , ty : TyBuilder :: slice ( ty. ty ) }
2640
+ Type { env : ty. env , ty : TyBuilder :: slice ( ty. ty ) }
2675
2641
}
2676
2642
2677
2643
pub fn is_unit ( & self ) -> bool {
@@ -2727,7 +2693,7 @@ impl Type {
2727
2693
/// This function is used in `.await` syntax completion.
2728
2694
pub fn impls_future ( & self , db : & dyn HirDatabase ) -> bool {
2729
2695
let std_future_trait = db
2730
- . lang_item ( self . krate , SmolStr :: new_inline ( "future_trait" ) )
2696
+ . lang_item ( self . env . krate , SmolStr :: new_inline ( "future_trait" ) )
2731
2697
. and_then ( |it| it. as_trait ( ) ) ;
2732
2698
let std_future_trait = match std_future_trait {
2733
2699
Some ( it) => it,
@@ -2744,7 +2710,7 @@ impl Type {
2744
2710
/// This function can be used to check if a particular type is callable, since FnOnce is a
2745
2711
/// supertrait of Fn and FnMut, so all callable types implements at least FnOnce.
2746
2712
pub fn impls_fnonce ( & self , db : & dyn HirDatabase ) -> bool {
2747
- let fnonce_trait = match FnTrait :: FnOnce . get_id ( db, self . krate ) {
2713
+ let fnonce_trait = match FnTrait :: FnOnce . get_id ( db, self . env . krate ) {
2748
2714
Some ( it) => it,
2749
2715
None => return false ,
2750
2716
} ;
@@ -2780,7 +2746,7 @@ impl Type {
2780
2746
binders : CanonicalVarKinds :: empty ( Interner ) ,
2781
2747
} ;
2782
2748
2783
- db. trait_solve ( self . krate , goal) . is_some ( )
2749
+ db. trait_solve ( self . env . krate , goal) . is_some ( )
2784
2750
}
2785
2751
2786
2752
pub fn normalize_trait_assoc_type (
@@ -2815,7 +2781,7 @@ impl Type {
2815
2781
[ TyVariableKind :: General ] . into_iter ( ) ,
2816
2782
) ;
2817
2783
2818
- match db. trait_solve ( self . krate , goal) ? {
2784
+ match db. trait_solve ( self . env . krate , goal) ? {
2819
2785
Solution :: Unique ( s) => s
2820
2786
. value
2821
2787
. subst
@@ -2827,7 +2793,7 @@ impl Type {
2827
2793
}
2828
2794
2829
2795
pub fn is_copy ( & self , db : & dyn HirDatabase ) -> bool {
2830
- let lang_item = db. lang_item ( self . krate , SmolStr :: new_inline ( "copy" ) ) ;
2796
+ let lang_item = db. lang_item ( self . env . krate , SmolStr :: new_inline ( "copy" ) ) ;
2831
2797
let copy_trait = match lang_item {
2832
2798
Some ( LangItemTarget :: TraitId ( it) ) => it,
2833
2799
_ => return false ,
@@ -3170,7 +3136,7 @@ impl Type {
3170
3136
}
3171
3137
3172
3138
fn derived ( & self , ty : Ty ) -> Type {
3173
- Type { krate : self . krate , env : self . env . clone ( ) , ty }
3139
+ Type { env : self . env . clone ( ) , ty }
3174
3140
}
3175
3141
3176
3142
pub fn walk ( & self , db : & dyn HirDatabase , mut cb : impl FnMut ( Type ) ) {
@@ -3480,7 +3446,7 @@ impl HasCrate for TypeAlias {
3480
3446
3481
3447
impl HasCrate for Type {
3482
3448
fn krate ( & self , _db : & dyn HirDatabase ) -> Crate {
3483
- self . krate . into ( )
3449
+ self . env . krate . into ( )
3484
3450
}
3485
3451
}
3486
3452
0 commit comments