about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-08-21 03:49:17 +0000
committerbors <bors@rust-lang.org>2025-08-21 03:49:17 +0000
commit922958cffe059e9c156835df19d199ccd861c36a (patch)
tree3059ab2c1c181c0fde55975b3395157239890bc3 /tests
parent125ff8a788c5d6a66917f499abdc00051afe6886 (diff)
parentc2a0fa86adae16d38bd8fa4603694fa4a0913189 (diff)
downloadrust-922958cffe059e9c156835df19d199ccd861c36a.tar.gz
rust-922958cffe059e9c156835df19d199ccd861c36a.zip
Auto merge of #145244 - lcnr:handle-opaque-types-before-region-inference, r=BoxyUwU
support non-defining uses of opaques in borrowck

Reimplements the first part of rust-lang/rust#139587, but limited to only the new solver. To do so I also entirely rewrite the way we handle opaque types in borrowck even on stable. This should not impact behavior however.

We now support revealing uses during MIR borrowck with the new solver:
```rust
fn foo<'a>(x: &'a u32) -> impl Sized + use<'a> {
    let local = 1;
    foo::<'_>(&local);
    x
}
```

### How do opaque types work right now

Whenever we use an opaque type during type checking, we remember this use in the `opaque_type_storage` of the `InferCtxt`.

Right now, we collect all *member constraints* at the end of MIR type check by looking at all uses from the `opaque_type_storage`. We then apply these constraints while computing the region values for each SCC. This does not add actual region constraints but directly updates the final region values.

This means we need to manually handle any constraints from member constraints for diagnostics. We do this by separately tracking `applied_member_constraints` in the `RegionInferenceContext`.

After we've finished computing the region values, it is now immutable and we check whether all member constraints hold. If not, we error.

We now map the hidden types of our defining uses to the defining scope. This assumes that all member constraints apply. To handle non-member regions, we simply map any region in the hidden type we fail to map to a choice region to `'erased` https://github.com/rust-lang/rust/blob/b1b26b834d85e84b46aa8f8f3ce210a1627aa85f/compiler/rustc_borrowck/src/region_infer/opaque_types.rs#L126-L132

### How do we handle opaque types with this PR

MIR type check still works the same by populating the `opaque_type_storage` whenever we use an opaque type.

We now have a new step `fn handle_opaque_type_uses` which happens between MIR type check and `compute_regions`.

This step looks at all opaque type uses in the storage and first checks whether they are defining: are the arguments of the `opaque_type_key` unique region parameters. *With the new solver we silently ignore any *non-defining* uses here. The old solver emits an errors.*

`fn compute_concrete_opaque_types`: We then collect all member constraints for the defining uses and apply them just like we did before. However, we do it on a temporary region graph which is only used while computing the concrete opaque types. We then use this region graph to compute the concrete type which we then store in the `root_cx`.

`fn apply_computed_concrete_opaque_types`: Now that we know the final concrete type of each opaque type and have mapped them to the definition of the opaque. We iterate over all opaque type uses and equate their hidden type with the instantiated final concrete type. This is the step which actually mutates the region graph.

The actual region checking can now entirely ignores opaque types (outside of the `ConstraintCategory` from checking the opaque type uses).

### Diagnostics issue (chill)

Because we now simply use type equality to "apply member constraints" we get ordinary `OutlivesConstraint`s, even if the regions were already related to another.

This is generally not an issue, expect that it can *hide* the actual region constraints which resulted in the final value of the opaque. The constraints we get from checking against the final opaque type definition relies on constraints we used to compute that definition.

I mostly handle this by updating `find_constraint_path_between_regions` to first ignore member constraints in its search and only if that does not find a path, retry while considering member constraints.

### Diagnostics issue (not chill)

A separate issue is that `find_constraint_paths_between_regions` currently looks up member constraints by their **scc**, not by region value:
https://github.com/rust-lang/rust/blob/2c1ac85679678dfe5cce7ea8037735b0349ceaf3/compiler/rustc_borrowck/src/region_infer/mod.rs#L1768-L1775

