Fix diagnostic by using predicate in GATs too

This commit is contained in:
Tyler Mandry 2020-07-25 13:52:47 -07:00
parent 31a3bb59ce
commit e35d2867f1
3 changed files with 5 additions and 27 deletions

View file

@ -1220,11 +1220,7 @@ fn compare_projection_bounds<'tcx>(
// we want <T as X>::Y to normalize to S. This is valid because we are // we want <T as X>::Y to normalize to S. This is valid because we are
// checking the default value specifically here. Add this equality to the // checking the default value specifically here. Add this equality to the
// ParamEnv for normalization specifically. // ParamEnv for normalization specifically.
let normalize_param_env = if impl_ty.defaultness.is_final() { let normalize_param_env = {
// If the associated type is final then normalization can already
// do this without the explicit predicate.
param_env
} else {
let mut predicates = param_env.caller_bounds().iter().collect::<Vec<_>>(); let mut predicates = param_env.caller_bounds().iter().collect::<Vec<_>>();
predicates.push( predicates.push(
ty::Binder::dummy(ty::ProjectionPredicate { ty::Binder::dummy(ty::ProjectionPredicate {

View file

@ -7,7 +7,7 @@ trait ATy {
impl<'b> ATy for &'b () { impl<'b> ATy for &'b () {
type Item<'a> = &'b (); type Item<'a> = &'b ();
//~^ ERROR cannot infer an appropriate lifetime //~^ ERROR does not fulfill the required lifetime
} }
trait StaticTy { trait StaticTy {

View file

@ -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 --> $DIR/unsatisfied-outlives-bound.rs:9:5
| |
LL | type Item<'a> = &'b (); LL | type Item<'a> = &'b ();
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
| |
note: first, the lifetime cannot outlive the lifetime `'b` as defined on the impl at 8:6... note: type must outlive the lifetime `'a` as defined on the associated item at 9:15
--> $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...
--> $DIR/unsatisfied-outlives-bound.rs:9:15 --> $DIR/unsatisfied-outlives-bound.rs:9:15
| |
LL | type Item<'a> = &'b (); 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 error[E0477]: the type `&'a ()` does not fulfill the required lifetime
--> $DIR/unsatisfied-outlives-bound.rs:18:5 --> $DIR/unsatisfied-outlives-bound.rs:18:5
@ -37,5 +20,4 @@ LL | type Item<'a> = &'a ();
error: aborting due to 2 previous errors error: aborting due to 2 previous errors
Some errors have detailed explanations: E0477, E0495. For more information about this error, try `rustc --explain E0477`.
For more information about an error, try `rustc --explain E0477`.