Skip to content

Commit c4618fe

Browse files
committed
Auto merge of #17190 - dfireBird:dyn_trait_with_lifetimes_in_rpit, r=Veykril
Fix: Lifetime's Bound Var Debrujin Index in Dyn Traits Surely fixes #17182 I have tried running the analysis-stats in some of the repos mentioned in #17080. No panic in almost all of them.
2 parents 1a5bb27 + 8cbeb04 commit c4618fe

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

crates/hir-ty/src/lower.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1311,11 +1311,10 @@ impl<'a> TyLoweringContext<'a> {
13111311
bounds,
13121312
lifetime: match lifetime {
13131313
Some(it) => match it.bound_var(Interner) {
1314-
Some(bound_var) => LifetimeData::BoundVar(BoundVar::new(
1315-
DebruijnIndex::INNERMOST,
1316-
bound_var.index,
1317-
))
1318-
.intern(Interner),
1314+
Some(bound_var) => bound_var
1315+
.shifted_out_to(DebruijnIndex::new(2))
1316+
.map(|bound_var| LifetimeData::BoundVar(bound_var).intern(Interner))
1317+
.unwrap_or(it),
13191318
None => it,
13201319
},
13211320
None => static_lifetime(),

crates/hir-ty/src/tests/traits.rs

+21
Original file line numberDiff line numberDiff line change
@@ -4803,3 +4803,24 @@ fn foo() {
48034803
"#,
48044804
);
48054805
}
4806+
4807+
#[test]
4808+
fn dyn_trait_with_lifetime_in_rpit() {
4809+
check_types(
4810+
r#"
4811+
//- minicore: future
4812+
pub struct Box<T> {}
4813+
4814+
trait Trait {}
4815+
4816+
pub async fn foo_async<'a>() -> Box<dyn Trait + 'a> {
4817+
Box {}
4818+
}
4819+
4820+
fn foo() {
4821+
foo_async();
4822+
//^^^^^^^^^^^impl Future<Output = Box<dyn Trait>> + ?Sized
4823+
}
4824+
"#,
4825+
)
4826+
}

0 commit comments

Comments
 (0)