about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorEsteban Kuber <esteban@kuber.com.ar>2021-10-10 10:37:57 +0000
committerEsteban Kuber <esteban@kuber.com.ar>2021-12-10 03:08:22 +0000
commitd10fe26f39983c782f1a37a447f2c10c2ef561ba (patch)
tree9cf5786605414d8b28f45f43321674c00f49804b /src/test
parente6b883c74f49f32cb5d1cbad3457f2b8805a4a38 (diff)
downloadrust-d10fe26f39983c782f1a37a447f2c10c2ef561ba.tar.gz
rust-d10fe26f39983c782f1a37a447f2c10c2ef561ba.zip
Point at capture points for non-`'static` reference crossing a `yield` point
```
error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
  --> $DIR/issue-72312.rs:10:24
   |
LL |     pub async fn start(&self) {
   |                        ^^^^^ this data with an anonymous lifetime `'_`...
...
LL |         require_static(async move {
   |         -------------- ...is required to live as long as `'static` here...
LL |             &self;
   |             ----- ...and is captured here
   |
note: `'static` lifetime requirement introduced by this trait bound
  --> $DIR/issue-72312.rs:2:22
   |
LL | fn require_static<T: 'static>(val: T) -> T {
   |                      ^^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0759`.
```

Fix #72312.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/async-await/issues/issue-62097.stderr18
-rw-r--r--src/test/ui/async-await/issues/issue-72312.rs19
-rw-r--r--src/test/ui/async-await/issues/issue-72312.stderr20
-rw-r--r--src/test/ui/traits/trait-upcasting/type-checking-test-4.rs18
-rw-r--r--src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr48
5 files changed, 116 insertions, 7 deletions
diff --git a/src/test/ui/async-await/issues/issue-62097.stderr b/src/test/ui/async-await/issues/issue-62097.stderr
index 56a28d904b9..bb329a4a0c2 100644
--- a/src/test/ui/async-await/issues/issue-62097.stderr
+++ b/src/test/ui/async-await/issues/issue-62097.stderr
@@ -2,12 +2,20 @@ error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'
   --> $DIR/issue-62097.rs:12:31
    |
 LL |     pub async fn run_dummy_fn(&self) {
-   |                               ^^^^^
-   |                               |
-   |                               this data with an anonymous lifetime `'_`...
-   |                               ...is captured here...
+   |                               ^^^^^ this data with an anonymous lifetime `'_`...
 LL |         foo(|| self.bar()).await;
-   |         --- ...and is required to live as long as `'static` here
+   |         --- ...is required to live as long as `'static` here...
+   |
+note: ...and is captured here
+  --> $DIR/issue-62097.rs:13:9
+   |
+LL |         foo(|| self.bar()).await;
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^
+note: `'static` lifetime requirement introduced by this trait bound
+  --> $DIR/issue-62097.rs:4:19
+   |
+LL |     F: FnOnce() + 'static
+   |                   ^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/async-await/issues/issue-72312.rs b/src/test/ui/async-await/issues/issue-72312.rs
new file mode 100644
index 00000000000..d33685e02f1
--- /dev/null
+++ b/src/test/ui/async-await/issues/issue-72312.rs
@@ -0,0 +1,19 @@
+// edition:2018
+fn require_static<T: 'static>(val: T) -> T {
+    //~^ NOTE 'static` lifetime requirement introduced by this trait bound
+    val
+}
+
+struct Problem;
+
+impl Problem {
+    pub async fn start(&self) { //~ ERROR E0759
+        //~^ NOTE this data with an anonymous lifetime `'_`
+        //~| NOTE in this expansion of desugaring of `async` block or function
+        require_static(async move { //~ NOTE ...is required to live as long as `'static` here
+            &self; //~ NOTE ...and is captured here
+        });
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/async-await/issues/issue-72312.stderr b/src/test/ui/async-await/issues/issue-72312.stderr
new file mode 100644
index 00000000000..ee5ee6f0f93
--- /dev/null
+++ b/src/test/ui/async-await/issues/issue-72312.stderr
@@ -0,0 +1,20 @@
+error[E0759]: `self` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement
+  --> $DIR/issue-72312.rs:10:24
+   |
+LL |     pub async fn start(&self) {
+   |                        ^^^^^ this data with an anonymous lifetime `'_`...
+...
+LL |         require_static(async move {
+   |         -------------- ...is required to live as long as `'static` here...
+LL |             &self;
+   |             ----- ...and is captured here
+   |
+note: `'static` lifetime requirement introduced by this trait bound
+  --> $DIR/issue-72312.rs:2:22
+   |
+LL | fn require_static<T: 'static>(val: T) -> T {
+   |                      ^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0759`.
diff --git a/src/test/ui/traits/trait-upcasting/type-checking-test-4.rs b/src/test/ui/traits/trait-upcasting/type-checking-test-4.rs
index 9b27fd46f7a..95698fd1e1a 100644
--- a/src/test/ui/traits/trait-upcasting/type-checking-test-4.rs
+++ b/src/test/ui/traits/trait-upcasting/type-checking-test-4.rs
@@ -29,4 +29,22 @@ fn test_wrong3<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
     y.get_b() // ERROR
 }
 
+fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
+    <_ as Bar>::get_b(x) // ERROR
+    //~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+}
+
+fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
+    <_ as Bar<'_, '_>>::get_b(x) // ERROR
+    //~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+}
+
+fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
+    let y = x as &dyn Bar<'_, '_>;
+    //~^ ERROR `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+    y.get_b(); // ERROR
+    let z = y;
+    z.get_b() // ERROR
+}
+
 fn main() {}
diff --git a/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr b/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr
index 4967f3dc2c8..04560ea4e29 100644
--- a/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr
+++ b/src/test/ui/traits/trait-upcasting/type-checking-test-4.stderr
@@ -39,9 +39,53 @@ LL |     let y = x as &dyn Bar<'_, '_>;
    |             ...is captured here...
 LL |
 LL |     y.get_b() // ERROR
-   |     --------- ...and is required to live as long as `'static` here
+   |     --------- ...is required to live as long as `'static` here...
+   |
+note: ...and is captured here too
+  --> $DIR/type-checking-test-4.rs:29:5
+   |
+LL |     y.get_b() // ERROR
+   |     ^
+
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+  --> $DIR/type-checking-test-4.rs:33:5
+   |
+LL | fn test_wrong4<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
+   |                       ------------ this data with lifetime `'a`...
+LL |     <_ as Bar>::get_b(x) // ERROR
+   |     ^^^^^^^^^^^^^^^^^ ...is captured here, requiring it to live as long as `'static`
+
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+  --> $DIR/type-checking-test-4.rs:38:15
+   |
+LL | fn test_wrong5<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
+   |                       ------------ this data with lifetime `'a`...
+LL |     <_ as Bar<'_, '_>>::get_b(x) // ERROR
+   |     ----------^^---------------- ...is captured and required to live as long as `'static` here
+
+error[E0759]: `x` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
+  --> $DIR/type-checking-test-4.rs:43:27
+   |
+LL | fn test_wrong6<'a>(x: &dyn Foo<'a>) -> Option<&'static u32> {
+   |                       ------------ this data with lifetime `'a`...
+LL |     let y = x as &dyn Bar<'_, '_>;
+   |             -             ^^
+   |             |
+   |             ...is captured here...
+LL |
+LL |     y.get_b(); // ERROR
+   |     - ...and is captured here too
+LL |     let z = y;
+LL |     z.get_b() // ERROR
+   |     --------- ...is required to live as long as `'static` here...
+   |
+note: ...and is captured here too
+  --> $DIR/type-checking-test-4.rs:47:5
+   |
+LL |     z.get_b() // ERROR
+   |     ^
 
-error: aborting due to 3 previous errors
+error: aborting due to 6 previous errors
 
 Some errors have detailed explanations: E0308, E0759.
 For more information about an error, try `rustc --explain E0308`.