This means that in the `borrowck-4` test, the resulting constraint path is currently
```
('?2: '?5) due to Single(bb0[5]) (None) (Boring) (ConstraintSccIndex(1): ConstraintSccIndex(1)),
('?5: '?3) due to Single(bb0[6]) (None) (Boring) (ConstraintSccIndex(1): ConstraintSccIndex(1)),
('?3: '?0) due to All(src/main.rs:15:5: 15:6 (#0)) (None) (OpaqueType) (ConstraintSccIndex(1): ConstraintSccIndex(1))
```
Here `'?3` is equal to `'?4`, but the reason why it's in the opaque is that it's related to `'?4`. With my PR this will be correctly tracked so we end up with
```
('?2: '?5) due to Single(bb0[5]) (None) (Boring) (ConstraintSccIndex(1): ConstraintSccIndex(1)),
('?5: '?3) due to Single(bb0[6]) (None) (Boring) (ConstraintSccIndex(1): ConstraintSccIndex(1)),
('?3: '?4) due to Single(bb0[6]) (None) (Assignment) (ConstraintSccIndex(1): ConstraintSccIndex(1)),
('?4: '?0) due to All(src/main.rs:15:5: 15:6 (#0)) (None) (OpaqueType) (ConstraintSccIndex(1): ConstraintSccIndex(1)),
```
This additional `Assignment` step then worsens the error message as we stop talking about the fact that the closures is returned from the function. Fixing this is hard. I've looked into this and it's making me sad :< Properly handling this requires some deeper changes to MIR borrowck diagnostics and that seems like too much for this PR. Given that this only impacts a single test, it seems acceptable to me.

r? `@ghost`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/async-await/async-borrowck-escaping-block-error.stderr6
-rw-r--r--tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs6
-rw-r--r--tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr37
-rw-r--r--tests/ui/impl-trait/does-not-live-long-enough.stderr4
-rw-r--r--tests/ui/impl-trait/member-constraints/apply_member_constraint-no-req-eq.rs4
-rw-r--r--tests/ui/impl-trait/member-constraints/nested-impl-trait-pass.rs4
-rw-r--r--tests/ui/impl-trait/nested-rpit-hrtb.rs1
-rw-r--r--tests/ui/impl-trait/nested-rpit-hrtb.stderr14
-rw-r--r--tests/ui/impl-trait/no-anonymize-regions.rs4
-rw-r--r--tests/ui/impl-trait/non-defining-uses/as-projection-term.next.stderr6
-rw-r--r--tests/ui/impl-trait/non-defining-uses/as-projection-term.rs2
-rw-r--r--tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs4
-rw-r--r--tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr40
-rw-r--r--tests/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs2
-rw-r--r--tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr2
-rw-r--r--tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr9
-rw-r--r--tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr9
-rw-r--r--tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs3
-rw-r--r--tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.stderr7
-rw-r--r--tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.rs2
-rw-r--r--tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.stderr8
23 files changed, 97 insertions, 81 deletions
diff --git a/tests/ui/async-await/async-borrowck-escaping-block-error.stderr b/tests/ui/async-await/async-borrowck-escaping-block-error.stderr
index 8410e7eca57..6ea03c99aa0 100644
--- a/tests/ui/async-await/async-borrowck-escaping-block-error.stderr
+++ b/tests/ui/async-await/async-borrowck-escaping-block-error.stderr
@@ -6,11 +6,7 @@ LL |     Box::new(async { x } )
    |              |
    |              may outlive borrowed value `x`
    |
-note: async block is returned here
-  --> $DIR/async-borrowck-escaping-block-error.rs:6:5
-   |
-LL |     Box::new(async { x } )
-   |     ^^^^^^^^^^^^^^^^^^^^^^
+   = note: async blocks are not executed immediately and must either take a reference or ownership of outside variables they use
 help: to force the async block to take ownership of `x` (and any other referenced variables), use the `move` keyword
    |
 LL |     Box::new(async move { x } )
