@@ -34,8 +34,8 @@ use chalk_ir::{
34
34
} ;
35
35
use either:: Either ;
36
36
use hir_def:: {
37
- AdtId , AssocItemId , DefWithBodyId , FieldId , FunctionId , GenericDefId , GenericParamId , ImplId ,
38
- ItemContainerId , Lookup , TraitId , TupleFieldId , TupleId , TypeAliasId , VariantId ,
37
+ AdtId , AssocItemId , ConstId , DefWithBodyId , FieldId , FunctionId , GenericDefId , GenericParamId ,
38
+ ImplId , ItemContainerId , Lookup , TraitId , TupleFieldId , TupleId , TypeAliasId , VariantId ,
39
39
builtin_type:: { BuiltinInt , BuiltinType , BuiltinUint } ,
40
40
expr_store:: { Body , ExpressionStore , HygieneId , path:: Path } ,
41
41
hir:: { BindingAnnotation , BindingId , ExprId , ExprOrPatId , LabelId , PatId } ,
@@ -67,9 +67,9 @@ use crate::{
67
67
expr:: ExprIsRead ,
68
68
unify:: InferenceTable ,
69
69
} ,
70
- lower:: { GenericArgsPosition , ImplTraitLoweringMode , diagnostics:: TyLoweringDiagnostic } ,
70
+ lower:: { ImplTraitLoweringMode , LifetimeElisionKind , diagnostics:: TyLoweringDiagnostic } ,
71
71
mir:: MirSpan ,
72
- to_assoc_type_id,
72
+ static_lifetime , to_assoc_type_id,
73
73
traits:: FnTrait ,
74
74
utils:: UnevaluatedConstEvaluatorFolder ,
75
75
} ;
@@ -96,7 +96,7 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
96
96
DefWithBodyId :: FunctionId ( f) => {
97
97
ctx. collect_fn ( f) ;
98
98
}
99
- DefWithBodyId :: ConstId ( c) => ctx. collect_const ( & db. const_signature ( c) ) ,
99
+ DefWithBodyId :: ConstId ( c) => ctx. collect_const ( c , & db. const_signature ( c) ) ,
100
100
DefWithBodyId :: StaticId ( s) => ctx. collect_static ( & db. static_signature ( s) ) ,
101
101
DefWithBodyId :: VariantId ( v) => {
102
102
ctx. return_ty = TyBuilder :: builtin (
@@ -899,9 +899,13 @@ impl<'a> InferenceContext<'a> {
899
899
result
900
900
}
901
901
902
- fn collect_const ( & mut self , data : & ConstSignature ) {
903
- let return_ty =
904
- self . make_ty ( data. type_ref , & data. store , InferenceTyDiagnosticSource :: Signature ) ;
902
+ fn collect_const ( & mut self , id : ConstId , data : & ConstSignature ) {
903
+ let return_ty = self . make_ty (
904
+ data. type_ref ,
905
+ & data. store ,
906
+ InferenceTyDiagnosticSource :: Signature ,
907
+ LifetimeElisionKind :: for_const ( id. loc ( self . db ) . container ) ,
908
+ ) ;
905
909
906
910
// Constants might be defining usage sites of TAITs.
907
911
self . make_tait_coercion_table ( iter:: once ( & return_ty) ) ;
@@ -910,8 +914,12 @@ impl<'a> InferenceContext<'a> {
910
914
}
911
915
912
916
fn collect_static ( & mut self , data : & StaticSignature ) {
913
- let return_ty =
914
- self . make_ty ( data. type_ref , & data. store , InferenceTyDiagnosticSource :: Signature ) ;
917
+ let return_ty = self . make_ty (
918
+ data. type_ref ,
919
+ & data. store ,
920
+ InferenceTyDiagnosticSource :: Signature ,
921
+ LifetimeElisionKind :: Elided ( static_lifetime ( ) ) ,
922
+ ) ;
915
923
916
924
// Statics might be defining usage sites of TAITs.
917
925
self . make_tait_coercion_table ( iter:: once ( & return_ty) ) ;
@@ -921,12 +929,15 @@ impl<'a> InferenceContext<'a> {
921
929
922
930
fn collect_fn ( & mut self , func : FunctionId ) {
923
931
let data = self . db . function_signature ( func) ;
924
- let mut param_tys =
925
- self . with_ty_lowering ( & data. store , InferenceTyDiagnosticSource :: Signature , |ctx| {
932
+ let mut param_tys = self . with_ty_lowering (
933
+ & data. store ,
934
+ InferenceTyDiagnosticSource :: Signature ,
935
+ LifetimeElisionKind :: for_fn_params ( & data) ,
936
+ |ctx| {
926
937
ctx. type_param_mode ( ParamLoweringMode :: Placeholder ) ;
927
- ctx. in_fn_signature = true ;
928
938
data. params . iter ( ) . map ( |& type_ref| ctx. lower_ty ( type_ref) ) . collect :: < Vec < _ > > ( )
929
- } ) ;
939
+ } ,
940
+ ) ;
930
941
931
942
// Check if function contains a va_list, if it does then we append it to the parameter types
932
943
// that are collected from the function data
@@ -967,10 +978,10 @@ impl<'a> InferenceContext<'a> {
967
978
let return_ty = self . with_ty_lowering (
968
979
& data. store ,
969
980
InferenceTyDiagnosticSource :: Signature ,
981
+ LifetimeElisionKind :: for_fn_ret ( ) ,
970
982
|ctx| {
971
983
ctx. type_param_mode ( ParamLoweringMode :: Placeholder )
972
984
. impl_trait_mode ( ImplTraitLoweringMode :: Opaque ) ;
973
- ctx. in_fn_signature = true ;
974
985
ctx. lower_ty ( return_ty)
975
986
} ,
976
987
) ;
@@ -1304,6 +1315,7 @@ impl<'a> InferenceContext<'a> {
1304
1315
& mut self ,
1305
1316
store : & ExpressionStore ,
1306
1317
types_source : InferenceTyDiagnosticSource ,
1318
+ lifetime_elision : LifetimeElisionKind ,
1307
1319
f : impl FnOnce ( & mut TyLoweringContext < ' _ > ) -> R ,
1308
1320
) -> R {
1309
1321
let mut ctx = TyLoweringContext :: new (
@@ -1313,42 +1325,65 @@ impl<'a> InferenceContext<'a> {
1313
1325
& self . diagnostics ,
1314
1326
types_source,
1315
1327
self . generic_def ,
1328
+ lifetime_elision,
1316
1329
) ;
1317
1330
f ( & mut ctx)
1318
1331
}
1319
1332
1320
1333
fn with_body_ty_lowering < R > ( & mut self , f : impl FnOnce ( & mut TyLoweringContext < ' _ > ) -> R ) -> R {
1321
- self . with_ty_lowering ( self . body , InferenceTyDiagnosticSource :: Body , f)
1334
+ self . with_ty_lowering (
1335
+ self . body ,
1336
+ InferenceTyDiagnosticSource :: Body ,
1337
+ LifetimeElisionKind :: Infer ,
1338
+ f,
1339
+ )
1322
1340
}
1323
1341
1324
1342
fn make_ty (
1325
1343
& mut self ,
1326
1344
type_ref : TypeRefId ,
1327
1345
store : & ExpressionStore ,
1328
1346
type_source : InferenceTyDiagnosticSource ,
1347
+ lifetime_elision : LifetimeElisionKind ,
1329
1348
) -> Ty {
1330
- let ty = self . with_ty_lowering ( store, type_source, |ctx| ctx. lower_ty ( type_ref) ) ;
1349
+ let ty = self
1350
+ . with_ty_lowering ( store, type_source, lifetime_elision, |ctx| ctx. lower_ty ( type_ref) ) ;
1331
1351
let ty = self . insert_type_vars ( ty) ;
1332
1352
self . normalize_associated_types_in ( ty)
1333
1353
}
1334
1354
1335
1355
fn make_body_ty ( & mut self , type_ref : TypeRefId ) -> Ty {
1336
- self . make_ty ( type_ref, self . body , InferenceTyDiagnosticSource :: Body )
1356
+ self . make_ty (
1357
+ type_ref,
1358
+ self . body ,
1359
+ InferenceTyDiagnosticSource :: Body ,
1360
+ LifetimeElisionKind :: Infer ,
1361
+ )
1337
1362
}
1338
1363
1339
1364
fn make_body_const ( & mut self , const_ref : ConstRef , ty : Ty ) -> Const {
1340
- let const_ = self . with_ty_lowering ( self . body , InferenceTyDiagnosticSource :: Body , |ctx| {
1341
- ctx. type_param_mode = ParamLoweringMode :: Placeholder ;
1342
- ctx. lower_const ( & const_ref, ty)
1343
- } ) ;
1365
+ let const_ = self . with_ty_lowering (
1366
+ self . body ,
1367
+ InferenceTyDiagnosticSource :: Body ,
1368
+ LifetimeElisionKind :: Infer ,
1369
+ |ctx| {
1370
+ ctx. type_param_mode = ParamLoweringMode :: Placeholder ;
1371
+ ctx. lower_const ( & const_ref, ty)
1372
+ } ,
1373
+ ) ;
1344
1374
self . insert_type_vars ( const_)
1345
1375
}
1346
1376
1347
1377
fn make_path_as_body_const ( & mut self , path : & Path , ty : Ty ) -> Const {
1348
- let const_ = self . with_ty_lowering ( self . body , InferenceTyDiagnosticSource :: Body , |ctx| {
1349
- ctx. type_param_mode = ParamLoweringMode :: Placeholder ;
1350
- ctx. lower_path_as_const ( path, ty)
1351
- } ) ;
1378
+ let const_ = self . with_ty_lowering (
1379
+ self . body ,
1380
+ InferenceTyDiagnosticSource :: Body ,
1381
+ LifetimeElisionKind :: Infer ,
1382
+ |ctx| {
1383
+ ctx. type_param_mode = ParamLoweringMode :: Placeholder ;
1384
+ ctx. lower_path_as_const ( path, ty)
1385
+ } ,
1386
+ ) ;
1352
1387
self . insert_type_vars ( const_)
1353
1388
}
1354
1389
@@ -1357,9 +1392,12 @@ impl<'a> InferenceContext<'a> {
1357
1392
}
1358
1393
1359
1394
fn make_body_lifetime ( & mut self , lifetime_ref : & LifetimeRef ) -> Lifetime {
1360
- let lt = self . with_ty_lowering ( self . body , InferenceTyDiagnosticSource :: Body , |ctx| {
1361
- ctx. lower_lifetime ( lifetime_ref)
1362
- } ) ;
1395
+ let lt = self . with_ty_lowering (
1396
+ self . body ,
1397
+ InferenceTyDiagnosticSource :: Body ,
1398
+ LifetimeElisionKind :: Infer ,
1399
+ |ctx| ctx. lower_lifetime ( lifetime_ref) ,
1400
+ ) ;
1363
1401
self . insert_type_vars ( lt)
1364
1402
}
1365
1403
@@ -1529,23 +1567,24 @@ impl<'a> InferenceContext<'a> {
1529
1567
& self . diagnostics ,
1530
1568
InferenceTyDiagnosticSource :: Body ,
1531
1569
self . generic_def ,
1570
+ LifetimeElisionKind :: Infer ,
1532
1571
) ;
1533
- let mut path_ctx = ctx. at_path ( path, node, GenericArgsPosition :: Value ) ;
1572
+ let mut path_ctx = ctx. at_path ( path, node) ;
1534
1573
let ( resolution, unresolved) = if value_ns {
1535
1574
let Some ( res) = path_ctx. resolve_path_in_value_ns ( HygieneId :: ROOT ) else {
1536
1575
return ( self . err_ty ( ) , None ) ;
1537
1576
} ;
1538
1577
match res {
1539
1578
ResolveValueResult :: ValueNs ( value, _) => match value {
1540
1579
ValueNs :: EnumVariantId ( var) => {
1541
- let substs = path_ctx. substs_from_path ( var. into ( ) , true ) ;
1580
+ let substs = path_ctx. substs_from_path ( var. into ( ) , true , false ) ;
1542
1581
drop ( ctx) ;
1543
1582
let ty = self . db . ty ( var. lookup ( self . db ) . parent . into ( ) ) ;
1544
1583
let ty = self . insert_type_vars ( ty. substitute ( Interner , & substs) ) ;
1545
1584
return ( ty, Some ( var. into ( ) ) ) ;
1546
1585
}
1547
1586
ValueNs :: StructId ( strukt) => {
1548
- let substs = path_ctx. substs_from_path ( strukt. into ( ) , true ) ;
1587
+ let substs = path_ctx. substs_from_path ( strukt. into ( ) , true , false ) ;
1549
1588
drop ( ctx) ;
1550
1589
let ty = self . db . ty ( strukt. into ( ) ) ;
1551
1590
let ty = self . insert_type_vars ( ty. substitute ( Interner , & substs) ) ;
@@ -1567,21 +1606,21 @@ impl<'a> InferenceContext<'a> {
1567
1606
} ;
1568
1607
return match resolution {
1569
1608
TypeNs :: AdtId ( AdtId :: StructId ( strukt) ) => {
1570
- let substs = path_ctx. substs_from_path ( strukt. into ( ) , true ) ;
1609
+ let substs = path_ctx. substs_from_path ( strukt. into ( ) , true , false ) ;
1571
1610
drop ( ctx) ;
1572
1611
let ty = self . db . ty ( strukt. into ( ) ) ;
1573
1612
let ty = self . insert_type_vars ( ty. substitute ( Interner , & substs) ) ;
1574
1613
forbid_unresolved_segments ( ( ty, Some ( strukt. into ( ) ) ) , unresolved)
1575
1614
}
1576
1615
TypeNs :: AdtId ( AdtId :: UnionId ( u) ) => {
1577
- let substs = path_ctx. substs_from_path ( u. into ( ) , true ) ;
1616
+ let substs = path_ctx. substs_from_path ( u. into ( ) , true , false ) ;
1578
1617
drop ( ctx) ;
1579
1618
let ty = self . db . ty ( u. into ( ) ) ;
1580
1619
let ty = self . insert_type_vars ( ty. substitute ( Interner , & substs) ) ;
1581
1620
forbid_unresolved_segments ( ( ty, Some ( u. into ( ) ) ) , unresolved)
1582
1621
}
1583
1622
TypeNs :: EnumVariantId ( var) => {
1584
- let substs = path_ctx. substs_from_path ( var. into ( ) , true ) ;
1623
+ let substs = path_ctx. substs_from_path ( var. into ( ) , true , false ) ;
1585
1624
drop ( ctx) ;
1586
1625
let ty = self . db . ty ( var. lookup ( self . db ) . parent . into ( ) ) ;
1587
1626
let ty = self . insert_type_vars ( ty. substitute ( Interner , & substs) ) ;
@@ -1665,7 +1704,7 @@ impl<'a> InferenceContext<'a> {
1665
1704
never ! ( "resolver should always resolve lang item paths" ) ;
1666
1705
return ( self . err_ty ( ) , None ) ;
1667
1706
} ;
1668
- let substs = path_ctx. substs_from_path_segment ( it. into ( ) , true , None ) ;
1707
+ let substs = path_ctx. substs_from_path_segment ( it. into ( ) , true , None , false ) ;
1669
1708
drop ( ctx) ;
1670
1709
let ty = self . db . ty ( it. into ( ) ) ;
1671
1710
let ty = self . insert_type_vars ( ty. substitute ( Interner , & substs) ) ;
0 commit comments