Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 13301e7

Browse files
committed
replace static_lifetime with new_lifetime_var where necessary
implemented suggested fixes and changes and fix merge conflicts
1 parent a555e95 commit 13301e7

File tree

5 files changed

+19
-23
lines changed

5 files changed

+19
-23
lines changed

crates/hir-def/src/resolver.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -430,17 +430,12 @@ impl Resolver {
430430
return Some(LifetimeNs::Static);
431431
}
432432

433-
for scope in self.scopes() {
434-
match scope {
435-
Scope::GenericParams { def, params } => {
436-
if let Some(id) = params.find_lifetime_by_name(&lifetime.name, *def) {
437-
return Some(LifetimeNs::LifetimeParam(id));
438-
}
439-
}
440-
_ => continue,
433+
self.scopes().find_map(|scope| match scope {
434+
Scope::GenericParams { def, params } => {
435+
params.find_lifetime_by_name(&lifetime.name, *def).map(LifetimeNs::LifetimeParam)
441436
}
442-
}
443-
None
437+
_ => None,
438+
})
444439
}
445440

446441
/// Returns a set of names available in the current scope.

crates/hir-ty/src/builder.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use smallvec::SmallVec;
1515

1616
use crate::{
1717
consteval::unknown_const_as_generic, db::HirDatabase, error_lifetime,
18-
infer::unify::InferenceTable, primitive, static_lifetime, to_assoc_type_id, to_chalk_trait_id,
19-
utils::generics, Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner,
20-
ProjectionTy, Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind,
18+
infer::unify::InferenceTable, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics,
19+
Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy,
20+
Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind,
2121
};
2222

2323
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -134,8 +134,7 @@ impl<D> TyBuilder<D> {
134134
self.fill(|x| match x {
135135
ParamKind::Type => table.new_type_var().cast(Interner),
136136
ParamKind::Const(ty) => table.new_const_var(ty.clone()).cast(Interner),
137-
// FIXME: create new_lifetime_var in table
138-
ParamKind::Lifetime => static_lifetime().cast(Interner),
137+
ParamKind::Lifetime => table.new_lifetime_var().cast(Interner),
139138
})
140139
}
141140

crates/hir-ty/src/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ impl HirDisplay for Ty {
951951
parent_params + self_param + type_params + const_params + lifetime_params;
952952
// We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
953953
if total_len > 0 {
954-
// `parameters` are in the order of fn's params (including impl traits),
954+
// `parameters` are in the order of fn's params (including impl traits), fn's lifetimes
955955
// parent's params (those from enclosing impl or trait, if any).
956956
let parameters = parameters.as_slice(Interner);
957957
let fn_params_len = self_param + type_params + const_params;
@@ -1383,7 +1383,7 @@ fn hir_fmt_generics(
13831383
} else {
13841384
parameters.as_slice(Interner)
13851385
};
1386-
//FIXME: Should handle when creating substitutions
1386+
//FIXME: Should handle the ordering of lifetimes when creating substitutions
13871387
let mut parameters_to_write = parameters_to_write.to_vec();
13881388
parameters_to_write.sort_by(param_compare);
13891389
if !parameters_to_write.is_empty() {

crates/hir-ty/src/infer/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,8 +1873,9 @@ impl InferenceContext<'_> {
18731873
GenericParamId::ConstParamId(id) => {
18741874
substs.push(self.table.new_const_var(self.db.const_param_ty(id)).cast(Interner))
18751875
}
1876-
// FIXME: create `new_lifetime_var` in infer
1877-
GenericParamId::LifetimeParamId(_) => substs.push(static_lifetime().cast(Interner)),
1876+
GenericParamId::LifetimeParamId(_) => {
1877+
substs.push(self.table.new_lifetime_var().cast(Interner))
1878+
}
18781879
}
18791880
}
18801881
assert_eq!(substs.len(), total_len);

crates/hir-ty/src/lower.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use chalk_ir::{
1818
cast::Cast, fold::Shift, fold::TypeFoldable, interner::HasInterner, Mutability, Safety,
1919
};
2020

21+
use either::Either;
2122
use hir_def::{
2223
builtin_type::BuiltinType,
2324
data::adt::StructKind,
@@ -279,6 +280,7 @@ impl<'a> TyLoweringContext<'a> {
279280
}
280281
TypeRef::Reference(inner, lifetime, mutability) => {
281282
let inner_ty = self.lower_ty(inner);
283+
// FIXME: It should infer the eldided lifetimes instead of stubbing with static
282284
let lifetime =
283285
lifetime.as_ref().map_or_else(static_lifetime, |lr| self.lower_lifetime(lr));
284286
TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty)
@@ -863,9 +865,9 @@ impl<'a> TyLoweringContext<'a> {
863865
fill_self_params();
864866
}
865867
let expected_num = if generic_args.has_self_type {
866-
self_params + type_params + const_params + lifetime_params
868+
self_params + type_params + const_params
867869
} else {
868-
type_params + const_params + lifetime_params
870+
type_params + const_params
869871
};
870872
let skip = if generic_args.has_self_type && self_params == 0 { 1 } else { 0 };
871873
// if args are provided, it should be all of them, but we can't rely on that
@@ -899,8 +901,7 @@ impl<'a> TyLoweringContext<'a> {
899901
.args
900902
.iter()
901903
.filter(|arg| matches!(arg, GenericArg::Lifetime(_)))
902-
.skip(skip)
903-
.take(expected_num)
904+
.take(lifetime_params)
904905
{
905906
// Taking into the fact that def_generic_iter will always have lifetimes at the end
906907
// Should have some test cases tho to test this behaviour more properly

0 commit comments

Comments
 (0)