diff --git a/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs b/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs
index c7a37a81848..123e23d6107 100644
--- a/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs
+++ b/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.rs
@@ -5,12 +5,12 @@ struct Point {
     x: i32,
     y: i32,
 }
-fn foo () -> impl FnMut()->() {
+fn foo () -> impl FnMut() {
     let mut p = Point {x: 1, y: 2 };
     let mut c = || {
-    //~^ ERROR closure may outlive the current function, but it borrows `p`
-       p.x+=5;
+       p.x += 5;
        println!("{:?}", p);
+        //~^ ERROR `p` does not live long enough
     };
     c
 }
diff --git a/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr b/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr
index d47f0539b84..96910375e09 100644
--- a/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr
+++ b/tests/ui/closures/2229_closure_analysis/diagnostics/borrowck/borrowck-4.stderr
@@ -1,22 +1,23 @@
-error[E0373]: closure may outlive the current function, but it borrows `p`, which is owned by the current function
-  --> $DIR/borrowck-4.rs:10:17
+error[E0597]: `p` does not live long enough
+  --> $DIR/borrowck-4.rs:12:25
    |
-LL |     let mut c = || {
-   |                 ^^ may outlive borrowed value `p`
-...
-LL |        println!("{:?}", p);
-   |                         - `p` is borrowed here
-   |
-note: closure is returned here
-  --> $DIR/borrowck-4.rs:15:5
-   |
-LL |     c
-   |     ^
-help: to force the closure to take ownership of `p` (and any other referenced variables), use the `move` keyword
-   |
-LL |     let mut c = move || {
-   |                 ++++
+LL |       let mut p = Point {x: 1, y: 2 };
+   |           ----- binding `p` declared here
+LL |       let mut c = || {
+   |                   --
+   |                   |
+   |  _________________value captured here
+   | |
+LL | |        p.x += 5;
+LL | |        println!("{:?}", p);
+   | |                         ^ borrowed value does not live long enough
+LL | |
+LL | |     };
+   | |_____- assignment requires that `p` is borrowed for `'static`
+LL |       c
+LL |   }
+   |   - `p` dropped here while still borrowed
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0373`.
+For more information about this error, try `rustc --explain E0597`.
diff --git a/tests/ui/impl-trait/does-not-live-long-enough.stderr b/tests/ui/impl-trait/does-not-live-long-enough.stderr
index cfc13298071..9f3918ce3e0 100644
--- a/tests/ui/impl-trait/does-not-live-long-enough.stderr
+++ b/tests/ui/impl-trait/does-not-live-long-enough.stderr
@@ -1,12 +1,14 @@
 error[E0373]: closure may outlive the current function, but it borrows `prefix`, which is owned by the current function
   --> $DIR/does-not-live-long-enough.rs:6:33
    |
+LL |     fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator<Item=&'a str> {
+   |                     -- lifetime `'a` defined here
 LL |         self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref())
    |                                 ^^^               ------ `prefix` is borrowed here
    |                                 |
    |                                 may outlive borrowed value `prefix`
    |
-note: closure is returned here
+note: function requires argument type to outlive `'a`
   --> $DIR/does-not-live-long-enough.rs:6:9
    |
 LL |         self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref())
diff --git a/tests/ui/impl-trait/member-constraints/apply_member_constraint-no-req-eq.rs b/tests/ui/impl-trait/member-constraints/apply_member_constraint-no-req-eq.rs
index 3aa52fe2644..e9af42b30e9 100644
--- a/tests/ui/impl-trait/member-constraints/apply_member_constraint-no-req-eq.rs
+++ b/tests/ui/impl-trait/member-constraints/apply_member_constraint-no-req-eq.rs
@@ -1,5 +1,7 @@
 //@ check-pass
