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); return Some(LifetimeNs::Static);
} }
for scope in self.scopes() { self.scopes().find_map(|scope| match scope {
match scope { Scope::GenericParams { def, params } => {
Scope::GenericParams { def, params } => { params.find_lifetime_by_name(&lifetime.name, *def).map(LifetimeNs::LifetimeParam)
if let Some(id) = params.find_lifetime_by_name(&lifetime.name, *def) {
return Some(LifetimeNs::LifetimeParam(id));
}
}
_ => continue,
} }
} _ => None,
None })
} }
/// Returns a set of names available in the current scope. /// Returns a set of names available in the current scope.

View File

@ -15,9 +15,9 @@ use smallvec::SmallVec;
use crate::{ use crate::{
consteval::unknown_const_as_generic, db::HirDatabase, error_lifetime, consteval::unknown_const_as_generic, db::HirDatabase, error_lifetime,
infer::unify::InferenceTable, primitive, static_lifetime, to_assoc_type_id, to_chalk_trait_id, infer::unify::InferenceTable, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics,
utils::generics, Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner, Binders, BoundVar, CallableSig, GenericArg, GenericArgData, Interner, ProjectionTy,
ProjectionTy, Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind, Substitution, TraitRef, Ty, TyDefId, TyExt, TyKind,
}; };
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
@ -134,8 +134,7 @@ impl<D> TyBuilder<D> {
self.fill(|x| match x { self.fill(|x| match x {
ParamKind::Type => table.new_type_var().cast(Interner), ParamKind::Type => table.new_type_var().cast(Interner),
ParamKind::Const(ty) => table.new_const_var(ty.clone()).cast(Interner), ParamKind::Const(ty) => table.new_const_var(ty.clone()).cast(Interner),
// FIXME: create new_lifetime_var in table ParamKind::Lifetime => table.new_lifetime_var().cast(Interner),
ParamKind::Lifetime => static_lifetime().cast(Interner),
}) })
} }

View File

@ -951,7 +951,7 @@ impl HirDisplay for Ty {
parent_params + self_param + type_params + const_params + lifetime_params; 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? // We print all params except implicit impl Trait params. Still a bit weird; should we leave out parent and self?
if total_len > 0 { 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). // parent's params (those from enclosing impl or trait, if any).
let parameters = parameters.as_slice(Interner); let parameters = parameters.as_slice(Interner);
let fn_params_len = self_param + type_params + const_params; let fn_params_len = self_param + type_params + const_params;
@ -1383,7 +1383,7 @@ fn hir_fmt_generics(
} else { } else {
parameters.as_slice(Interner) 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(); let mut parameters_to_write = parameters_to_write.to_vec();
parameters_to_write.sort_by(param_compare); parameters_to_write.sort_by(param_compare);
if !parameters_to_write.is_empty() { if !parameters_to_write.is_empty() {

View File

@ -1873,8 +1873,9 @@ impl InferenceContext<'_> {
GenericParamId::ConstParamId(id) => { GenericParamId::ConstParamId(id) => {
substs.push(self.table.new_const_var(self.db.const_param_ty(id)).cast(Interner)) substs.push(self.table.new_const_var(self.db.const_param_ty(id)).cast(Interner))
} }
// FIXME: create `new_lifetime_var` in infer GenericParamId::LifetimeParamId(_) => {
GenericParamId::LifetimeParamId(_) => substs.push(static_lifetime().cast(Interner)), substs.push(self.table.new_lifetime_var().cast(Interner))
}
} }
} }
assert_eq!(substs.len(), total_len); 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, cast::Cast, fold::Shift, fold::TypeFoldable, interner::HasInterner, Mutability, Safety,
}; };
use either::Either;
use hir_def::{ use hir_def::{
builtin_type::BuiltinType, builtin_type::BuiltinType,
data::adt::StructKind, data::adt::StructKind,
@ -279,6 +280,7 @@ impl<'a> TyLoweringContext<'a> {
} }
TypeRef::Reference(inner, lifetime, mutability) => { TypeRef::Reference(inner, lifetime, mutability) => {
let inner_ty = self.lower_ty(inner); let inner_ty = self.lower_ty(inner);
// FIXME: It should infer the eldided lifetimes instead of stubbing with static
let lifetime = let lifetime =
lifetime.as_ref().map_or_else(static_lifetime, |lr| self.lower_lifetime(lr)); lifetime.as_ref().map_or_else(static_lifetime, |lr| self.lower_lifetime(lr));
TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty) TyKind::Ref(lower_to_chalk_mutability(*mutability), lifetime, inner_ty)
@ -863,9 +865,9 @@ impl<'a> TyLoweringContext<'a> {
fill_self_params(); fill_self_params();
} }
let expected_num = if generic_args.has_self_type { let expected_num = if generic_args.has_self_type {
self_params + type_params + const_params + lifetime_params self_params + type_params + const_params
} else { } 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 }; 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 // 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 .args
.iter() .iter()
.filter(|arg| matches!(arg, GenericArg::Lifetime(_))) .filter(|arg| matches!(arg, GenericArg::Lifetime(_)))
.skip(skip) .take(lifetime_params)
.take(expected_num)
{ {
// Taking into the fact that def_generic_iter will always have lifetimes at the end // 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 // Should have some test cases tho to test this behaviour more properly