Skip to content

Commit

Permalink
Handle additional lifetime bounds on GATs like on methods
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jul 24, 2022
1 parent 6bb7581 commit 2bbcdc7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
24 changes: 15 additions & 9 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>(
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/generic-associated-types/impl_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions src/test/ui/generic-associated-types/impl_bounds.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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`.

0 comments on commit 2bbcdc7

Please sign in to comment.