-// FIXME(-Znext-solver): enable this test
+//@ revisions: current next
+//@ ignore-compare-mode-next-solver (explicit revisions)
+//@[next] compile-flags: -Znext-solver
 
 trait Id {
     type This;
diff --git a/tests/ui/impl-trait/member-constraints/nested-impl-trait-pass.rs b/tests/ui/impl-trait/member-constraints/nested-impl-trait-pass.rs
index 6860fc5e6a5..878b8746bfa 100644
--- a/tests/ui/impl-trait/member-constraints/nested-impl-trait-pass.rs
+++ b/tests/ui/impl-trait/member-constraints/nested-impl-trait-pass.rs
@@ -1,7 +1,9 @@
 // Nested impl-traits can impose different member constraints on the same region variable.
 
 //@ check-pass
-// FIXME(-Znext-solver): enable this test
+//@ revisions: current next
+//@ ignore-compare-mode-next-solver (explicit revisions)
+//@[next] compile-flags: -Znext-solver
 
 trait Cap<'a> {}
 impl<T> Cap<'_> for T {}
diff --git a/tests/ui/impl-trait/nested-rpit-hrtb.rs b/tests/ui/impl-trait/nested-rpit-hrtb.rs
index 11d79bcff73..f4ff13d6c20 100644
--- a/tests/ui/impl-trait/nested-rpit-hrtb.rs
+++ b/tests/ui/impl-trait/nested-rpit-hrtb.rs
@@ -48,6 +48,7 @@ fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc = im
 // This should resolve.
 fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}
 //~^ ERROR implementation of `Bar` is not general enough
+//~| ERROR lifetime may not live long enough
 
 // This should resolve.
 fn two_htrb_trait_param() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Qux<'b>> {}
diff --git a/tests/ui/impl-trait/nested-rpit-hrtb.stderr b/tests/ui/impl-trait/nested-rpit-hrtb.stderr
index 2e95ef370c7..93cd7bd788f 100644
--- a/tests/ui/impl-trait/nested-rpit-hrtb.stderr
+++ b/tests/ui/impl-trait/nested-rpit-hrtb.stderr
@@ -1,5 +1,5 @@
 error[E0261]: use of undeclared lifetime name `'b`
-  --> $DIR/nested-rpit-hrtb.rs:56:77
+  --> $DIR/nested-rpit-hrtb.rs:57:77
    |
 LL | fn two_htrb_outlives() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Sized + 'b> {}
    |                                                                             ^^ undeclared lifetime
@@ -15,7 +15,7 @@ LL | fn two_htrb_outlives<'b>() -> impl for<'a> Foo<'a, Assoc = impl for<'b> Siz
    |                     ++++
 
 error[E0261]: use of undeclared lifetime name `'b`
-  --> $DIR/nested-rpit-hrtb.rs:64:82
+  --> $DIR/nested-rpit-hrtb.rs:65:82
    |
 LL | fn two_htrb_outlives_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Sized + 'b> {}
    |                                                                                  ^^ undeclared lifetime
@@ -87,6 +87,12 @@ LL | fn one_hrtb_mention_fn_trait_param_uses<'b>() -> impl for<'a> Bar<'a, Assoc
            but trait `Qux<'_>` is implemented for `()`
    = help: for that trait implementation, expected `()`, found `&'a ()`
 
+error: lifetime may not live long enough
+  --> $DIR/nested-rpit-hrtb.rs:49:93
+   |
+LL | fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc = impl Sized + 'b> {}
+   |                                      -- lifetime `'b` defined here                          ^^ opaque type requires that `'b` must outlive `'static`
+
 error: implementation of `Bar` is not general enough
   --> $DIR/nested-rpit-hrtb.rs:49:93
    |
@@ -97,7 +103,7 @@ LL | fn one_hrtb_mention_fn_outlives_uses<'b>() -> impl for<'a> Bar<'a, Assoc =
    = note: ...but it actually implements `Bar<'0>`, for some specific lifetime `'0`
 
 error[E0277]: the trait bound `for<'a, 'b> &'a (): Qux<'b>` is not satisfied
-  --> $DIR/nested-rpit-hrtb.rs:60:64
+  --> $DIR/nested-rpit-hrtb.rs:61:64
    |
 LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b> Qux<'b>> {}
    |                                                                ^^^^^^^^^^^^^^^^^^^^ the trait `for<'a, 'b> Qux<'b>` is not implemented for `&'a ()`
@@ -106,7 +112,7 @@ LL | fn two_htrb_trait_param_uses() -> impl for<'a> Bar<'a, Assoc = impl for<'b>
            but trait `Qux<'_>` is implemented for `()`
    = help: for that trait implementation, expected `()`, found `&'a ()`
 
-error: aborting due to 9 previous errors
+error: aborting due to 10 previous errors
 
 Some errors have detailed explanations: E0261, E0277, E0657.
 For more information about an error, try `rustc --explain E0261`.
diff --git a/tests/ui/impl-trait/no-anonymize-regions.rs b/tests/ui/impl-trait/no-anonymize-regions.rs
index 4f7f7c0641c..a89c9e05a34 100644
--- a/tests/ui/impl-trait/no-anonymize-regions.rs
+++ b/tests/ui/impl-trait/no-anonymize-regions.rs
@@ -1,5 +1,7 @@
 //@ check-pass
-// FIXME(-Znext-solver): enable this test
+//@ revisions: current next
+//@ ignore-compare-mode-next-solver (explicit revisions)
+//@[next] compile-flags: -Znext-solver
 
 // A regression test for an error in `redis` while working on #139587.
 //
diff --git a/tests/ui/impl-trait/non-defining-uses/as-projection-term.next.stderr b/tests/ui/impl-trait/non-defining-uses/as-projection-term.next.stderr
index 08c8365b180..96e242d5d48 100644
--- a/tests/ui/impl-trait/non-defining-uses/as-projection-term.next.stderr
+++ b/tests/ui/impl-trait/non-defining-uses/as-projection-term.next.stderr
@@ -1,12 +1,8 @@
-error[E0792]: expected generic lifetime parameter, found `'_`
+error: non-defining use of `impl Sized + '_` in the defining scope
   --> $DIR/as-projection-term.rs:14:19
    |
