Rollup merge of #132466 - cjgillot:opaque-late, r=compiler-errors
Account for late-bound depth when capturing all opaque lifetimes. Fixes https://github.com/rust-lang/rust/issues/132429 r? ````@compiler-errors````
This commit is contained in:
commit
020b63aebc
2 changed files with 33 additions and 3 deletions
|
@ -571,17 +571,29 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
||||||
// We list scopes outwards, this causes us to see lifetime parameters in reverse
|
// We list scopes outwards, this causes us to see lifetime parameters in reverse
|
||||||
// declaration order. In order to make it consistent with what `generics_of` might
|
// declaration order. In order to make it consistent with what `generics_of` might
|
||||||
// give, we will reverse the IndexMap after early captures.
|
// give, we will reverse the IndexMap after early captures.
|
||||||
|
let mut late_depth = 0;
|
||||||
let mut scope = self.scope;
|
let mut scope = self.scope;
|
||||||
|
let mut crossed_late_boundary = None;
|
||||||
let mut opaque_capture_scopes = vec![(opaque.def_id, &captures)];
|
let mut opaque_capture_scopes = vec![(opaque.def_id, &captures)];
|
||||||
loop {
|
loop {
|
||||||
match *scope {
|
match *scope {
|
||||||
Scope::Binder { ref bound_vars, s, .. } => {
|
Scope::Binder { ref bound_vars, scope_type, s, .. } => {
|
||||||
for (&original_lifetime, &def) in bound_vars.iter().rev() {
|
for (&original_lifetime, &def) in bound_vars.iter().rev() {
|
||||||
|
if let ResolvedArg::LateBound(..) = def
|
||||||
|
&& crossed_late_boundary.is_some()
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if let DefKind::LifetimeParam = self.tcx.def_kind(original_lifetime) {
|
if let DefKind::LifetimeParam = self.tcx.def_kind(original_lifetime) {
|
||||||
|
let def = def.shifted(late_depth);
|
||||||
let ident = lifetime_ident(original_lifetime);
|
let ident = lifetime_ident(original_lifetime);
|
||||||
self.remap_opaque_captures(&opaque_capture_scopes, def, ident);
|
self.remap_opaque_captures(&opaque_capture_scopes, def, ident);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
match scope_type {
|
||||||
|
BinderScopeType::Normal => late_depth += 1,
|
||||||
|
BinderScopeType::Concatenating => {}
|
||||||
|
}
|
||||||
scope = s;
|
scope = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,6 +614,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
||||||
|
|
||||||
Scope::Opaque { captures, def_id, s } => {
|
Scope::Opaque { captures, def_id, s } => {
|
||||||
opaque_capture_scopes.push((def_id, captures));
|
opaque_capture_scopes.push((def_id, captures));
|
||||||
|
late_depth = 0;
|
||||||
scope = s;
|
scope = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,8 +624,12 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
||||||
|
|
||||||
Scope::ObjectLifetimeDefault { s, .. }
|
Scope::ObjectLifetimeDefault { s, .. }
|
||||||
| Scope::Supertrait { s, .. }
|
| Scope::Supertrait { s, .. }
|
||||||
| Scope::TraitRefBoundary { s, .. }
|
| Scope::TraitRefBoundary { s, .. } => {
|
||||||
| Scope::LateBoundary { s, .. } => {
|
scope = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scope::LateBoundary { s, what, .. } => {
|
||||||
|
crossed_late_boundary = Some(what);
|
||||||
scope = s;
|
scope = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
tests/ui/impl-trait/in-trait/late-bound-in-object-assocty.rs
Normal file
13
tests/ui/impl-trait/in-trait/late-bound-in-object-assocty.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
// Test for issue #132429
|
||||||
|
//@compile-flags: -Zunstable-options --edition=2024
|
||||||
|
//@check-pass
|
||||||
|
|
||||||
|
use std::future::Future;
|
||||||
|
|
||||||
|
trait Test {
|
||||||
|
fn foo<'a>(&'a self) -> Box<dyn Future<Output = impl IntoIterator<Item = u32>>> {
|
||||||
|
Box::new(async { [] })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue