Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.64 treats as casts from non-Copy enums as not moving the LHS #104262

Closed
cbiffle opened this issue Nov 10, 2022 · 2 comments
Closed

1.64 treats as casts from non-Copy enums as not moving the LHS #104262

cbiffle opened this issue Nov 10, 2022 · 2 comments
Labels
C-bug Category: This is a bug.

Comments

@cbiffle
Copy link
Contributor

cbiffle commented Nov 10, 2022

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.

@cbiffle cbiffle added the C-bug Category: This is a bug. label Nov 10, 2022
@ehuss
Copy link
Contributor

ehuss commented Nov 11, 2022

I believe this was #102389.

It was accepted for a 1.64.1 stable point release, but for some reason that stable release never happened. I don't see a discussion around that decision specifically. Usually a stable point release is only made if there is sufficient motivation, so perhaps it didn't meet the threshold?

@cbiffle
Copy link
Contributor Author

cbiffle commented Nov 11, 2022

I believe you are right! Since it was previously recognized and deliberately fixed (presumably with a regression test) I'm happy to close this issue. We, at least, do not need a 1.64 point release, we'll just clamber our way up to 1.65.

@cbiffle cbiffle closed this as completed Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants