fix index returned for the use of BoundVar

This commit is contained in:
dfireBird 2024-03-06 23:15:04 +05:30
parent f95b3d4cd2
commit 16493e301e
No known key found for this signature in database
GPG key ID: 26D522CA5FC2B93D
3 changed files with 14 additions and 10 deletions

View file

@ -611,6 +611,10 @@ pub fn static_lifetime() -> Lifetime {
LifetimeData::Static.intern(Interner) LifetimeData::Static.intern(Interner)
} }
pub fn error_lifetime() -> Lifetime {
static_lifetime()
}
pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>( pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
t: T, t: T,
for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty, for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty,

View file

@ -54,7 +54,7 @@ use crate::{
unknown_const_as_generic, unknown_const_as_generic,
}, },
db::HirDatabase, db::HirDatabase,
make_binders, error_lifetime, make_binders,
mapping::{from_chalk_trait_id, lt_to_placeholder_idx, ToChalk}, mapping::{from_chalk_trait_id, lt_to_placeholder_idx, ToChalk},
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx, static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
utils::{ utils::{
@ -1327,7 +1327,7 @@ impl<'a> TyLoweringContext<'a> {
self.resolver.generic_def().expect("generics in scope"), self.resolver.generic_def().expect("generics in scope"),
); );
let idx = match generics.lifetime_idx(id) { let idx = match generics.lifetime_idx(id) {
None => return static_lifetime(), None => return error_lifetime(),
Some(idx) => idx, Some(idx) => idx,
}; };
@ -1336,7 +1336,7 @@ impl<'a> TyLoweringContext<'a> {
} }
.intern(Interner), .intern(Interner),
}, },
None => static_lifetime(), None => error_lifetime(),
} }
} }
} }

View file

@ -318,14 +318,14 @@ impl Generics {
parent + child parent + child
} }
/// Returns numbers of generic parameters excluding those from parent. /// Returns numbers of generic parameters and lifetimes excluding those from parent.
pub(crate) fn len_self(&self) -> usize { pub(crate) fn len_self(&self) -> usize {
self.params.type_or_consts.len() self.params.type_or_consts.len() + self.params.lifetimes.len()
} }
/// Returns number of generic lifetime excluding those from parent. /// Returns number of generic parameter excluding those from parent
pub(crate) fn len_lt_self(&self) -> usize { fn len_params(&self) -> usize {
self.params.lifetimes.len() self.params.type_or_consts.len()
} }
/// (parent total, self param, type param list, const param list, impl trait) /// (parent total, self param, type param list, const param list, impl trait)
@ -376,11 +376,11 @@ impl Generics {
.enumerate() .enumerate()
.find(|(_, (idx, _))| *idx == lifetime.local_id)?; .find(|(_, (idx, _))| *idx == lifetime.local_id)?;
Some((idx, data)) Some((self.len_params() + idx, data))
} else { } else {
self.parent_generics() self.parent_generics()
.and_then(|g| g.find_lifetime(lifetime)) .and_then(|g| g.find_lifetime(lifetime))
.map(|(idx, data)| (self.len_lt_self() + idx, data)) .map(|(idx, data)| (self.len_self() + idx, data))
} }
} }