Skip to content

Commit 16493e3

Browse files
committed
fix index returned for the use of BoundVar
1 parent f95b3d4 commit 16493e3

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

crates/hir-ty/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,10 @@ pub fn static_lifetime() -> Lifetime {
611611
LifetimeData::Static.intern(Interner)
612612
}
613613

614+
pub fn error_lifetime() -> Lifetime {
615+
static_lifetime()
616+
}
617+
614618
pub(crate) fn fold_free_vars<T: HasInterner<Interner = Interner> + TypeFoldable<Interner>>(
615619
t: T,
616620
for_ty: impl FnMut(BoundVar, DebruijnIndex) -> Ty,

crates/hir-ty/src/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use crate::{
5454
unknown_const_as_generic,
5555
},
5656
db::HirDatabase,
57-
make_binders,
57+
error_lifetime, make_binders,
5858
mapping::{from_chalk_trait_id, lt_to_placeholder_idx, ToChalk},
5959
static_lifetime, to_assoc_type_id, to_chalk_trait_id, to_placeholder_idx,
6060
utils::{
@@ -1327,7 +1327,7 @@ impl<'a> TyLoweringContext<'a> {
13271327
self.resolver.generic_def().expect("generics in scope"),
13281328
);
13291329
let idx = match generics.lifetime_idx(id) {
1330-
None => return static_lifetime(),
1330+
None => return error_lifetime(),
13311331
Some(idx) => idx,
13321332
};
13331333

@@ -1336,7 +1336,7 @@ impl<'a> TyLoweringContext<'a> {
13361336
}
13371337
.intern(Interner),
13381338
},
1339-
None => static_lifetime(),
1339+
None => error_lifetime(),
13401340
}
13411341
}
13421342
}

crates/hir-ty/src/utils.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ impl Generics {
318318
parent + child
319319
}
320320

321-
/// Returns numbers of generic parameters excluding those from parent.
321+
/// Returns numbers of generic parameters and lifetimes excluding those from parent.
322322
pub(crate) fn len_self(&self) -> usize {
323-
self.params.type_or_consts.len()
323+
self.params.type_or_consts.len() + self.params.lifetimes.len()
324324
}
325325

326-
/// Returns number of generic lifetime excluding those from parent.
327-
pub(crate) fn len_lt_self(&self) -> usize {
328-
self.params.lifetimes.len()
326+
/// Returns number of generic parameter excluding those from parent
327+
fn len_params(&self) -> usize {
328+
self.params.type_or_consts.len()
329329
}
330330

331331
/// (parent total, self param, type param list, const param list, impl trait)
@@ -376,11 +376,11 @@ impl Generics {
376376
.enumerate()
377377
.find(|(_, (idx, _))| *idx == lifetime.local_id)?;
378378

379-
Some((idx, data))
379+
Some((self.len_params() + idx, data))
380380
} else {
381381
self.parent_generics()
382382
.and_then(|g| g.find_lifetime(lifetime))
383-
.map(|(idx, data)| (self.len_lt_self() + idx, data))
383+
.map(|(idx, data)| (self.len_self() + idx, data))
384384
}
385385
}
386386

0 commit comments

Comments
 (0)