Description
This code is (rightfully) rejected by at least 1.57 - 1.63, accepted by 1.64, and rejected again by 1.65.
enum Foo {
A = 1,
}
fn main() {
let a = Foo::A;
let b = a as u8;
let c = a as u8;
}
In compiler versions other than 1.64, the second a as u8
assignment is rejected, since a
is not Copy
and was previously moved into the as u8
operation that created b
. On 1.64 it's silently tolerated.
This does not, as far as I can tell, affect as
conversions other non-Copy
types, though I could only come up with one example (&mut
can be as
-converted without being Copy
). It also appears to be specific to as
conversions -- attempting to move the value twice without casting triggers the compiler warning you'd expect.
It's possible this is already covered by an existing bug report, since it appears to be fixed in 1.65, but I couldn't find one, and wanted to make sure there was a paper trail in case this surprises anyone else. We've got a repo pinned to 1.64 that contains some incorrect code being admitted by this bug. (The closest thing we could find is #91161.)
Thanks to @jgallagher for help tracking this down.