Skip to content

Commit 6996ae1

Browse files
Add UI test for Pin PartialEq unsoundness
1 parent dfcf764 commit 6996ae1

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Pin's PartialEq implementation allowed to access the pointer allowing for
2+
// unsoundness by using Rc::get_mut to move value within Rc.
3+
// See https://internals.rust-lang.org/t/unsoundness-in-pin/11311/73 for more details.
4+
5+
use std::ops::Deref;
6+
use std::pin::Pin;
7+
use std::rc::Rc;
8+
9+
struct Apple;
10+
11+
impl Deref for Apple {
12+
type Target = Apple;
13+
fn deref(&self) -> &Apple {
14+
&Apple
15+
}
16+
}
17+
18+
impl PartialEq<Rc<Apple>> for Apple {
19+
fn eq(&self, _rc: &Rc<Apple>) -> bool {
20+
unreachable!()
21+
}
22+
}
23+
24+
fn main() {
25+
let _ = Pin::new(Apple) == Rc::pin(Apple);
26+
//~^ ERROR type mismatch resolving
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0271]: type mismatch resolving `<std::rc::Rc<Apple> as std::ops::Deref>::Target == std::rc::Rc<Apple>`
2+
--> $DIR/issue-67039-unsound-pin-partialeq.rs:25:29
3+
|
4+
LL | let _ = Pin::new(Apple) == Rc::pin(Apple);
5+
| ^^ expected struct `Apple`, found struct `std::rc::Rc`
6+
|
7+
= note: expected type `Apple`
8+
found struct `std::rc::Rc<Apple>`
9+
= 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>`
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)