-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UI test for Pin PartialEq unsoundness
- Loading branch information
1 parent
dfcf764
commit 6996ae1
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Pin's PartialEq implementation allowed to access the pointer allowing for | ||
// unsoundness by using Rc::get_mut to move value within Rc. | ||
// See https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73 for more details. | ||
|
||
use std::ops::Deref; | ||
use std::pin::Pin; | ||
use std::rc::Rc; | ||
|
||
struct Apple; | ||
|
||
impl Deref for Apple { | ||
type Target = Apple; | ||
fn deref(&self) -> &Apple { | ||
&Apple | ||
} | ||
} | ||
|
||
impl PartialEq<Rc<Apple>> for Apple { | ||
fn eq(&self, _rc: &Rc<Apple>) -> bool { | ||
unreachable!() | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = Pin::new(Apple) == Rc::pin(Apple); | ||
//~^ ERROR type mismatch resolving | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
error[E0271]: type mismatch resolving `<std::rc::Rc<Apple> as std::ops::Deref>::Target == std::rc::Rc<Apple>` | ||
--> $DIR/issue-67039-unsound-pin-partialeq.rs:25:29 | ||
| | ||
LL | let _ = Pin::new(Apple) == Rc::pin(Apple); | ||
| ^^ expected struct `Apple`, found struct `std::rc::Rc` | ||
| | ||
= note: expected type `Apple` | ||
found struct `std::rc::Rc<Apple>` | ||
= note: required because of the requirements on the impl of `std::cmp::PartialEq<std::pin::Pin<std::rc::Rc<Apple>>>` for `std::pin::Pin<Apple>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0271`. |