Unnamed repository; edit this file 'description' to name the repository.
fix index returned for the use of BoundVar
dfireBird 2024-03-18
parent f95b3d4 · commit 16493e3
-rw-r--r--crates/hir-ty/src/lib.rs4
-rw-r--r--crates/hir-ty/src/lower.rs6
-rw-r--r--crates/hir-ty/src/utils.rs14
3 files changed, 14 insertions, 10 deletions
diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs
index d6d5c16ae7..accf306dde 100644
--- a/crates/hir-ty/src/lib.rs
+++ b/crates/hir-ty/src/lib.rs
@@ -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,
diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs
index af1a91a06a..3327d28479 100644
--- a/crates/hir-ty/src/lower.rs
+++ b/crates/hir-ty/src/lower.rs
@@ -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(),
}
}
}
diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs
index 84fcc31dd4..f45fe863df 100644
--- a/crates/hir-ty/src/utils.rs
+++ b/crates/hir-ty/src/utils.rs
@@ -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))
}
}