Description
@MinusKelvin noticed this 1.63→1.64 change in #102303 (comment)
I tried this code:
pub enum Enum { A, B, C }
pub fn func(inbounds: &Enum, array: &[i16; 3]) -> i16 {
array[*inbounds as usize]
}
I expected to see this happen: because Enum
is non-Copy
, an error about moving out from behind a reference, like happened in 1.63 https://rust.godbolt.org/z/vGPqbsE6v
error[E0507]: cannot move out of `*inbounds` which is behind a shared reference
--> <source>:3:11
|
3 | array[*inbounds as usize]
| ^^^^^^^^^ move occurs because `*inbounds` has type `Enum`, which does not implement the `Copy` trait
Instead, this happened: it compiles fine in 1.64 https://rust.godbolt.org/z/svsPMxTs8 and in nightly https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=817f19e95903785423743c2a8466c189
This is probably cased by
Change enum->int casts to not go through MIR casts #96862
which is mentioned in https://github.com/rust-lang/rust/blob/stable/RELEASES.md#version-1640-2022-09-22
It's unclear to me whether this is intentional under the banner of "Drop
behaviour", since there's no Drop
trait involved.