Skip to content

Commit 9e0e4c3

Browse files
committed
Added diagnostic for pin! macro in addition to Box::pin if Unpin isn't implemented
1 parent 59a05ad commit 9e0e4c3

8 files changed

+55
-7
lines changed

library/core/src/marker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
823823
/// [`pin` module]: crate::pin
824824
#[stable(feature = "pin", since = "1.33.0")]
825825
#[rustc_on_unimplemented(
826-
note = "consider using `Box::pin`",
826+
note = "consider using the `pin!` macro\nconsider using `Box::pin` if you need to access the pinned value outside of the current scope",
827827
message = "`{Self}` cannot be unpinned"
828828
)]
829829
#[lang = "unpin"]

tests/ui/async-await/pin-needed-to-poll-2.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ LL | Pin::new(&mut self.sleep).poll(cx)
66
| |
77
| required by a bound introduced by this call
88
|
9-
= note: consider using `Box::pin`
9+
= note: consider using the `pin!` macro
10+
consider using `Box::pin` if you need to access the pinned value outside of the current scope
1011
note: required because it appears within the type `Sleep`
1112
--> $DIR/pin-needed-to-poll-2.rs:8:8
1213
|

tests/ui/generator/static-not-unpin.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ LL | assert_unpin(generator);
66
| |
77
| required by a bound introduced by this call
88
|
9-
= note: consider using `Box::pin`
9+
= note: consider using the `pin!` macro
10+
consider using `Box::pin` if you need to access the pinned value outside of the current scope
1011
note: required by a bound in `assert_unpin`
1112
--> $DIR/static-not-unpin.rs:7:20
1213
|

tests/ui/suggestions/expected-boxed-future-isnt-pinned.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ LL | Pin::new(x)
5050
| |
5151
| required by a bound introduced by this call
5252
|
53-
= note: consider using `Box::pin`
53+
= note: consider using the `pin!` macro
54+
consider using `Box::pin` if you need to access the pinned value outside of the current scope
5455
note: required by a bound in `Pin::<P>::new`
5556
--> $SRC_DIR/core/src/pin.rs:LL:COL
5657

@@ -62,7 +63,8 @@ LL | Pin::new(Box::new(x))
6263
| |
6364
| required by a bound introduced by this call
6465
|
65-
= note: consider using `Box::pin`
66+
= note: consider using the `pin!` macro
67+
consider using `Box::pin` if you need to access the pinned value outside of the current scope
6668
note: required by a bound in `Pin::<P>::new`
6769
--> $SRC_DIR/core/src/pin.rs:LL:COL
6870

tests/ui/suggestions/issue-84973-blacklist.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ LL | f_unpin(static || { yield; });
3838
| |
3939
| required by a bound introduced by this call
4040
|
41-
= note: consider using `Box::pin`
41+
= note: consider using the `pin!` macro
42+
consider using `Box::pin` if you need to access the pinned value outside of the current scope
4243
note: required by a bound in `f_unpin`
4344
--> $DIR/issue-84973-blacklist.rs:8:15
4445
|
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use std::pin::Pin;
2+
use std::marker::PhantomPinned;
3+
4+
#[derive(Debug)]
5+
struct Test {
6+
_marker: PhantomPinned,
7+
}
8+
impl Test {
9+
fn new() -> Self {
10+
Test {
11+
_marker: PhantomPinned, // This makes our type `!Unpin`
12+
}
13+
}
14+
}
15+
16+
fn dummy(_: &mut Test) {}
17+
18+
pub fn main() {
19+
let mut test1 = Test::new();
20+
let mut test1 = unsafe { Pin::new_unchecked(&mut test1) };
21+
22+
dummy(test1.get_mut()); //~ ERROR E0277
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: `PhantomPinned` cannot be unpinned
2+
--> $DIR/suggest-pin-macro.rs:22:17
3+
|
4+
LL | dummy(test1.get_mut());
5+
| ^^^^^^^ within `Test`, the trait `Unpin` is not implemented for `PhantomPinned`
6+
|
7+
= note: consider using the `pin!` macro
8+
consider using `Box::pin` if you need to access the pinned value outside of the current scope
9+
note: required because it appears within the type `Test`
10+
--> $DIR/suggest-pin-macro.rs:5:8
11+
|
12+
LL | struct Test {
13+
| ^^^^
14+
note: required by a bound in `Pin::<&'a mut T>::get_mut`
15+
--> $SRC_DIR/core/src/pin.rs:LL:COL
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.

tests/ui/typeck/issue-90164.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ LL | copy(r, w);
66
| |
77
| required by a bound introduced by this call
88
|
9-
= note: consider using `Box::pin`
9+
= note: consider using the `pin!` macro
10+
consider using `Box::pin` if you need to access the pinned value outside of the current scope
1011
note: required by a bound in `copy`
1112
--> $DIR/issue-90164.rs:1:12
1213
|

0 commit comments

Comments
 (0)