Skip to content

Commit 2bbcdc7

Browse files
Handle additional lifetime bounds on GATs like on methods
1 parent 6bb7581 commit 2bbcdc7

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+15-9
Original file line numberDiff line numberDiff line change
@@ -2351,18 +2351,24 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
23512351
GenericKind::Projection(ref p) => format!("the associated type `{}`", p),
23522352
};
23532353

2354-
if let Some(SubregionOrigin::CompareImplMethodObligation {
2355-
span,
2356-
impl_item_def_id,
2357-
trait_item_def_id,
2358-
}) = origin
2359-
{
2360-
return self.report_extra_impl_obligation(
2354+
match origin {
2355+
Some(SubregionOrigin::CompareImplMethodObligation {
23612356
span,
23622357
impl_item_def_id,
23632358
trait_item_def_id,
2364-
&format!("`{}: {}`", bound_kind, sub),
2365-
);
2359+
} | SubregionOrigin::CompareImplTypeObligation {
2360+
span,
2361+
impl_item_def_id,
2362+
trait_item_def_id,
2363+
}) => {
2364+
return self.report_extra_impl_obligation(
2365+
span,
2366+
impl_item_def_id,
2367+
trait_item_def_id,
2368+
&format!("`{}: {}`", bound_kind, sub),
2369+
);
2370+
}
2371+
_ => {}
23662372
}
23672373

23682374
fn binding_suggestion<'tcx, S: fmt::Display>(

src/test/ui/generic-associated-types/impl_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct Fooy<T>(T);
1313

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

src/test/ui/generic-associated-types/impl_bounds.stderr

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
error[E0310]: the parameter type `T` may not live long enough
1+
error[E0276]: impl has stricter requirements than trait
22
--> $DIR/impl_bounds.rs:15:39
33
|
4+
LL | type A<'a> where Self: 'a;
5+
| ---------- definition of `A` from trait
6+
...
47
LL | type A<'a> = (&'a ()) where Self: 'static;
5-
| ^^^^^^^ ...so that the definition in impl matches the definition from the trait
6-
|
7-
help: consider adding an explicit lifetime bound...
8-
|
9-
LL | impl<T: 'static> Foo for Fooy<T> {
10-
| +++++++++
8+
| ^^^^^^^ impl has extra requirement `T: 'static`
119

1210
error[E0276]: impl has stricter requirements than trait
1311
--> $DIR/impl_bounds.rs:17:48
@@ -90,5 +88,5 @@ LL | impl<T: std::marker::Copy> Foo for Fooy<T> {
9088

9189
error: aborting due to 5 previous errors
9290

93-
Some errors have detailed explanations: E0276, E0277, E0310, E0478.
91+
Some errors have detailed explanations: E0276, E0277, E0478.
9492
For more information about an error, try `rustc --explain E0276`.

0 commit comments

Comments
 (0)