Unnamed repository; edit this file 'description' to name the repository.
replace static_lifetime with new_lifetime_var where necessary
implemented suggested fixes and changes and fix merge conflicts
dfireBird 2024-03-18
parent a555e95 · commit 13301e7
-rw-r--r--crates/hir-def/src/resolver.rs15
-rw-r--r--crates/hir-ty/src/builder.rs9
-rw-r--r--crates/hir-ty/src/display.rs4
-rw-r--r--crates/hir-ty/src/infer/expr.rs5
-rw-r--r--crates/hir-ty/src/lower.rs9
5 files changed, 19 insertions, 23 deletions
diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs
index bfad75c50b..fadab858aa 100644
--- a/crates/hir-def/src/resolver.rs
+++ b/crates/hir-def/src/resolver.rs
@@ -430,17 +430,12 @@ impl Resolver {
return Some(LifetimeNs::Static);
}
- for scope in self.scopes() {
- match scope {
- Scope::GenericParams { def, params } => {
- if let Some(id) = params.find_lifetime_by_name(&lifetime.name, *def) {
- return Some(LifetimeNs::LifetimeParam(id));
- }
- }
- _ => continue,
+ self.scopes().find_map(|scope| match scope {
+ Scope::GenericParams { def, params } => {
+ params.find_lifetime_by_name(&lifetime.name, *def).map(LifetimeNs::LifetimeParam)
}
- }
- None
+ _ => None,
+ })
}
/// Returns a set of names available in the current scope.
diff --git a/crates/hir-ty/src/builder.rs b/crates/hir-ty/src/builder.rs
index 536542f9a0..cb118a3684 100644
--- a/crates/hir-ty/src/builder.rs
+++ b/crates/hir-ty/src/builder.rs
@@ -15,9 +15,9 @@ use smallvec::SmallVec;
use crate::{
consteval::unknown_const_as_generic, db::HirDatabase, error_lifetime,
- infer::unify::InferenceTable, primitive, static_lifetime, to_assoc_type_id, to_chalk_trait_id,
- utils::generics, Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner,
- ProjectionTy, Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind,
+ infer::unify::InferenceTable, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics,
+ Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy,
+ Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind,
};
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -134,8 +134,7 @@ impl<D> TyBuilder<D> {
self.fill(|x| match x {
ParamKind::Type => table.new_type_var().cast(Interner),
ParamKind::Const(ty) => table.new_const_var(ty.clone()).cast(Interner),
- // FIXME: create new_lifetime_var in table
- ParamKind::Lifetime => static_lifetime().cast(Interner),
+ ParamKind::Lifetime => table.new_lifetime_var().cast(Interner),
})
}
diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs
index f472a5d7f2..abac344703 100644
--- a/crates/hir-ty/src/display.rs
+++ b/crates/hir-ty/src/display.rs
@@ -951,7 +951,7 @@ impl HirDisplay for Ty {
parent_params + self_param + type_params + const_params + lifetime_params;
// We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
if total_len > 0 {
- // `parameters` are in the order of fn's params (including impl traits),
+ // `parameters` are in the order of fn's params (including impl traits), fn's lifetimes
// parent's params (those from enclosing impl or trait, if any).
let parameters = parameters.as_slice(Interner);
let fn_params_len = self_param + type_params + const_params;
@@ -1383,7 +1383,7 @@ fn hir_fmt_generics(
} else {
parameters.as_slice(Interner)
};
- //FIXME: Should handle when creating substitutions
+ //FIXME: Should handle the ordering of lifetimes when creating substitutions
let mut parameters_to_write = parameters_to_write.to_vec();
parameters_to_write.sort_by(param_compare);
if !parameters_to_write.is_empty() {
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index 82f7e87ac9..aab052fdf1 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -1873,8 +1873,9 @@ impl InferenceContext<'_> {
GenericParamId::ConstParamId(id) => {
substs.push(self.table.new_const_var(self.db.const_param_ty(id)).cast(Interner))
}
- // FIXME: create `new_lifetime_var` in infer
- GenericParamId::LifetimeParamId(_) => substs.push(static_lifetime().cast(Interner)),
+ GenericParamId::LifetimeParamId(_) => {
+ substs.push(self.table.new_lifetime_var().cast(Interner))
+ }
}
}
assert_eq!(substs.len(), total_len);
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index 63772fb7c1..b4ff98a63c 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -18,6 +18,7 @@ use chalk_ir::{
cast::Cast, fold::Shift, fold::TypeFoldable, interner::HasInterner, Mutability, Safety,
};
+use either::Either;
use hir_def::{
builtin_type::BuiltinType,
data::adt::StructKind,
@@ -279,6 +280,7 @@ impl<'a> TyLoweringContext<'a> {
}
TypeRef::Reference(inner, lifetime, mutability) => {
let inner_ty = self.lower_ty(inner);
+ // FIXME: It should infer the eldided lifetimes instead of stubbing with static
let lifetime =
lifetime.as_ref().map_or_else(static_lifetime, |lr| self.lower_lifetime(lr));
TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty)
@@ -863,9 +865,9 @@ impl<'a> TyLoweringContext<'a> {
fill_self_params();
}
let expected_num = if generic_args.has_self_type {
- self_params + type_params + const_params + lifetime_params
+ self_params + type_params + const_params
} else {
- type_params + const_params + lifetime_params
+ type_params + const_params
};
let skip = if generic_args.has_self_type && self_params == 0 { 1 } else { 0 };
// 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> {
.args
.iter()
.filter(|arg| matches!(arg, GenericArg::Lifetime(_)))
- .skip(skip)
- .take(expected_num)
+ .take(lifetime_params)
{
// Taking into the fact that def_generic_iter will always have lifetimes at the end
// Should have some test cases tho to test this behaviour more properly