Correctly handle binders inside trait predicates
This commit is contained in:
parent
033013cab3
commit
29272fc514
3 changed files with 9 additions and 13 deletions
|
@ -883,7 +883,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
})
|
||||
.collect();
|
||||
if !lifetimes.is_empty() {
|
||||
self.trait_ref_hack = true;
|
||||
let next_early_index = self.next_early_index();
|
||||
let scope = Scope::Binder {
|
||||
lifetimes,
|
||||
|
@ -895,9 +894,10 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
let result = self.with(scope, |old_scope, this| {
|
||||
this.check_lifetime_params(old_scope, &bound_generic_params);
|
||||
this.visit_ty(&bounded_ty);
|
||||
this.trait_ref_hack = true;
|
||||
walk_list!(this, visit_param_bound, bounds);
|
||||
this.trait_ref_hack = false;
|
||||
});
|
||||
self.trait_ref_hack = false;
|
||||
result
|
||||
} else {
|
||||
self.visit_ty(&bounded_ty);
|
||||
|
@ -932,13 +932,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
|
||||
|
||||
let should_pop_missing_lt = self.is_trait_ref_fn_scope(trait_ref);
|
||||
if !self.trait_ref_hack
|
||||
|
||||
let trait_ref_hack = take(&mut self.trait_ref_hack);
|
||||
if !trait_ref_hack
|
||||
|| trait_ref.bound_generic_params.iter().any(|param| match param.kind {
|
||||
GenericParamKind::Lifetime { .. } => true,
|
||||
_ => false,
|
||||
})
|
||||
{
|
||||
if self.trait_ref_hack {
|
||||
if trait_ref_hack {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
trait_ref.span,
|
||||
|
@ -968,10 +970,11 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
|
|||
this.check_lifetime_params(old_scope, &trait_ref.bound_generic_params);
|
||||
walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
|
||||
this.visit_trait_ref(&trait_ref.trait_ref);
|
||||
})
|
||||
});
|
||||
} else {
|
||||
self.visit_trait_ref(&trait_ref.trait_ref);
|
||||
}
|
||||
self.trait_ref_hack = trait_ref_hack;
|
||||
if should_pop_missing_lt {
|
||||
self.missing_named_lifetime_spots.pop();
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ fn f() where
|
|||
//~^ ERROR use of undeclared lifetime name `'a`
|
||||
for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
|
||||
//~^ ERROR use of undeclared lifetime name `'b`
|
||||
//~| ERROR nested quantification of lifetimes
|
||||
{}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -7,12 +7,6 @@ LL | for<'a> dyn Trait1<'a>: Trait1<'a>, // OK
|
|||
LL | (dyn for<'a> Trait1<'a>): Trait1<'a>,
|
||||
| ^^ undeclared lifetime
|
||||
|
||||
error[E0316]: nested quantification of lifetimes
|
||||
--> $DIR/where-lifetime-resolution.rs:8:17
|
||||
|
|
||||
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0261]: use of undeclared lifetime name `'b`
|
||||
--> $DIR/where-lifetime-resolution.rs:8:52
|
||||
|
|
||||
|
@ -22,6 +16,6 @@ LL | fn f() where
|
|||
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
|
||||
| ^^ undeclared lifetime
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0261`.
|
||||
|
|
Loading…
Reference in a new issue