]> git.proxmox.com Git - rustc.git/blob - tests/ui/issues/issue-67039-unsound-pin-partialeq.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / issues / issue-67039-unsound-pin-partialeq.rs
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 }