mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
fix index returned for the use of BoundVar
This commit is contained in:
parent
f95b3d4cd2
commit
16493e301e
3 changed files with 14 additions and 10 deletions
|
@ -611,6 +611,10 @@ pub fn static_lifetime() -> Lifetime {
|
|||
LifetimeData::Static.intern(Interner)
|
||||
}
|
||||
|
||||
pub fn error_lifetime() -> Lifetime {
|
||||
static_lifetime()
|
||||
}
|
||||
|
||||
pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
|
||||
t: T,
|
||||
for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty,
|
||||
|
|
|
@ -54,7 +54,7 @@ use crate::{
|
|||
unknown_const_as_generic,
|
||||
},
|
||||
db::HirDatabase,
|
||||
make_binders,
|
||||
error_lifetime, make_binders,
|
||||
mapping::{from_chalk_trait_id, lt_to_placeholder_idx, ToChalk},
|
||||
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
|
||||
utils::{
|
||||
|
@ -1327,7 +1327,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
self.resolver.generic_def().expect("generics in scope"),
|
||||
);
|
||||
let idx = match generics.lifetime_idx(id) {
|
||||
None => return static_lifetime(),
|
||||
None => return error_lifetime(),
|
||||
Some(idx) => idx,
|
||||
};
|
||||
|
||||
|
@ -1336,7 +1336,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
}
|
||||
.intern(Interner),
|
||||
},
|
||||
None => static_lifetime(),
|
||||
None => error_lifetime(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -318,14 +318,14 @@ impl Generics {
|
|||
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 {
|
||||
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.
|
||||
pub(crate) fn len_lt_self(&self) -> usize {
|
||||
self.params.lifetimes.len()
|
||||
/// Returns number of generic parameter excluding those from parent
|
||||
fn len_params(&self) -> usize {
|
||||
self.params.type_or_consts.len()
|
||||
}
|
||||
|
||||
/// (parent total, self param, type param list, const param list, impl trait)
|
||||
|
@ -376,11 +376,11 @@ impl Generics {
|
|||
.enumerate()
|
||||
.find(|(_, (idx, _))| *idx == lifetime.local_id)?;
|
||||
|
||||
Some((idx, data))
|
||||
Some((self.len_params() + idx, data))
|
||||
} else {
|
||||
self.parent_generics()
|
||||
.and_then(|g| g.find_lifetime(lifetime))
|
||||
.map(|(idx, data)| (self.len_lt_self() + idx, data))
|
||||
.map(|(idx, data)| (self.len_self() + idx, data))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue