Skip to content

Commit

Permalink
Add UI test for Pin PartialEq unsoundness
Browse files Browse the repository at this point in the history
  • Loading branch information
KamilaBorowska committed Dec 5, 2019
1 parent dfcf764 commit 6996ae1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/test/ui/issues/issue-67039-unsound-pin-partialeq.rs
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 src/test/ui/issues/issue-67039-unsound-pin-partialeq.stderr
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`.

0 comments on commit 6996ae1

Please sign in to comment.