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

proc-macro panic on FromPrimitive for u64 #102

Closed
mlgiraud opened this issue Feb 15, 2023 · 3 comments
Closed

proc-macro panic on FromPrimitive for u64 #102

mlgiraud opened this issue Feb 15, 2023 · 3 comments

Comments

@mlgiraud
Copy link
Contributor

mlgiraud commented Feb 15, 2023

The following code

use num_enum::FromPrimitive;

fn main() {
    println!("Hello, world!");
}

#[derive(Debug, Eq, PartialEq, FromPrimitive)]
#[repr(u64)]
enum Number {
    Zero = 0,
    #[num_enum(default)]
    NonZero = 1,
}

produces the error

error: proc-macro derive panicked
 --> src/main.rs:7:32
  |
7 | #[derive(Debug, Eq, PartialEq, FromPrimitive)]
  |                                ^^^^^^^^^^^^^
  |
  = help: message: attempt to shift left with overflow

It works as intended when using u32 or smaller types.
Rust version used: stable-x86_64-unknown-linux-gnu - Up to date : 1.67.1 (d5a82bbd2 2023-02-07)

@mlgiraud
Copy link
Contributor Author

Sidenote: It compiles in release. The error only occurs in debug builds.

mlgiraud added a commit to mlgiraud/num_enum that referenced this issue Feb 16, 2023
Large enums realistically will never be naturally exhaustive due to their size. The shift is now done as a checked shift and when the shift fails it will default to not naturally exhaustive, requiring the default attribute, even if it were exhaustive. (I want to meet the person who manages to write down 2^64 enum values or more)
@mlgiraud
Copy link
Contributor Author

@illicitonion Could you please review my fix i provided and merge as soon as you find the time? This is currently a blocker for our project. See #103

illicitonion pushed a commit that referenced this issue Feb 16, 2023
Large enums realistically will never be naturally exhaustive due to their size. The shift is now done as a checked shift and when the shift fails it will default to not naturally exhaustive, requiring the default attribute, even if it were exhaustive. (I want to meet the person who manages to write down 2^64 enum values or more)
@illicitonion
Copy link
Owner

Fixed by #103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants