about summary refs log tree commit diff
path: root/tests/ui/impl-trait/precise-capturing
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-07-11 14:00:54 -0400
committerMichael Goulet <michael@errs.io>2024-07-11 14:01:29 -0400
commit03bee1e1e56b10a3bff0e8eb524faacdb745cabc (patch)
tree7dce501a57c92e79f22ffd328d8cf62428125342 /tests/ui/impl-trait/precise-capturing
parent0c81f94b9a6207fb1fc080caa83584dea2d71fc6 (diff)
downloadrust-03bee1e1e56b10a3bff0e8eb524faacdb745cabc.tar.gz
rust-03bee1e1e56b10a3bff0e8eb524faacdb745cabc.zip
Suggest using precise capturing for hidden type that captures region
Diffstat (limited to 'tests/ui/impl-trait/precise-capturing')
-rw-r--r--tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr6
-rw-r--r--tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs30
-rw-r--r--tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr67
3 files changed, 100 insertions, 3 deletions
diff --git a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr
index 6544837ba83..979c0ca6d7b 100644
--- a/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr
+++ b/tests/ui/impl-trait/precise-capturing/forgot-to-capture-lifetime.stderr
@@ -16,10 +16,10 @@ LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<> { x }
    |                       |                 opaque type defined here
    |                       hidden type `&'a ()` captures the lifetime `'a` as defined here
    |
-help: to declare that `impl Sized` captures `'a`, you can add an explicit `'a` lifetime bound
+help: add `'a` to the `use<...>` bound to explicitly capture it
    |
-LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<> + 'a { x }
-   |                                                            ++++
+LL | fn lifetime_in_hidden<'a>(x: &'a ()) -> impl Sized + use<'a> { x }
+   |                                                          ++
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs
new file mode 100644
index 00000000000..e0b115b0ce4
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs
@@ -0,0 +1,30 @@
+#![feature(precise_capturing)]
+
+fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
+//~^ HELP add `'a` to the `use<...>` bound
+    x
+//~^ ERROR hidden type for
+}
+
+fn param<'a, T>(x: &'a ()) -> impl Sized + use<T> {
+//~^ HELP add `'a` to the `use<...>` bound
+    x
+//~^ ERROR hidden type for
+}
+
+fn empty<'a>(x: &'a ()) -> impl Sized + use<> {
+//~^ HELP add `'a` to the `use<...>` bound
+    x
+//~^ ERROR hidden type for
+}
+
+trait Captures<'a> {}
+impl<T> Captures<'_> for T {}
+
+fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> {
+//~^ HELP add a `use<...>` bound
+    x
+//~^ ERROR hidden type for
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr
new file mode 100644
index 00000000000..391f16d012e
--- /dev/null
+++ b/tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr
@@ -0,0 +1,67 @@
+error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
+  --> $DIR/hidden-type-suggestion.rs:5:5
+   |
+LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
+   |             --                    -------------------- opaque type defined here
+   |             |
+   |             hidden type `&'a ()` captures the lifetime `'a` as defined here
+LL |
+LL |     x
+   |     ^
+   |
+help: add `'a` to the `use<...>` bound to explicitly capture it
+   |
+LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b, 'a> {
+   |                                                      ++++
+
+error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
+  --> $DIR/hidden-type-suggestion.rs:11:5
+   |
+LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use<T> {
+   |          --                   ------------------- opaque type defined here
+   |          |
+   |          hidden type `&'a ()` captures the lifetime `'a` as defined here
+LL |
+LL |     x
+   |     ^
+   |
+help: add `'a` to the `use<...>` bound to explicitly capture it
+   |
+LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use<'a, T> {
+   |                                                +++
+
+error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
+  --> $DIR/hidden-type-suggestion.rs:17:5
+   |
+LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<> {
+   |          --                ------------------ opaque type defined here
+   |          |
+   |          hidden type `&'a ()` captures the lifetime `'a` as defined here
+LL |
+LL |     x
+   |     ^
+   |
+help: add `'a` to the `use<...>` bound to explicitly capture it
+   |
+LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<'a> {
+   |                                             ++
+
+error[E0700]: hidden type for `impl Captures<'captured>` captures lifetime that does not appear in bounds
+  --> $DIR/hidden-type-suggestion.rs:26:5
+   |
+LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> {
+   |            --                                                    ------------------------ opaque type defined here
+   |            |
+   |            hidden type `&'a ()` captures the lifetime `'a` as defined here
+LL |
+LL |     x
+   |     ^
+   |
+help: add a `use<...>` bound to explicitly capture `'a`
+   |
+LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> + use<'captured, 'a, Captured> {
+   |                                                                                           ++++++++++++++++++++++++++++++
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0700`.