Skip to content

Commit c920ae9

Browse files
committed
Correctly handle binders inside trait predicates
1 parent bb86748 commit c920ae9

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
@@ -908,7 +908,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
908908
})
909909
.collect();
910910
if !lifetimes.is_empty() {
911-
self.trait_ref_hack = true;
912911
let next_early_index = self.next_early_index();
913912
let scope = Scope::Binder {
914913
lifetimes,
@@ -920,9 +919,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
920919
let result = self.with(scope, |old_scope, this| {
921920
this.check_lifetime_params(old_scope, &bound_generic_params);
922921
this.visit_ty(&bounded_ty);
922+
this.trait_ref_hack = true;
923923
walk_list!(this, visit_param_bound, bounds);
924+
this.trait_ref_hack = false;
924925
});
925-
self.trait_ref_hack = false;
926926
result
927927
} else {
928928
self.visit_ty(&bounded_ty);
@@ -957,13 +957,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
957957
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
958958

959959
let should_pop_missing_lt = self.is_trait_ref_fn_scope(trait_ref);
960-
if !self.trait_ref_hack
960+
961+
let trait_ref_hack = take(&mut self.trait_ref_hack);
962+
if !trait_ref_hack
961963
|| trait_ref.bound_generic_params.iter().any(|param| match param.kind {
962964
GenericParamKind::Lifetime { .. } => true,
963965
_ => false,
964966
})
965967
{
966-
if self.trait_ref_hack {
968+
if trait_ref_hack {
967969
struct_span_err!(
968970
self.tcx.sess,
969971
trait_ref.span,
@@ -993,10 +995,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
993995
this.check_lifetime_params(old_scope, &trait_ref.bound_generic_params);
994996
walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
995997
this.visit_trait_ref(&trait_ref.trait_ref);
996-
})
998+
});
997999
} else {
9981000
self.visit_trait_ref(&trait_ref.trait_ref);
9991001
}
1002+
self.trait_ref_hack = trait_ref_hack;
10001003
if should_pop_missing_lt {
10011004
self.missing_named_lifetime_spots.pop();
10021005
}

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)