←back to thread

Tree Borrows

(plf.inf.ethz.ch)
564 points zdw | 1 comments | | HN request time: 0.22s | source
Show context
wavemode ◴[] No.44511091[source]
From the paper:

> The problem with unsafe code is that it can do things like this:

    fn main() {
        let mut x = 42;
        let ptr = &mut x as *mut i32;
        let val = unsafe { write_both(&mut *ptr, &mut *ptr) };
        println!("{val}");
    }
No it can't? Using pointers to coexist multiple mutable references to the same variable is undefined behavior. Unless I'm just misunderstanding the point they're trying to make here.
replies(6): >>44511182 #>>44511227 #>>44511321 #>>44511369 #>>44511392 #>>44512352 #
seritools ◴[] No.44511182[source]
"can do things" in this case doesn't mean "is allowed to do things".

"Unsafe code allows to express the following, which is UB:"

replies(1): >>44511268 #
1. ◴[] No.44511268[source]