about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_borrowck/src/region_infer/opaque_types.rs8
-rw-r--r--tests/ui/error-codes/E0657.rs2
-rw-r--r--tests/ui/error-codes/E0657.stderr27
-rw-r--r--tests/ui/type-alias-impl-trait/escaping-bound-var.rs4
-rw-r--r--tests/ui/type-alias-impl-trait/escaping-bound-var.stderr14
5 files changed, 14 insertions, 41 deletions
diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs
index 0474dd18d45..84bacabc14e 100644
--- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs
+++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs
@@ -478,6 +478,10 @@ fn check_opaque_type_parameter_valid<'tcx>(
             let opaque_param = opaque_generics.param_at(i, tcx);
             let kind = opaque_param.kind.descr();
 
+            if let Err(guar) = opaque_env.param_is_error(i) {
+                return Err(guar);
+            }
+
             return Err(tcx.dcx().emit_err(NonGenericOpaqueTypeParam {
                 ty: arg,
                 kind,
@@ -536,6 +540,10 @@ impl<'tcx> LazyOpaqueTyEnv<'tcx> {
         canonical_args[param1] == canonical_args[param2]
     }
 
+    pub fn param_is_error(&self, param_index: usize) -> Result<(), ErrorGuaranteed> {
+        self.get_canonical_args()[param_index].error_reported()
+    }
+
     fn get_canonical_args(&self) -> ty::GenericArgsRef<'tcx> {
         use rustc_hir as hir;
         use rustc_infer::infer::outlives::env::OutlivesEnvironment;
diff --git a/tests/ui/error-codes/E0657.rs b/tests/ui/error-codes/E0657.rs
index d70c0b334fa..212c1d9e581 100644
--- a/tests/ui/error-codes/E0657.rs
+++ b/tests/ui/error-codes/E0657.rs
@@ -11,7 +11,6 @@ fn free_fn_capture_hrtb_in_impl_trait()
         //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
 {
     Box::new(())
-    //~^ ERROR expected generic lifetime parameter, found `'static`
 }
 
 struct Foo;
@@ -21,7 +20,6 @@ impl Foo {
             //~^ ERROR `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
     {
         Box::new(())
-        //~^ ERROR expected generic lifetime parameter, found `'static`
     }
 }
 
diff --git a/tests/ui/error-codes/E0657.stderr b/tests/ui/error-codes/E0657.stderr
index 28b989aa429..c539007cdcf 100644
--- a/tests/ui/error-codes/E0657.stderr
+++ b/tests/ui/error-codes/E0657.stderr
@@ -10,37 +10,18 @@ note: lifetime declared here
 LL |     -> Box<for<'a> Id<impl Lt<'a>>>
    |                ^^
 
-error[E0792]: expected generic lifetime parameter, found `'static`
-  --> $DIR/E0657.rs:13:5
-   |
-LL |     -> Box<for<'a> Id<impl Lt<'a>>>
-   |                               -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
-...
-LL |     Box::new(())
-   |     ^^^^^^^^^^^^
-
 error[E0657]: `impl Trait` cannot capture higher-ranked lifetime from `dyn` type
-  --> $DIR/E0657.rs:20:35
+  --> $DIR/E0657.rs:19:35
    |
 LL |         -> Box<for<'a> Id<impl Lt<'a>>>
    |                                   ^^
    |
 note: lifetime declared here
-  --> $DIR/E0657.rs:20:20
+  --> $DIR/E0657.rs:19:20
    |
 LL |         -> Box<for<'a> Id<impl Lt<'a>>>
    |                    ^^
 
-error[E0792]: expected generic lifetime parameter, found `'static`
-  --> $DIR/E0657.rs:23:9
-   |
-LL |         -> Box<for<'a> Id<impl Lt<'a>>>
-   |                                   -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
-...
-LL |         Box::new(())
-   |         ^^^^^^^^^^^^
-
-error: aborting due to 4 previous errors
+error: aborting due to 2 previous errors
 
-Some errors have detailed explanations: E0657, E0792.
-For more information about an error, try `rustc --explain E0657`.
+For more information about this error, try `rustc --explain E0657`.
diff --git a/tests/ui/type-alias-impl-trait/escaping-bound-var.rs b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs
index 4abd6b75ae6..1ff200680be 100644
--- a/tests/ui/type-alias-impl-trait/escaping-bound-var.rs
+++ b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs
@@ -17,10 +17,6 @@ impl Test<'_> for () {}
 
 fn constrain() -> Foo {
     ()
-    //~^ ERROR expected generic lifetime parameter, found `'static`
-    // FIXME(aliemjay): Undesirable error message appears because error regions
-    // are converterted internally into `'?0` which corresponds to `'static`
-    // This should be fixed in a later commit.
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr b/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr
index b903b9f9151..09f6fba79cf 100644
--- a/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr
+++ b/tests/ui/type-alias-impl-trait/escaping-bound-var.stderr
@@ -10,16 +10,6 @@ note: lifetime declared here
 LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
    |                         ^^
 
-error[E0792]: expected generic lifetime parameter, found `'static`
-  --> $DIR/escaping-bound-var.rs:19:5
-   |
-LL | pub type Foo = impl for<'a> Trait<'a, Assoc = impl Test<'a>>;
-   |                         -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
-...
-LL |     ()
-   |     ^^
-
-error: aborting due to 2 previous errors
+error: aborting due to 1 previous error
 
-Some errors have detailed explanations: E0657, E0792.
-For more information about an error, try `rustc --explain E0657`.
+For more information about this error, try `rustc --explain E0657`.