-LL | fn recur<'a>() -> impl Sized + 'a {
-   |                                -- this generic parameter must be used with a generic lifetime parameter
-...
 LL |     prove_proj(|| recur());
    |                   ^^^^^^^
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/impl-trait/non-defining-uses/as-projection-term.rs b/tests/ui/impl-trait/non-defining-uses/as-projection-term.rs
index 4c5adc7a00a..f0cf333b6a1 100644
--- a/tests/ui/impl-trait/non-defining-uses/as-projection-term.rs
+++ b/tests/ui/impl-trait/non-defining-uses/as-projection-term.rs
@@ -12,6 +12,6 @@ fn recur<'a>() -> impl Sized + 'a {
     // inference variable at this point, we unify it with `opaque<'1>` and
     // end up ignoring that defining use as the hidden type is equal to its key.
     prove_proj(|| recur());
-    //[next]~^ ERROR expected generic lifetime parameter, found `'_`
+    //[next]~^ ERROR non-defining use of `impl Sized + '_` in the defining scope
 }
 fn main() {}
diff --git a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs
index 80a4ab35527..5fa13152653 100644
--- a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs
+++ b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs
@@ -31,6 +31,7 @@ mod capture_tait {
     #[define_opaque(Opq2)]
     fn test() -> Opq2 {}
     //~^ ERROR hidden type for `capture_tait::Opq0` captures lifetime that does not appear in bounds
+    //~| ERROR expected generic lifetime parameter, found `'a`
 }
 
 mod capture_tait_complex_pass {
@@ -52,7 +53,8 @@ mod capture_tait_complex_fail {
     type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>;
     #[define_opaque(Opq2)]
     fn test() -> Opq2 {}
-    //~^ ERROR hidden type for `capture_tait_complex_fail::Opq0<'a>` captures lifetime that does not appear in bounds
+    //~^ ERROR expected generic lifetime parameter, found `'a`
+    //~| ERROR expected generic lifetime parameter, found `'a`
 }
 
 // non-defining use because 'static is used.
diff --git a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr
index 665b9a91696..8e2c02f15c5 100644
--- a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr
+++ b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr
@@ -16,6 +16,15 @@ LL |     fn test() -> impl for<'a> Trait<'a, Ty = impl Sized> {}
    |                           |                  opaque type defined here
    |                           hidden type `&'a ()` captures the lifetime `'a` as defined here
 
+error[E0792]: expected generic lifetime parameter, found `'a`
+  --> $DIR/higher-ranked-regions-basic.rs:32:23
+   |
+LL |     type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0>;
+   |               -- this generic parameter must be used with a generic lifetime parameter
+...
+LL |     fn test() -> Opq2 {}
+   |                       ^^
+
 error[E0700]: hidden type for `capture_tait::Opq0` captures lifetime that does not appear in bounds
   --> $DIR/higher-ranked-regions-basic.rs:32:23
    |
@@ -28,7 +37,7 @@ LL |     fn test() -> Opq2 {}
    |                       ^^
 
 error[E0792]: expected generic lifetime parameter, found `'a`
-  --> $DIR/higher-ranked-regions-basic.rs:42:23
+  --> $DIR/higher-ranked-regions-basic.rs:43:23
    |
 LL |     type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'b>>; // <- Note 'b
    |               -- this generic parameter must be used with a generic lifetime parameter
@@ -37,7 +46,7 @@ LL |     fn test() -> Opq2 {}
    |                       ^^
 
 error[E0792]: expected generic lifetime parameter, found `'b`
-  --> $DIR/higher-ranked-regions-basic.rs:42:23
+  --> $DIR/higher-ranked-regions-basic.rs:43:23
    |
 LL |     type Opq0<'a> = impl Sized;
    |               -- this generic parameter must be used with a generic lifetime parameter
@@ -45,19 +54,26 @@ LL |     type Opq0<'a> = impl Sized;
 LL |     fn test() -> Opq2 {}
    |                       ^^
 
-error[E0700]: hidden type for `capture_tait_complex_fail::Opq0<'a>` captures lifetime that does not appear in bounds
-  --> $DIR/higher-ranked-regions-basic.rs:54:23
+error[E0792]: expected generic lifetime parameter, found `'a`
+  --> $DIR/higher-ranked-regions-basic.rs:55:23
    |
-LL |     type Opq0<'a> = impl Sized;
-   |                     ---------- opaque type defined here
 LL |     type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'a>>; // <- Note 'a
-   |                              -- hidden type `&'b ()` captures the lifetime `'b` as defined here
+   |               -- this generic parameter must be used with a generic lifetime parameter
+...
+LL |     fn test() -> Opq2 {}
+   |                       ^^
+
+error[E0792]: expected generic lifetime parameter, found `'a`
+  --> $DIR/higher-ranked-regions-basic.rs:55:23
+   |
+LL |     type Opq0<'a> = impl Sized;
+   |               -- this generic parameter must be used with a generic lifetime parameter
 ...
 LL |     fn test() -> Opq2 {}
    |                       ^^
 
 error[E0792]: expected generic lifetime parameter, found `'a`
-  --> $DIR/higher-ranked-regions-basic.rs:63:65
+  --> $DIR/higher-ranked-regions-basic.rs:65:65
    |
 LL |     type Opq0<'a, 'b> = impl Sized;
    |               -- this generic parameter must be used with a generic lifetime parameter
@@ -66,7 +82,7 @@ LL |     fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'static>> {}
    |                                                                 ^^
 
 error[E0792]: expected generic lifetime parameter, found `'a`
-  --> $DIR/higher-ranked-regions-basic.rs:72:60
+  --> $DIR/higher-ranked-regions-basic.rs:74:60
    |
 LL |     type Opq0<'a, 'b> = impl Sized;
    |               -- this generic parameter must be used with a generic lifetime parameter
@@ -75,7 +91,7 @@ LL |     fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'a>> {}
    |                                                            ^^
 
 error[E0792]: expected generic lifetime parameter, found `'a`
-  --> $DIR/higher-ranked-regions-basic.rs:82:23
+  --> $DIR/higher-ranked-regions-basic.rs:84:23
    |
 LL |     type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'a, 'b>>;
    |               -- this generic parameter must be used with a generic lifetime parameter
@@ -84,7 +100,7 @@ LL |     fn test() -> Opq2 {}
    |                       ^^
 
 error[E0792]: expected generic lifetime parameter, found `'a`
-  --> $DIR/higher-ranked-regions-basic.rs:82:23
+  --> $DIR/higher-ranked-regions-basic.rs:84:23
    |
 LL |     type Opq0<'a, 'b> = impl Sized;
    |               -- this generic parameter must be used with a generic lifetime parameter
@@ -92,7 +108,7 @@ LL |     type Opq0<'a, 'b> = impl Sized;
 LL |     fn test() -> Opq2 {}
    |                       ^^
 
-error: aborting due to 10 previous errors
+error: aborting due to 12 previous errors
 
 Some errors have detailed explanations: E0700, E0792.
 For more information about an error, try `rustc --explain E0700`.
diff --git a/tests/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs b/tests/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs
index c24672816ac..eb9b376686a 100644
--- a/tests/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs
+++ b/tests/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs
@@ -18,7 +18,7 @@ mod bav {
     impl Bar for i32 {}
 
     fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
-        val.use_self() //~ ERROR cannot return value referencing function parameter
+        val.use_self() //~ ERROR cannot return value referencing function parameter `val`
     }
 }
 
diff --git a/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr
index 3a1f685f16b..9a3cfa9987a 100644
--- a/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr
+++ b/tests/ui/suggestions/lifetimes/explicit-lifetime-suggestion-in-proper-span-issue-121267.stderr
@@ -8,7 +8,7 @@ LL | |
 LL | |         .filter_map(|_| foo(src))
    | |_________________________________^
    |
-   = note: hidden type `FilterMap<std::slice::Iter<'static, i32>, {closure@$DIR/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs:9:21: 9:24}>` captures lifetime `'_`
+   = note: hidden type `FilterMap<std::slice::Iter<'_, i32>, {closure@$DIR/explicit-lifetime-suggestion-in-proper-span-issue-121267.rs:9:21: 9:24}>` captures lifetime `'_`
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs
index 902d6ca57e6..5c6ad2cc725 100644
--- a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs
+++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs
@@ -8,7 +8,7 @@ fn get_one<'a>(a: *mut &'a str) -> impl IntoIterator<Item = Opaque<'a>> {
         Some(a)
     } else {
         None::<Opaque<'static>>
-        //~^ ERROR hidden type for `Opaque<'static>` captures lifetime that does not appear in bounds
+        //~^ ERROR expected generic lifetime parameter, found `'static`
     }
 }
 
diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr
index 562ab4168b5..2cb8f03235a 100644
--- a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr
+++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr
@@ -1,15 +1,12 @@
-error[E0700]: hidden type for `Opaque<'static>` captures lifetime that does not appear in bounds
+error[E0792]: expected generic lifetime parameter, found `'static`
   --> $DIR/different_args_considered_equal2.rs:10:9
    |
 LL | pub type Opaque<'a> = impl Sized;
-   |                       ---------- opaque type defined here
-...
-LL | fn get_one<'a>(a: *mut &'a str) -> impl IntoIterator<Item = Opaque<'a>> {
-   |            -- hidden type `*mut &'a str` captures the lifetime `'a` as defined here
+   |                 -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type
 ...
 LL |         None::<Opaque<'static>>
    |         ^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0700`.
+For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr
index 4a5360c9922..43e887f36c5 100644
--- a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr
+++ b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr
@@ -1,15 +1,12 @@
-error[E0700]: hidden type for `Opaque<'x>` captures lifetime that does not appear in bounds
+error[E0792]: expected generic lifetime parameter, found `'_`
   --> $DIR/generic-not-strictly-equal.rs:34:5
    |
 LL | type Opaque<'a> = impl Copy + Captures<'a>;
-   |                   ------------------------ opaque type defined here
-...
-LL | fn test<'x>(_: Opaque<'x>) {
-   |         -- hidden type `&'x u8` captures the lifetime `'x` as defined here
+   |             -- this generic parameter must be used with a generic lifetime parameter
 ...
 LL |     relate(opaque, hidden); // defining use: Opaque<'?1> := u8
    |     ^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0700`.
+For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs
index c1059e3da33..42f363d0e57 100644
--- a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs
+++ b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs
@@ -32,8 +32,7 @@ fn test<'x>(_: Opaque<'x>) {
 
     ensure_outlives::<'x>(opaque); // outlives constraint: '?1: 'x
     relate(opaque, hidden); // defining use: Opaque<'?1> := u8
-    //[basic]~^ ERROR expected generic lifetime parameter, found `'_`
-    //[member_constraints]~^^ ERROR captures lifetime that does not appear in bounds
+    //~^ ERROR expected generic lifetime parameter, found `'_`
 }
 
 fn main() {}
