Skip to content

Commit 8570a30

Browse files
Rollup merge of #132466 - cjgillot:opaque-late, r=compiler-errors
Account for late-bound depth when capturing all opaque lifetimes. Fixes #132429 r? `@compiler-errors`
2 parents 832aeae + e2a50de commit 8570a30

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+20-3
Original file line numberDiff line numberDiff line change
@@ -571,17 +571,29 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
571571
// We list scopes outwards, this causes us to see lifetime parameters in reverse
572572
// declaration order. In order to make it consistent with what `generics_of` might
573573
// give, we will reverse the IndexMap after early captures.
574+
let mut late_depth = 0;
574575
let mut scope = self.scope;
576+
let mut crossed_late_boundary = None;
575577
let mut opaque_capture_scopes = vec![(opaque.def_id, &captures)];
576578
loop {
577579
match *scope {
578-
Scope::Binder { ref bound_vars, s, .. } => {
580+
Scope::Binder { ref bound_vars, scope_type, s, .. } => {
579581
for (&original_lifetime, &def) in bound_vars.iter().rev() {
582+
if let ResolvedArg::LateBound(..) = def
583+
&& crossed_late_boundary.is_some()
584+
{
585+
continue;
586+
}
580587
if let DefKind::LifetimeParam = self.tcx.def_kind(original_lifetime) {
588+
let def = def.shifted(late_depth);
581589
let ident = lifetime_ident(original_lifetime);
582590
self.remap_opaque_captures(&opaque_capture_scopes, def, ident);
583591
}
584592
}
593+
match scope_type {
594+
BinderScopeType::Normal => late_depth += 1,
595+
BinderScopeType::Concatenating => {}
596+
}
585597
scope = s;
586598
}
587599

@@ -602,6 +614,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
602614

603615
Scope::Opaque { captures, def_id, s } => {
604616
opaque_capture_scopes.push((def_id, captures));
617+
late_depth = 0;
605618
scope = s;
606619
}
607620

@@ -611,8 +624,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
611624

612625
Scope::ObjectLifetimeDefault { s, .. }
613626
| Scope::Supertrait { s, .. }
614-
| Scope::TraitRefBoundary { s, .. }
615-
| Scope::LateBoundary { s, .. } => {
627+
| Scope::TraitRefBoundary { s, .. } => {
628+
scope = s;
629+
}
630+
631+
Scope::LateBoundary { s, what, .. } => {
632+
crossed_late_boundary = Some(what);
616633
scope = s;
617634
}
618635
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test for issue #132429
2+
//@compile-flags: -Zunstable-options --edition=2024
3+
//@check-pass
4+
5+
use std::future::Future;
6+
7+
trait Test {
8+
fn foo<'a>(&'a self) -> Box<dyn Future<Output = impl IntoIterator<Item = u32>>> {
9+
Box::new(async { [] })
10+
}
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)