Handle additional lifetime bounds on GATs like on methods

This commit is contained in:
Michael Goulet 2022-07-24 18:57:41 +00:00
parent 6bb7581a59
commit 2bbcdc7333
3 changed files with 22 additions and 18 deletions

View file

@ -2351,18 +2351,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
GenericKind::Projection(ref p) => format!("the associated type `{}`", p),
};
if let Some(SubregionOrigin::CompareImplMethodObligation {
span,
impl_item_def_id,
trait_item_def_id,
}) = origin
{
return self.report_extra_impl_obligation(
match origin {
Some(SubregionOrigin::CompareImplMethodObligation {
span,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", bound_kind, sub),
);
} | SubregionOrigin::CompareImplTypeObligation {
span,
impl_item_def_id,
trait_item_def_id,
}) => {
return self.report_extra_impl_obligation(
span,
impl_item_def_id,
trait_item_def_id,
&format!("`{}: {}`", bound_kind, sub),
);
}
_ => {}
}
fn binding_suggestion<'tcx, S: fmt::Display>(

View file

@ -13,7 +13,7 @@ struct Fooy<T>(T);
impl<T> Foo for Fooy<T> {
type A<'a> = (&'a ()) where Self: 'static;
//~^ ERROR the parameter type `T` may not live long enoug
//~^ ERROR impl has stricter requirements than trait
type B<'a, 'b> = (&'a(), &'b ()) where 'b: 'a;
//~^ ERROR impl has stricter requirements than trait
//~| ERROR lifetime bound not satisfied

View file

@ -1,13 +1,11 @@
error[E0310]: the parameter type `T` may not live long enough
error[E0276]: impl has stricter requirements than trait
--> $DIR/impl_bounds.rs:15:39
|
LL | type A<'a> where Self: 'a;
| ---------- definition of `A` from trait
...
LL | type A<'a> = (&'a ()) where Self: 'static;
| ^^^^^^^ ...so that the definition in impl matches the definition from the trait
|
help: consider adding an explicit lifetime bound...
|
LL | impl<T: 'static> Foo for Fooy<T> {
| +++++++++
| ^^^^^^^ impl has extra requirement `T: 'static`
error[E0276]: impl has stricter requirements than trait
--> $DIR/impl_bounds.rs:17:48
@ -90,5 +88,5 @@ LL | impl<T: std::marker::Copy> Foo for Fooy<T> {
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0276, E0277, E0310, E0478.
Some errors have detailed explanations: E0276, E0277, E0478.
For more information about an error, try `rustc --explain E0276`.