Skip to content

Commit 29272fc

Browse files
committed
Correctly handle binders inside trait predicates
1 parent 033013c commit 29272fc

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/librustc_resolve/late/lifetimes.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
883883
})
884884
.collect();
885885
if !lifetimes.is_empty() {
886-
self.trait_ref_hack = true;
887886
let next_early_index = self.next_early_index();
888887
let scope = Scope::Binder {
889888
lifetimes,
@@ -895,9 +894,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
895894
let result = self.with(scope, |old_scope, this| {
896895
this.check_lifetime_params(old_scope, &bound_generic_params);
897896
this.visit_ty(&bounded_ty);
897+
this.trait_ref_hack = true;
898898
walk_list!(this, visit_param_bound, bounds);
899+
this.trait_ref_hack = false;
899900
});
900-
self.trait_ref_hack = false;
901901
result
902902
} else {
903903
self.visit_ty(&bounded_ty);
@@ -932,13 +932,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
932932
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
933933

934934
let should_pop_missing_lt = self.is_trait_ref_fn_scope(trait_ref);
935-
if !self.trait_ref_hack
935+
936+
let trait_ref_hack = take(&mut self.trait_ref_hack);
937+
if !trait_ref_hack
936938
|| trait_ref.bound_generic_params.iter().any(|param| match param.kind {
937939
GenericParamKind::Lifetime { .. } => true,
938940
_ => false,
939941
})
940942
{
941-
if self.trait_ref_hack {
943+
if trait_ref_hack {
942944
struct_span_err!(
943945
self.tcx.sess,
944946
trait_ref.span,
@@ -968,10 +970,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
968970
this.check_lifetime_params(old_scope, &trait_ref.bound_generic_params);
969971
walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
970972
this.visit_trait_ref(&trait_ref.trait_ref);
971-
})
973+
});
972974
} else {
973975
self.visit_trait_ref(&trait_ref.trait_ref);
974976
}
977+
self.trait_ref_hack = trait_ref_hack;
975978
if should_pop_missing_lt {
976979
self.missing_named_lifetime_spots.pop();
977980
}

src/test/ui/where-clauses/where-lifetime-resolution.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ fn f() where
77
//~^ ERROR use of undeclared lifetime name `'a`
88
for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
99
//~^ ERROR use of undeclared lifetime name `'b`
10-
//~| ERROR nested quantification of lifetimes
1110
{}
1211

1312
fn main() {}

src/test/ui/where-clauses/where-lifetime-resolution.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ LL | for<'a> dyn Trait1<'a>: Trait1<'a>, // OK
77
LL | (dyn for<'a> Trait1<'a>): Trait1<'a>,
88
| ^^ undeclared lifetime
99

10-
error[E0316]: nested quantification of lifetimes
11-
--> $DIR/where-lifetime-resolution.rs:8:17
12-
|
13-
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
14-
| ^^^^^^^^^^^^^^^^^^^^^^
15-
1610
error[E0261]: use of undeclared lifetime name `'b`
1711
--> $DIR/where-lifetime-resolution.rs:8:52
1812
|
@@ -22,6 +16,6 @@ LL | fn f() where
2216
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
2317
| ^^ undeclared lifetime
2418

25-
error: aborting due to 3 previous errors
19+
error: aborting due to 2 previous errors
2620

2721
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)