Closed kyleguarco closed 3 months ago
This is behaving as intended. There are two ways this could be UB, https://github.com/rust-lang/unsafe-code-guidelines/issues/188 and by foo
reaching the end of its lifetime. However, current MIR generation makes foo
live until the end of its scope. This is not a guarantee, this program might become UB in future rustc versions, and then Miri will detect it as such.
But for now, there's no bug here.
This unique case of UB was discussed in the Rust Community Discord. Here's a link to the message that started the discussion.
This strip of code causes UB when used on a non-
Copy
type:miri
does not complain about dereferencing a moved pointer (movingfoo
tobar
) despitetest
still holding reference&foo
.Might be related to (or a duplicate of) rust-lang/unsafe-code-guidelines#188?