]> git.lizzy.rs Git - rust.git/commit - src/tools/miri
Rollup merge of #92704 - 5225225:std_mem_transmute_ref_t_mut_t, r=michaelwoerister
authorMatthias Krüger <matthias.krueger@famsik.de>
Thu, 20 Jan 2022 16:10:37 +0000 (17:10 +0100)
committerGitHub <noreply@github.com>
Thu, 20 Jan 2022 16:10:37 +0000 (17:10 +0100)
commit5c10dbd85f962e4fc1ed16f4e157f00e5e7b6a8a
tree028faa77af90be6df66d96c3cba5b28c6638ef62
parent1839829f0a88a5835d3b85043d69b12d056ea191
parent36a11417fafcbfae0500884df2d4b6dd2c5e5a0f
Rollup merge of #92704 - 5225225:std_mem_transmute_ref_t_mut_t, r=michaelwoerister

Change lint message to be stronger for &T -> &mut T transmute

The old message implied that it's only UB if you use the reference to mutate, which (as far as I know) is not true. As in, the following program has UB, and a &T -> &mut T transmute is effectively an `unreachable_unchecked`.

```rust
fn main() {
    #[allow(mutable_transmutes)]
    unsafe {
        let _ = std::mem::transmute::<&i32, &mut i32>(&0);
    }
}
```

In the future, it might be a good idea to use the edition system to make this a hard error, since I don't think it is *ever* defined behaviour? Unless we rule that `&UnsafeCell<i32> -> &mut i32` is fine. (That, and you always could just use `.get()`, so you're not losing anything)
compiler/rustc_lint/src/builtin.rs