diff --git a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.rs b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.rs
index baeba1d3de6..013651e8775 100644
--- a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.rs
+++ b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.rs
@@ -9,7 +9,7 @@ impl Foo for () {
     type Assoc<'a, 'b> = impl Sized;
     fn bar<'a: 'a, 'b: 'b>(x: &'a ()) -> Self::Assoc<'a, 'b> {
         let closure = |x: &'a ()| -> Self::Assoc<'b, 'a> { x };
-        //~^ ERROR `<() as Foo>::Assoc<'b, 'a>` captures lifetime that does not appear in bounds
+        //~^ ERROR expected generic lifetime parameter, found `'_`
         x
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.stderr b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.stderr
index a7d3e7f0be4..f399520e7fd 100644
--- a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.stderr
+++ b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound.stderr
@@ -1,13 +1,12 @@
-error[E0700]: hidden type for `<() as Foo>::Assoc<'b, 'a>` captures lifetime that does not appear in bounds
+error[E0792]: expected generic lifetime parameter, found `'_`
   --> $DIR/in-assoc-ty-early-bound.rs:11:60
    |
 LL |     type Assoc<'a, 'b> = impl Sized;
-   |                          ---------- opaque type defined here
+   |                -- this generic parameter must be used with a generic lifetime parameter
 LL |     fn bar<'a: 'a, 'b: 'b>(x: &'a ()) -> Self::Assoc<'a, 'b> {
-   |            -- hidden type `&'a ()` captures the lifetime `'a` as defined here
 LL |         let closure = |x: &'a ()| -> Self::Assoc<'b, 'a> { x };
    |                                                            ^
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0700`.
+For more information about this error, try `rustc --explain E0792`.
diff --git a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.rs b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.rs
index 92c8a8f3216..21df53c43d7 100644
--- a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.rs
+++ b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.rs
@@ -13,7 +13,7 @@ impl Foo for () {
     {
         let _ = |x: &'a ()| {
             let _: Self::Assoc<'a> = x;
-            //~^ ERROR `<() as Foo>::Assoc<'a>` captures lifetime that does not appear in bound
+            //~^ ERROR expected generic lifetime parameter, found `'_`
         };
     }
 }
diff --git a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.stderr b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.stderr
index 7ce4517fb1e..aaed03e739b 100644
--- a/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.stderr
+++ b/tests/ui/type-alias-impl-trait/in-assoc-ty-early-bound2.stderr
@@ -1,14 +1,12 @@
-error[E0700]: hidden type for `<() as Foo>::Assoc<'a>` captures lifetime that does not appear in bounds
+error[E0792]: expected generic lifetime parameter, found `'_`
   --> $DIR/in-assoc-ty-early-bound2.rs:15:20
    |
 LL |     type Assoc<'a> = impl Sized;
-   |                      ---------- opaque type defined here
-LL |     fn bar<'a: 'a>()
-   |            -- hidden type `&'a ()` captures the lifetime `'a` as defined here
+   |                -- this generic parameter must be used with a generic lifetime parameter
 ...
 LL |             let _: Self::Assoc<'a> = x;
    |                    ^^^^^^^^^^^^^^^
 
 error: aborting due to 1 previous error
 
-For more information about this error, try `rustc --explain E0700`.
+For more information about this error, try `rustc --explain E0792`.