replace static_lifetime with new_lifetime_var where necessary

implemented suggested fixes and changes and fix merge conflicts
This commit is contained in:
dfireBird 2024-03-18 15:48:59 +05:30
parent a555e95c9a
commit 13301e7a1a
No known key found for this signature in database
GPG key ID: 26D522CA5FC2B93D
5 changed files with 19 additions and 23 deletions

View file

@ -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.

View file

@ -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),
})
}

View file

@ -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() {

View file

@ -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);

View file

@ -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