From c1dc0b7bbc239290388d2365c6d0b282e299bdbc Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 8 Apr 2021 10:56:03 -0400 Subject: [PATCH] add comments --- compiler/rustc_resolve/src/late/lifetimes.rs | 24 +++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index a6dceddb43519..91bc8ab5ef41d 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -2343,7 +2343,18 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { Scope::TraitRefBoundary { s, .. } => { // We've exited nested poly trait refs; mark that we are no longer in nested trait refs. - // We don't increase the late depth because this isn't a `Binder` scope + // We don't increase the late depth because this isn't a `Binder` scope. + // + // This came up in #83737, which boiled down to a case like this: + // + // ``` + // F: for<> Fn(&()) -> Box Future + Unpin>, + // // ^^^^^ + + // ``` + // + // Here, as we traverse upwards from the `dyn for<>` binder, we want to reset `in_poly_trait_ref` + // to false, so that we avoid excess contaenation when we encounter the outer `for<>` binder. in_poly_trait_ref = false; scope = s; } @@ -2369,6 +2380,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // We've already seen a binder that is a poly trait ref and this one is too, // that means that they are nested and we are concatenating the bound vars; // don't increase the late depth. + // + // This happens specifically with associated trait bounds like the following: + // + // ``` + // for<'a> T: Iterator Foo<'a, 'b>> + // ``` + // + // In this case, as we traverse `for<'b>`, we would increment `late_depth` but + // set `in_poly_trait_ref` to true. Then when we traverse `for<'a>`, we would + // not increment `late_depth` again. (NB: Niko thinks this logic is actually + // wrong.) (true, true) => {} // We've exited nested poly trait refs; add one to the late depth and mark // that we are no longer in nested trait refs