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

as cast of non-Copy enum is no longer a move #102389

Closed
scottmcm opened this issue Sep 28, 2022 · 3 comments · Fixed by #103016
Closed

as cast of non-Copy enum is no longer a move #102389

scottmcm opened this issue Sep 28, 2022 · 3 comments · Fixed by #103016
Assignees
Labels
C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@scottmcm
Copy link
Member

@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.

@scottmcm scottmcm added T-lang Relevant to the language team, which will review and decide on the PR/issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. C-bug Category: This is a bug. labels Sep 28, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 28, 2022
@scottmcm scottmcm added the I-lang-nominated Nominated for discussion during a lang team meeting. label Sep 28, 2022
@joshtriplett joshtriplett added the P-critical Critical priority label Oct 4, 2022
@joshtriplett
Copy link
Member

Prioritized as P-critical in @rust-lang/lang meeting just now. This needs to be fixed by 1.65 at a minimum.

@nikomatsakis
Copy link
Contributor

@rustbot labels +T-compiler

This needs work from T-compiler! :)

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 11, 2022
@nikomatsakis
Copy link
Contributor

@rustbot labels -I-lang-nominated

Meeting consensus is that the current behavior is wrong and needs to be fixed.

@rustbot rustbot removed the I-lang-nominated Nominated for discussion during a lang team meeting. label Oct 11, 2022
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 13, 2022
@pnkfelix pnkfelix self-assigned this Oct 13, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 13, 2022
@bors bors closed this as completed in cf67565 Oct 14, 2022
GDYendell added a commit to GDYendell/exercism-rust that referenced this issue Oct 23, 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. P-critical Critical priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants