From e35d2867f14a36094bdceadc731fdd1d26882fc9 Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Sat, 25 Jul 2020 13:52:47 -0700 Subject: [PATCH] Fix diagnostic by using predicate in GATs too --- src/librustc_typeck/check/compare_method.rs | 6 +---- .../unsatisfied-outlives-bound.rs | 2 +- .../unsatisfied-outlives-bound.stderr | 24 +++---------------- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index bf415406675..b739e2fe1fb 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -1220,11 +1220,7 @@ fn compare_projection_bounds<'tcx>( // we want ::Y to normalize to S. This is valid because we are // checking the default value specifically here. Add this equality to the // ParamEnv for normalization specifically. - let normalize_param_env = if impl_ty.defaultness.is_final() { - // If the associated type is final then normalization can already - // do this without the explicit predicate. - param_env - } else { + let normalize_param_env = { let mut predicates = param_env.caller_bounds().iter().collect::>(); predicates.push( ty::Binder::dummy(ty::ProjectionPredicate { diff --git a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.rs b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.rs index 4831a8c63e8..7510c58d574 100644 --- a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.rs +++ b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.rs @@ -7,7 +7,7 @@ trait ATy { impl<'b> ATy for &'b () { type Item<'a> = &'b (); - //~^ ERROR cannot infer an appropriate lifetime + //~^ ERROR does not fulfill the required lifetime } trait StaticTy { diff --git a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr index 80f69becc2c..5d612284a21 100644 --- a/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr +++ b/src/test/ui/generic-associated-types/unsatisfied-outlives-bound.stderr @@ -1,31 +1,14 @@ -error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements +error[E0477]: the type `&'b ()` does not fulfill the required lifetime --> $DIR/unsatisfied-outlives-bound.rs:9:5 | LL | type Item<'a> = &'b (); | ^^^^^^^^^^^^^^^^^^^^^^^ | -note: first, the lifetime cannot outlive the lifetime `'b` as defined on the impl at 8:6... - --> $DIR/unsatisfied-outlives-bound.rs:8:6 - | -LL | impl<'b> ATy for &'b () { - | ^^ -note: ...so that the types are compatible - --> $DIR/unsatisfied-outlives-bound.rs:9:5 - | -LL | type Item<'a> = &'b (); - | ^^^^^^^^^^^^^^^^^^^^^^^ - = note: expected `ATy` - found `ATy` -note: but, the lifetime must be valid for the lifetime `'a` as defined on the associated item at 9:15... +note: type must outlive the lifetime `'a` as defined on the associated item at 9:15 --> $DIR/unsatisfied-outlives-bound.rs:9:15 | LL | type Item<'a> = &'b (); | ^^ -note: ...so that the type `&()` will meet its required lifetime bounds - --> $DIR/unsatisfied-outlives-bound.rs:9:5 - | -LL | type Item<'a> = &'b (); - | ^^^^^^^^^^^^^^^^^^^^^^^ error[E0477]: the type `&'a ()` does not fulfill the required lifetime --> $DIR/unsatisfied-outlives-bound.rs:18:5 @@ -37,5 +20,4 @@ LL | type Item<'a> = &'a (); error: aborting due to 2 previous errors -Some errors have detailed explanations: E0477, E0495. -For more information about an error, try `rustc --explain E0477`. +For more information about this error, try `rustc --explain E0477`.