about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2021-10-15 07:44:47 +0200
committerGitHub <noreply@github.com>2021-10-15 07:44:47 +0200
commite2c28ad1e7c5f5fc74c6472c27c8f6adfebb5b8c (patch)
tree77ed2b72260b447bcaaf197ee555fb942084f5fb /src/test
parent345d483e9573c2217f72e7a54e76ba1f99b4eb06 (diff)
parentd18502d6b347732a16dd45811d55111277802611 (diff)
downloadrust-e2c28ad1e7c5f5fc74c6472c27c8f6adfebb5b8c.tar.gz
rust-e2c28ad1e7c5f5fc74c6472c27c8f6adfebb5b8c.zip
Rollup merge of #89870 - tmandry:box-pin, r=estebank
Suggest Box::pin when Pin::new is used instead

This fixes an incorrect diagnostic.

**Based on #89390**; only the last commit is specific to this PR. "Ignore whitespace changes" also helps here.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs3
-rw-r--r--src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr17
2 files changed, 7 insertions, 13 deletions
diff --git a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs
index 89a36e89b0a..7e9c5492d1a 100644
--- a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs
+++ b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.rs
@@ -15,9 +15,6 @@ fn bar<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32>
     Box::new(x) //~ ERROR mismatched types
 }
 
-// This case is still subpar:
-// `Pin::new(x)`: store this in the heap by calling `Box::new`: `Box::new(x)`
-// Should suggest changing the code from `Pin::new` to `Box::pin`.
 fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
     Pin::new(x) //~ ERROR mismatched types
     //~^ ERROR E0277
diff --git a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr
index f0af37e0cbe..aa3175dae2e 100644
--- a/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr
+++ b/src/test/ui/suggestions/expected-boxed-future-isnt-pinned.stderr
@@ -27,23 +27,20 @@ LL |     Box::new(x)
    = help: use `Box::pin`
 
 error[E0308]: mismatched types
-  --> $DIR/expected-boxed-future-isnt-pinned.rs:22:14
+  --> $DIR/expected-boxed-future-isnt-pinned.rs:19:14
    |
 LL | fn baz<F: Future<Output=i32> + Send + 'static>(x: F) -> BoxFuture<'static, i32> {
    |        - this type parameter
 LL |     Pin::new(x)
-   |              ^ expected struct `Box`, found type parameter `F`
+   |     -------- ^ expected struct `Box`, found type parameter `F`
+   |     |
+   |     help: use `Box::pin` to pin and box this expression: `Box::pin`
    |
    = note:      expected struct `Box<dyn Future<Output = i32> + Send>`
            found type parameter `F`
-   = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html
-help: store this in the heap by calling `Box::new`
-   |
-LL |     Pin::new(Box::new(x))
-   |              +++++++++ +
 
 error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
-  --> $DIR/expected-boxed-future-isnt-pinned.rs:22:5
+  --> $DIR/expected-boxed-future-isnt-pinned.rs:19:5
    |
 LL |     Pin::new(x)
    |     ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
@@ -56,7 +53,7 @@ LL |     pub const fn new(pointer: P) -> Pin<P> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0277]: `dyn Future<Output = i32> + Send` cannot be unpinned
-  --> $DIR/expected-boxed-future-isnt-pinned.rs:27:5
+  --> $DIR/expected-boxed-future-isnt-pinned.rs:24:5
    |
 LL |     Pin::new(Box::new(x))
    |     ^^^^^^^^ the trait `Unpin` is not implemented for `dyn Future<Output = i32> + Send`
@@ -69,7 +66,7 @@ LL |     pub const fn new(pointer: P) -> Pin<P> {
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error[E0308]: mismatched types
-  --> $DIR/expected-boxed-future-isnt-pinned.rs:31:5
+  --> $DIR/expected-boxed-future-isnt-pinned.rs:28:5
    |
 LL |   fn zap() -> BoxFuture<'static, i32> {
    |               ----------------------- expected `Pin<Box<(dyn Future<Output = i32> + Send + 'static)>>` because of return type