about summary refs log tree commit diff
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2024-02-27 15:57:49 +0100
committerlcnr <rust@lcnr.de>2024-02-27 15:57:49 +0100
commit71d82c2899f5d5a4b5ec8c3be3823bf1509d3bf7 (patch)
treefd106a157756d4fb00cd293ca422fd0b5d895967
parent93bc7a428cdf64a822274f7c5647ad46f8ecf122 (diff)
downloadrust-71d82c2899f5d5a4b5ec8c3be3823bf1509d3bf7.tar.gz
rust-71d82c2899f5d5a4b5ec8c3be3823bf1509d3bf7.zip
when defining opaques, require the hidden type to be well-formed
-rw-r--r--compiler/rustc_infer/src/infer/opaque_types.rs19
-rw-r--r--tests/ui/closures/issue-78720.rs4
-rw-r--r--tests/ui/closures/issue-78720.stderr6
-rw-r--r--tests/ui/impl-trait/issues/issue-86800.rs9
-rw-r--r--tests/ui/impl-trait/issues/issue-86800.stderr29
-rw-r--r--tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr10
-rw-r--r--tests/ui/impl-trait/recursive-coroutine-boxed.rs2
-rw-r--r--tests/ui/impl-trait/wf-check-hidden-type.rs3
-rw-r--r--tests/ui/impl-trait/wf-check-hidden-type.stderr22
-rw-r--r--tests/ui/lifetimes/issue-76168-hr-outlives-3.rs1
-rw-r--r--tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr19
-rw-r--r--tests/ui/traits/next-solver/normalize-async-closure-in-trait.rs2
-rw-r--r--tests/ui/traits/next-solver/normalize-async-closure-in-trait.stderr15
-rw-r--r--tests/ui/traits/non_lifetime_binders/type-match-with-late-bound.stderr16
-rw-r--r--tests/ui/type-alias-impl-trait/issue-90400-2.stderr12
-rw-r--r--tests/ui/type-alias-impl-trait/wf-check-definition-site.rs6
-rw-r--r--tests/ui/type-alias-impl-trait/wf-check-definition-site.stderr55
-rw-r--r--tests/ui/type-alias-impl-trait/wf-nested.fail.stderr21
-rw-r--r--tests/ui/type-alias-impl-trait/wf-nested.pass.stderr31
-rw-r--r--tests/ui/type-alias-impl-trait/wf-nested.pass_sound.stderr20
-rw-r--r--tests/ui/type-alias-impl-trait/wf-nested.rs5
21 files changed, 167 insertions, 140 deletions
diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs
index ec674407e52..1d27b93221e 100644
--- a/compiler/rustc_infer/src/infer/opaque_types.rs
+++ b/compiler/rustc_infer/src/infer/opaque_types.rs
@@ -605,8 +605,25 @@ impl<'tcx> InferCtxt<'tcx> {
         obligations: &mut Vec<PredicateObligation<'tcx>>,
     ) {
         let tcx = self.tcx;
-        let item_bounds = tcx.explicit_item_bounds(def_id);
+        // Require that the hidden type is well-formed. We have to
+        // make sure we wf-check the hidden type to fix #114728.
+        //
+        // However, we don't check that all types are well-formed.
+        // We only do so for types provided by the user or if they are
+        // "used", e.g. for method selection.
+        //
+        // This means we never check the wf requirements of the hidden
+        // type during MIR borrowck, causing us to infer the wrong
+        // lifetime for its member constraints which then results in
+        // unexpected region errors.
+        obligations.push(traits::Obligation::new(
+            tcx,
+            cause.clone(),
+            param_env,
+            ty::ClauseKind::WellFormed(hidden_ty.into()),
+        ));
 
+        let item_bounds = tcx.explicit_item_bounds(def_id);
         for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) {
             let predicate = predicate.fold_with(&mut BottomUpFolder {
                 tcx,
diff --git a/tests/ui/closures/issue-78720.rs b/tests/ui/closures/issue-78720.rs
index 0e1f78ae3c6..0c4f337ba57 100644
--- a/tests/ui/closures/issue-78720.rs
+++ b/tests/ui/closures/issue-78720.rs
@@ -1,7 +1,7 @@
 fn server() -> impl {
-//~^ ERROR at least one trait must be specified
+    //~^ ERROR at least one trait must be specified
+    //~| ERROR type annotations needed
     ().map2(|| "")
-    //~^ ERROR type annotations needed
 }
 
 trait FilterBase2 {
diff --git a/tests/ui/closures/issue-78720.stderr b/tests/ui/closures/issue-78720.stderr
index d8d3811af5a..2f57c7616f1 100644
--- a/tests/ui/closures/issue-78720.stderr
+++ b/tests/ui/closures/issue-78720.stderr
@@ -23,10 +23,10 @@ LL | struct Map2<Segment2, F> {
    |                     +++
 
 error[E0282]: type annotations needed
-  --> $DIR/issue-78720.rs:3:5
+  --> $DIR/issue-78720.rs:1:16
    |
-LL |     ().map2(|| "")
-   |     ^^^^^^^^^^^^^^ cannot infer type
+LL | fn server() -> impl {
+   |                ^^^^ cannot infer type
 
 error[E0308]: mismatched types
   --> $DIR/issue-78720.rs:8:39
diff --git a/tests/ui/impl-trait/issues/issue-86800.rs b/tests/ui/impl-trait/issues/issue-86800.rs
index ae6e198c2ad..172ab04f58d 100644
--- a/tests/ui/impl-trait/issues/issue-86800.rs
+++ b/tests/ui/impl-trait/issues/issue-86800.rs
@@ -1,12 +1,6 @@
 #![feature(type_alias_impl_trait)]
 
 //@ edition:2021
-//@ compile-flags:-Z treat-err-as-bug=2
-//@ error-pattern: due to `-Z treat-err-as-bug=2
-//@ failure-status:101
-//@ normalize-stderr-test ".*note: .*\n\n" -> ""
-//@ normalize-stderr-test "thread 'rustc' panicked.*:\n.*\n" -> ""
-//@ rustc-env:RUST_BACKTRACE=0
 
 use std::future::Future;
 
@@ -29,6 +23,7 @@ struct Context {
 type TransactionResult<O> = Result<O, ()>;
 
 type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
+//~^ ERROR unconstrained opaque type
 
 fn execute_transaction_fut<'f, F, O>(
     f: F,
@@ -37,6 +32,7 @@ where
     F: FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O> + 'f
 {
     f
+    //~^ ERROR expected generic lifetime parameter, found `'_`
 }
 
 impl Context {
@@ -44,6 +40,7 @@ impl Context {
         &self, f: impl FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O>
     ) -> TransactionResult<O>
     {
+        //~^ ERROR expected generic lifetime parameter, found `'_`
         let mut conn = Connection {};
         let mut transaction = TestTransaction { conn: &mut conn };
         f(&mut transaction).await
diff --git a/tests/ui/impl-trait/issues/issue-86800.stderr b/tests/ui/impl-trait/issues/issue-86800.stderr
index 7af4846a959..146d2f67942 100644
--- a/tests/ui/impl-trait/issues/issue-86800.stderr
+++ b/tests/ui/impl-trait/issues/issue-86800.stderr
@@ -1,11 +1,13 @@
 error: unconstrained opaque type
-  --> $DIR/issue-86800.rs:31:34
+  --> $DIR/issue-86800.rs:25:34
    |
 LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-error: internal compiler error[E0792]: expected generic lifetime parameter, found `'_`
-  --> $DIR/issue-86800.rs:39:5
+   = note: `TransactionFuture` must be used in combination with a concrete type within the same module
+
+error[E0792]: expected generic lifetime parameter, found `'_`
+  --> $DIR/issue-86800.rs:34:5
    |
 LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
    |                        --- this generic parameter must be used with a generic lifetime parameter
@@ -13,9 +15,20 @@ LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResu
 LL |     f
    |     ^
 
-error: the compiler unexpectedly panicked. this is a bug.
+error[E0792]: expected generic lifetime parameter, found `'_`
+  --> $DIR/issue-86800.rs:42:5
+   |
+LL |   type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
+   |                          --- this generic parameter must be used with a generic lifetime parameter
+...
+LL | /     {
+LL | |
+LL | |         let mut conn = Connection {};
+LL | |         let mut transaction = TestTransaction { conn: &mut conn };
+LL | |         f(&mut transaction).await
+LL | |     }
+   | |_____^
+
+error: aborting due to 3 previous errors
 
-query stack during panic:
-#0 [mir_borrowck] borrow-checking `execute_transaction_fut`
-#1 [type_of_opaque] computing type of opaque `execute_transaction_fut::{opaque#0}`
-end of query stack
+For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
index fee3b86034a..4a5e4bfe94b 100644
--- a/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
+++ b/tests/ui/impl-trait/recursive-coroutine-boxed.next.stderr
@@ -1,9 +1,9 @@
 error[E0282]: type annotations needed
-  --> $DIR/recursive-coroutine-boxed.rs:10:23
+  --> $DIR/recursive-coroutine-boxed.rs:11:23
    |
 LL |         let mut gen = Box::pin(foo());
    |                       ^^^^^^^^ cannot infer type of the type parameter `T` declared on the struct `Box`
-...
+LL |
 LL |         let mut r = gen.as_mut().resume(());
    |                         ------ type must be known at this point
    |
@@ -13,10 +13,10 @@ LL |         let mut gen = Box::<T>::pin(foo());
    |                          +++++
 
 error[E0282]: type annotations needed
-  --> $DIR/recursive-coroutine-boxed.rs:10:32
+  --> $DIR/recursive-coroutine-boxed.rs:8:13
    |
-LL |         let mut gen = Box::pin(foo());
-   |                                ^^^^^ cannot infer type for opaque type `impl Coroutine<Yield = (), Return = ()>`
+LL | fn foo() -> impl Coroutine<Yield = (), Return = ()> {
+   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for opaque type `impl Coroutine<Yield = (), Return = ()>`
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/impl-trait/recursive-coroutine-boxed.rs b/tests/ui/impl-trait/recursive-coroutine-boxed.rs
index a42ae68f28e..8f0bbb400cf 100644
--- a/tests/ui/impl-trait/recursive-coroutine-boxed.rs
+++ b/tests/ui/impl-trait/recursive-coroutine-boxed.rs
@@ -6,10 +6,10 @@
 use std::ops::{Coroutine, CoroutineState};
 
 fn foo() -> impl Coroutine<Yield = (), Return = ()> {
+    //[next]~^ ERROR type annotations needed
     || {
         let mut gen = Box::pin(foo());
         //[next]~^ ERROR type annotations needed
-        //[next]~| ERROR type annotations needed
         let mut r = gen.as_mut().resume(());
         while let CoroutineState::Yielded(v) = r {
             yield v;
diff --git a/tests/ui/impl-trait/wf-check-hidden-type.rs b/tests/ui/impl-trait/wf-check-hidden-type.rs
index 29f15024d76..c3b1182a98f 100644
--- a/tests/ui/impl-trait/wf-check-hidden-type.rs
+++ b/tests/ui/impl-trait/wf-check-hidden-type.rs
@@ -11,8 +11,7 @@ impl<'a, 'b> Extend<'a, 'b> for Option<&'b &'a ()> {
 }
 
 fn boom<'a, 'b>() -> impl Extend<'a, 'b> {
-    //~^ ERROR in type `&'b &'a ()`, reference has a longer lifetime than the data it references
-    None::<&'_ &'_ ()>
+    None::<&'_ &'_ ()> //~ ERROR lifetime may not live long enough
 }
 
 fn main() {
diff --git a/tests/ui/impl-trait/wf-check-hidden-type.stderr b/tests/ui/impl-trait/wf-check-hidden-type.stderr
index 10c766c268c..86ba7aff54a 100644
--- a/tests/ui/impl-trait/wf-check-hidden-type.stderr
+++ b/tests/ui/impl-trait/wf-check-hidden-type.stderr
@@ -1,20 +1,14 @@
-error[E0491]: in type `&'b &'a ()`, reference has a longer lifetime than the data it references
-  --> $DIR/wf-check-hidden-type.rs:13:22
+error: lifetime may not live long enough
+  --> $DIR/wf-check-hidden-type.rs:14:5
    |
 LL | fn boom<'a, 'b>() -> impl Extend<'a, 'b> {
-   |                      ^^^^^^^^^^^^^^^^^^^
+   |         --  -- lifetime `'b` defined here
+   |         |
+   |         lifetime `'a` defined here
+LL |     None::<&'_ &'_ ()>
+   |     ^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
    |
-note: the pointer is valid for the lifetime `'b` as defined here
-  --> $DIR/wf-check-hidden-type.rs:13:13
-   |
-LL | fn boom<'a, 'b>() -> impl Extend<'a, 'b> {
-   |             ^^
-note: but the referenced data is only valid for the lifetime `'a` as defined here
-  --> $DIR/wf-check-hidden-type.rs:13:9
-   |
-LL | fn boom<'a, 'b>() -> impl Extend<'a, 'b> {
-   |         ^^
+   = help: consider adding the following bound: `'a: 'b`
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0491`.
diff --git a/tests/ui/lifetimes/issue-76168-hr-outlives-3.rs b/tests/ui/lifetimes/issue-76168-hr-outlives-3.rs
index 03913869503..85eeb5d4c90 100644
--- a/tests/ui/lifetimes/issue-76168-hr-outlives-3.rs
+++ b/tests/ui/lifetimes/issue-76168-hr-outlives-3.rs
@@ -6,6 +6,7 @@ use std::future::Future;
 async fn wrapper<F>(f: F)
 //~^ ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
 //~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
+//~| ERROR: expected a `FnOnce(&'a mut i32)` closure, found `i32`
 where
 F:,
 for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
diff --git a/tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr b/tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr
index 89ebdb57f3c..578ba149baf 100644
--- a/tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr
+++ b/tests/ui/lifetimes/issue-76168-hr-outlives-3.stderr
@@ -4,6 +4,7 @@ error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
 LL | / async fn wrapper<F>(f: F)
 LL | |
 LL | |
+LL | |
 LL | | where
 LL | | F:,
 LL | | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
@@ -20,7 +21,21 @@ LL | async fn wrapper<F>(f: F)
    = help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
 
 error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
-  --> $DIR/issue-76168-hr-outlives-3.rs:12:1
+  --> $DIR/issue-76168-hr-outlives-3.rs:6:1
+   |
+LL | / async fn wrapper<F>(f: F)
+LL | |
+LL | |
+LL | |
+LL | | where
+LL | | F:,
+LL | | for<'a> <i32 as FnOnce<(&'a mut i32,)>>::Output: Future<Output = ()> + 'a,
+   | |__________________________________________________________________________^ expected an `FnOnce(&'a mut i32)` closure, found `i32`
+   |
+   = help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
+
+error[E0277]: expected a `FnOnce(&'a mut i32)` closure, found `i32`
+  --> $DIR/issue-76168-hr-outlives-3.rs:13:1
    |
 LL | / {
 LL | |
@@ -31,6 +46,6 @@ LL | | }
    |
    = help: the trait `for<'a> FnOnce<(&'a mut i32,)>` is not implemented for `i32`
 
-error: aborting due to 3 previous errors
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0277`.
diff --git a/tests/ui/traits/next-solver/normalize-async-closure-in-trait.rs b/tests/ui/traits/next-solver/normalize-async-closure-in-trait.rs
index 8cdde4f4d51..968c18cb9f5 100644
--- a/tests/ui/traits/next-solver/normalize-async-closure-in-trait.rs
+++ b/tests/ui/traits/next-solver/normalize-async-closure-in-trait.rs
@@ -1,5 +1,5 @@
 //@ compile-flags: -Znext-solver
-//@ check-pass
+//@ known-bug: unknown
 //@ edition:2021
 
 trait Foo {
diff --git a/tests/ui/traits/next-solver/normalize-async-closure-in-trait.stderr b/tests/ui/traits/next-solver/normalize-async-closure-in-trait.stderr
new file mode 100644
index 00000000000..c10cddd95b5
--- /dev/null
+++ b/tests/ui/traits/next-solver/normalize-async-closure-in-trait.stderr
@@ -0,0 +1,15 @@
+error[E0271]: type mismatch resolving `impl Future<Output = ()> == {async fn body@$DIR/normalize-async-closure-in-trait.rs:6:20: 6:22}`
+  --> $DIR/normalize-async-closure-in-trait.rs:6:20
+   |
+LL |     async fn bar() {}
+   |                    ^^ types differ
+
+error[E0271]: type mismatch resolving `{async fn body@$DIR/normalize-async-closure-in-trait.rs:6:20: 6:22} <: impl Future<Output = ()>`
+  --> $DIR/normalize-async-closure-in-trait.rs:6:20
+   |
+LL |     async fn bar() {}
+   |                    ^^ types differ
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0271`.
diff --git a/tests/ui/traits/non_lifetime_binders/type-match-with-late-bound.stderr b/tests/ui/traits/non_lifetime_binders/type-match-with-late-bound.stderr
index 3a4415ed23a..6c259621466 100644
--- a/tests/ui/traits/non_lifetime_binders/type-match-with-late-bound.stderr
+++ b/tests/ui/traits/non_lifetime_binders/type-match-with-late-bound.stderr
@@ -21,6 +21,20 @@ help: consider adding an explicit lifetime bound
 LL |     for<F> F: 'a, !1_"F": 'a
    |                 ~~~~~~~~~~~~
 
-error: aborting due to 1 previous error; 1 warning emitted
+error[E0309]: the placeholder type `!2_"F"` may not live long enough
+  --> $DIR/type-match-with-late-bound.rs:11:1
+   |
+LL | async fn walk2<'a, T: 'a>(_: T)
+   |                -- the placeholder type `!2_"F"` must be valid for the lifetime `'a` as defined here...
+...
+LL | {}
+   | ^^ ...so that the type `F` will meet its required lifetime bounds
+   |
+help: consider adding an explicit lifetime bound
+   |
+LL |     for<F> F: 'a, !2_"F": 'a
+   |                 ~~~~~~~~~~~~
+
+error: aborting due to 2 previous errors; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0309`.
diff --git a/tests/ui/type-alias-impl-trait/issue-90400-2.stderr b/tests/ui/type-alias-impl-trait/issue-90400-2.stderr
index 5e978e97d6b..b4b78f8175f 100644
--- a/tests/ui/type-alias-impl-trait/issue-90400-2.stderr
+++ b/tests/ui/type-alias-impl-trait/issue-90400-2.stderr
@@ -2,15 +2,13 @@ error[E0277]: the trait bound `B: Bar` is not satisfied
   --> $DIR/issue-90400-2.rs:25:9
    |
 LL |         MyBaz(bar)
-   |         ^^^^^^^^^^ the trait `Bar` is not implemented for `B`, which is required by `MyBaz<B>: Baz`
+   |         ^^^^^^^^^^ the trait `Bar` is not implemented for `B`
    |
-note: required for `MyBaz<B>` to implement `Baz`
-  --> $DIR/issue-90400-2.rs:30:14
+note: required by a bound in `MyBaz`
+  --> $DIR/issue-90400-2.rs:29:17
    |
-LL | impl<B: Bar> Baz for MyBaz<B> {
-   |         ---  ^^^     ^^^^^^^^
-   |         |
-   |         unsatisfied trait bound introduced here
+LL | struct MyBaz<B: Bar>(B);
+   |                 ^^^ required by this bound in `MyBaz`
 help: consider restricting type parameter `B`
    |
 LL |     type FooFn<B: Bar> = impl Baz;
diff --git a/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs b/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs
index 2b5c9781a96..59c43574f8b 100644
--- a/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs
+++ b/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs
@@ -1,3 +1,5 @@
+//@ check-pass
+
 // Regression test for #114572, We were inferring an ill-formed type:
 //
 // `Opaque<'a> = Static<&'a str>`, vs
@@ -7,18 +9,15 @@
 struct Static<T: 'static>(T);
 
 type OpaqueRet<'a> = impl Sized + 'a;
-//~^ ERROR the type `&'a u8` does not fulfill the required lifetime
 fn test_return<'a>(msg: Static<&'static u8>) -> OpaqueRet<'a> {
     msg
 }
 
 fn test_rpit<'a>(msg: Static<&'static u8>) -> impl Sized + 'a {
-    //~^ ERROR the type `&'a u8` does not fulfill the required lifetime
     msg
 }
 
 type OpaqueAssign<'a> = impl Sized + 'a;
-//~^ ERROR the type `&'a u8` does not fulfill the required lifetime
 fn test_assign<'a>(msg: Static<&'static u8>) -> Option<OpaqueAssign<'a>> {
     let _: OpaqueAssign<'a> = msg;
     None
@@ -29,7 +28,6 @@ fn test_assign<'a>(msg: Static<&'static u8>) -> Option<OpaqueAssign<'a>> {
 trait RefAt<'a>: 'a {}
 struct Ref<'a, T: RefAt<'a>>(&'a T);
 type OpaqueRef<'a, T: RefAt<'static>> = impl Sized + 'a;
-//~^ ERROR mismatched types
 fn test_trait<'a, T: RefAt<'static>>(msg: Ref<'static, T>) -> OpaqueRef<'a, T> {
     msg
 }
diff --git a/tests/ui/type-alias-impl-trait/wf-check-definition-site.stderr b/tests/ui/type-alias-impl-trait/wf-check-definition-site.stderr
deleted file mode 100644
index a51c6bb2ec0..00000000000
--- a/tests/ui/type-alias-impl-trait/wf-check-definition-site.stderr
+++ /dev/null
@@ -1,55 +0,0 @@
-error[E0477]: the type `&'a u8` does not fulfill the required lifetime
-  --> $DIR/wf-check-definition-site.rs:9:22
-   |
-LL | type OpaqueRet<'a> = impl Sized + 'a;
-   |                      ^^^^^^^^^^^^^^^
-   |
-note: type must satisfy the static lifetime as required by this binding
-  --> $DIR/wf-check-definition-site.rs:7:18
-   |
-LL | struct Static<T: 'static>(T);
-   |                  ^^^^^^^
-
-error[E0477]: the type `&'a u8` does not fulfill the required lifetime
-  --> $DIR/wf-check-definition-site.rs:15:47
-   |
-LL | fn test_rpit<'a>(msg: Static<&'static u8>) -> impl Sized + 'a {
-   |                                               ^^^^^^^^^^^^^^^
-   |
-note: type must satisfy the static lifetime as required by this binding
-  --> $DIR/wf-check-definition-site.rs:7:18
-   |
-LL | struct Static<T: 'static>(T);
-   |                  ^^^^^^^
-
-error[E0477]: the type `&'a u8` does not fulfill the required lifetime
-  --> $DIR/wf-check-definition-site.rs:20:25
-   |
-LL | type OpaqueAssign<'a> = impl Sized + 'a;
-   |                         ^^^^^^^^^^^^^^^
-   |
-note: type must satisfy the static lifetime as required by this binding
-  --> $DIR/wf-check-definition-site.rs:7:18
-   |
-LL | struct Static<T: 'static>(T);
-   |                  ^^^^^^^
-
-error[E0308]: mismatched types
-  --> $DIR/wf-check-definition-site.rs:31:41
-   |
-LL | type OpaqueRef<'a, T: RefAt<'static>> = impl Sized + 'a;
-   |                                         ^^^^^^^^^^^^^^^ lifetime mismatch
-   |
-   = note: expected trait `RefAt<'a>`
-              found trait `RefAt<'static>`
-note: the lifetime `'a` as defined here...
-  --> $DIR/wf-check-definition-site.rs:31:16
-   |
-LL | type OpaqueRef<'a, T: RefAt<'static>> = impl Sized + 'a;
-   |                ^^
-   = note: ...does not necessarily outlive the static lifetime
-
-error: aborting due to 4 previous errors
-
-Some errors have detailed explanations: E0308, E0477.
-For more information about an error, try `rustc --explain E0308`.
diff --git a/tests/ui/type-alias-impl-trait/wf-nested.fail.stderr b/tests/ui/type-alias-impl-trait/wf-nested.fail.stderr
index dd6b5a166ec..79b726f83dd 100644
--- a/tests/ui/type-alias-impl-trait/wf-nested.fail.stderr
+++ b/tests/ui/type-alias-impl-trait/wf-nested.fail.stderr
@@ -1,21 +1,16 @@
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/wf-nested.rs:60:27
+  --> $DIR/wf-nested.rs:64:38
    |
-LL |     type InnerOpaque<T> = impl Sized;
-   |                           ^^^^^^^^^^
-   |                           |
-   |                           the parameter type `T` must be valid for the static lifetime...
-   |                           ...so that the type `T` will meet its required lifetime bounds...
+LL |     fn define<T>() -> OuterOpaque<T> {}
+   |                                      ^^
+   |                                      |
+   |                                      the parameter type `T` must be valid for the static lifetime...
+   |                                      ...so that the type `T` will meet its required lifetime bounds
    |
-note: ...that is required by this bound
-  --> $DIR/wf-nested.rs:12:20
-   |
-LL | struct IsStatic<T: 'static>(T);
-   |                    ^^^^^^^
 help: consider adding an explicit lifetime bound
    |
-LL |     type InnerOpaque<T: 'static> = impl Sized;
-   |                       +++++++++
+LL |     fn define<T: 'static>() -> OuterOpaque<T> {}
+   |                +++++++++
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/type-alias-impl-trait/wf-nested.pass.stderr b/tests/ui/type-alias-impl-trait/wf-nested.pass.stderr
index 820710afef5..b61b69d8e40 100644
--- a/tests/ui/type-alias-impl-trait/wf-nested.pass.stderr
+++ b/tests/ui/type-alias-impl-trait/wf-nested.pass.stderr
@@ -1,22 +1,31 @@
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/wf-nested.rs:36:57
+  --> $DIR/wf-nested.rs:34:38
    |
-LL |     fn define_rpit<T>() -> impl Trait<&'static T, Out = impl Sized> {}
-   |                                                         ^^^^^^^^^^
-   |                                                         |
-   |                                                         the parameter type `T` must be valid for the static lifetime...
-   |                                                         ...so that the type `T` will meet its required lifetime bounds...
+LL |     fn define<T>() -> OuterOpaque<T> {}
+   |                                      ^^
+   |                                      |
+   |                                      the parameter type `T` must be valid for the static lifetime...
+   |                                      ...so that the type `T` will meet its required lifetime bounds
+   |
+help: consider adding an explicit lifetime bound
    |
-note: ...that is required by this bound
-  --> $DIR/wf-nested.rs:12:20
+LL |     fn define<T: 'static>() -> OuterOpaque<T> {}
+   |                +++++++++
+
+error[E0310]: the parameter type `T` may not live long enough
+  --> $DIR/wf-nested.rs:37:69
+   |
+LL |     fn define_rpit<T>() -> impl Trait<&'static T, Out = impl Sized> {}
+   |                                                                     ^^
+   |                                                                     |
+   |                                                                     the parameter type `T` must be valid for the static lifetime...
+   |                                                                     ...so that the type `T` will meet its required lifetime bounds
    |
-LL | struct IsStatic<T: 'static>(T);
-   |                    ^^^^^^^
 help: consider adding an explicit lifetime bound
    |
 LL |     fn define_rpit<T: 'static>() -> impl Trait<&'static T, Out = impl Sized> {}
    |                     +++++++++
 
-error: aborting due to 1 previous error
+error: aborting due to 2 previous errors
 
 For more information about this error, try `rustc --explain E0310`.
diff --git a/tests/ui/type-alias-impl-trait/wf-nested.pass_sound.stderr b/tests/ui/type-alias-impl-trait/wf-nested.pass_sound.stderr
index 2bc8be27a60..dbd3a1394f8 100644
--- a/tests/ui/type-alias-impl-trait/wf-nested.pass_sound.stderr
+++ b/tests/ui/type-alias-impl-trait/wf-nested.pass_sound.stderr
@@ -1,5 +1,19 @@
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/wf-nested.rs:49:17
+  --> $DIR/wf-nested.rs:46:38
+   |
+LL |     fn define<T>() -> OuterOpaque<T> {}
+   |                                      ^^
+   |                                      |
+   |                                      the parameter type `T` must be valid for the static lifetime...
+   |                                      ...so that the type `T` will meet its required lifetime bounds
+   |
+help: consider adding an explicit lifetime bound
+   |
+LL |     fn define<T: 'static>() -> OuterOpaque<T> {}
+   |                +++++++++
+
+error[E0310]: the parameter type `T` may not live long enough
+  --> $DIR/wf-nested.rs:51:17
    |
 LL |         let _ = outer.get();
    |                 ^^^^^^^^^^^
@@ -13,7 +27,7 @@ LL |     fn test<T: 'static>() {
    |              +++++++++
 
 error[E0310]: the parameter type `T` may not live long enough
-  --> $DIR/wf-nested.rs:49:17
+  --> $DIR/wf-nested.rs:51:17
    |
 LL |         let _ = outer.get();
    |                 ^^^^^^^^^^^
@@ -27,6 +41,6 @@ help: consider adding an explicit lifetime bound
 LL |     fn test<T: 'static>() {
    |              +++++++++
 
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0310`.
diff --git a/tests/ui/type-alias-impl-trait/wf-nested.rs b/tests/ui/type-alias-impl-trait/wf-nested.rs
index dcb4e251d47..7f070bbe6c2 100644
--- a/tests/ui/type-alias-impl-trait/wf-nested.rs
+++ b/tests/ui/type-alias-impl-trait/wf-nested.rs
@@ -32,6 +32,7 @@ mod pass {
     use super::*;
     type OuterOpaque<T> = impl Trait<&'static T, Out = impl Sized>;
     fn define<T>() -> OuterOpaque<T> {}
+    //[pass]~^ ERROR `T` may not live long enough
 
     fn define_rpit<T>() -> impl Trait<&'static T, Out = impl Sized> {}
     //[pass]~^ ERROR the parameter type `T` may not live long enough
@@ -43,6 +44,7 @@ mod pass_sound {
     use super::*;
     type OuterOpaque<T> = impl Trait<&'static T, Out = impl Sized>;
     fn define<T>() -> OuterOpaque<T> {}
+    //[pass_sound]~^ ERROR `T` may not live long enough
 
     fn test<T>() {
         let outer = define::<T>();
@@ -57,9 +59,10 @@ mod pass_sound {
 #[cfg(fail)]
 mod fail {
     use super::*;
-    type InnerOpaque<T> = impl Sized; //[fail]~ ERROR `T` may not live long enough
+    type InnerOpaque<T> = impl Sized;
     type OuterOpaque<T> = impl Trait<&'static T, Out = InnerOpaque<T>>;
     fn define<T>() -> OuterOpaque<T> {}
+    //[fail]~^ ERROR the parameter type `T` may not live long enough
 }
 
 fn main() {}