about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-07-24 18:57:41 +0000
committerMichael Goulet <michael@errs.io>2022-07-24 18:57:41 +0000
commit2bbcdc73339c2b7c3e57c2fc0d3bc574945c0023 (patch)
tree5b89bcc0cf20fc69d97b5ec95c1e5507e265b62a
parent6bb7581a5926365ec65d64d15386c3723beff330 (diff)
downloadrust-2bbcdc73339c2b7c3e57c2fc0d3bc574945c0023.tar.gz
rust-2bbcdc73339c2b7c3e57c2fc0d3bc574945c0023.zip
Handle additional lifetime bounds on GATs like on methods
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs24
-rw-r--r--src/test/ui/generic-associated-types/impl_bounds.rs2
-rw-r--r--src/test/ui/generic-associated-types/impl_bounds.stderr14
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 4e87ec86658..a990c359e0a 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 01403a352d4..ec1d171c044 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>(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
diff --git a/src/test/ui/generic-associated-types/impl_bounds.stderr b/src/test/ui/generic-associated-types/impl_bounds.stderr
index 6d63f187d86..c3311e21959 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<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`.