Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 0669ae7

Browse files
committed
handle lifetimes separately in substs function
1 parent a6c8cbf commit 0669ae7

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

crates/hir-ty/src/lower.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ impl<'a> TyLoweringContext<'a> {
382382
list_params,
383383
const_params,
384384
_impl_trait_params,
385-
lifetime_params,
385+
_lifetime_params,
386386
) = if let Some(def) = self.resolver.generic_def() {
387387
let generics = generics(self.db.upcast(), def);
388388
generics.provenance_split()
@@ -391,11 +391,7 @@ impl<'a> TyLoweringContext<'a> {
391391
};
392392
TyKind::BoundVar(BoundVar::new(
393393
self.in_binders,
394-
idx as usize
395-
+ self_params
396-
+ list_params
397-
+ const_params
398-
+ lifetime_params,
394+
idx as usize + self_params + list_params + const_params,
399395
))
400396
.intern(Interner)
401397
}
@@ -869,11 +865,17 @@ impl<'a> TyLoweringContext<'a> {
869865
let expected_num = if generic_args.has_self_type {
870866
self_params + type_params + const_params + lifetime_params
871867
} else {
872-
type_params + const_params
868+
type_params + const_params + lifetime_params
873869
};
874870
let skip = if generic_args.has_self_type && self_params == 0 { 1 } else { 0 };
875871
// if args are provided, it should be all of them, but we can't rely on that
876-
for arg in generic_args.args.iter().skip(skip).take(expected_num) {
872+
for arg in generic_args
873+
.args
874+
.iter()
875+
.filter(|arg| !matches!(arg, GenericArg::Lifetime(_)))
876+
.skip(skip)
877+
.take(expected_num)
878+
{
877879
if let Some(id) = def_generic_iter.next() {
878880
if let Some(x) = generic_arg_to_chalk(
879881
self.db,
@@ -892,6 +894,34 @@ impl<'a> TyLoweringContext<'a> {
892894
}
893895
}
894896
}
897+
898+
for arg in generic_args
899+
.args
900+
.iter()
901+
.filter(|arg| matches!(arg, GenericArg::Lifetime(_)))
902+
.skip(skip)
903+
.take(expected_num)
904+
{
905+
// Taking into the fact that def_generic_iter will always have lifetimes at the end
906+
// Should have some test cases tho to test this behaviour more properly
907+
if let Some(id) = def_generic_iter.next() {
908+
if let Some(x) = generic_arg_to_chalk(
909+
self.db,
910+
id,
911+
arg,
912+
&mut (),
913+
|_, type_ref| self.lower_ty(type_ref),
914+
|_, const_ref, ty| self.lower_const(const_ref, ty),
915+
|_, lifetime_ref| self.lower_lifetime(lifetime_ref),
916+
) {
917+
had_explicit_args = true;
918+
substs.push(dbg!(x));
919+
} else {
920+
// Never return a None explictly
921+
never!("Unexpectd None by generic_arg_to_chalk");
922+
}
923+
}
924+
}
895925
} else {
896926
fill_self_params();
897927
}

0 commit comments

Comments
 (0)