From 2bbcdc73339c2b7c3e57c2fc0d3bc574945c0023 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 24 Jul 2022 18:57:41 +0000 Subject: [PATCH] Handle additional lifetime bounds on GATs like on methods --- .../src/infer/error_reporting/mod.rs | 24 ++++++++++++------- .../generic-associated-types/impl_bounds.rs | 2 +- .../impl_bounds.stderr | 14 +++++------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 4e87ec86658f..a990c359e0a3 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -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>( diff --git a/src/test/ui/generic-associated-types/impl_bounds.rs b/src/test/ui/generic-associated-types/impl_bounds.rs index 01403a352d4b..ec1d171c0447 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.rs +++ b/src/test/ui/generic-associated-types/impl_bounds.rs @@ -13,7 +13,7 @@ struct Fooy(T); impl Foo for Fooy { 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 diff --git a/src/test/ui/generic-associated-types/impl_bounds.stderr b/src/test/ui/generic-associated-types/impl_bounds.stderr index 6d63f187d869..c3311e21959f 100644 --- a/src/test/ui/generic-associated-types/impl_bounds.stderr +++ b/src/test/ui/generic-associated-types/impl_bounds.stderr @@ -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 Foo for Fooy { - | +++++++++ + | ^^^^^^^ 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 Foo for Fooy { 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`.