andersk / enum_primitive-rs

Macro to generate num::FromPrimitive instances for enum that works in Rust 1.0
MIT License
63 stars 22 forks source link

Test "negative" fails on 32bit systems #15

Open ignatenkobrain opened 6 years ago

ignatenkobrain commented 6 years ago
---- negative stdout ----
    thread 'negative' panicked at 'assertion failed: `(left == right)`
  left: `None`,
 right: `Some(A)`', tests/tests.rs:192:4
cuviper commented 6 years ago

The code only implements from_u64 and from_i64. The rest will be upcast to larger types by the default FromPrimitive methods. So a 32-bit from_usize(!16) will call from_u64(0xffffffef), not sign-extended in any way, so it won't match the negative discriminant.

Either the test should reflect the difference between 32-bit and 64-bit usize, or the implementation needs to change the way it compares values. I guess this is a design choice for the desired behavior.