-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
7: Use i64, and allow trivial_numeric_casts r=cuviper a=cuviper The traits are implemented from 64-bit values, and we don't want to lose any bits when comparing on platforms with smaller `isize`. Simple enum expressions may have no explicit type, like `A = 1`, so then the derived `1 as i64` is inferred like `1i64 as i64`, a trivial numeric cast. But it's quite possible that other expressions could have explicit types, so we can't just assign it directly either. The simple solution is to just allow the `trivial_numeric_casts` in derived code. Fixes #6.
- Loading branch information
Showing
2 changed files
with
36 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![deny(trivial_numeric_casts)] | ||
extern crate num; | ||
#[macro_use] | ||
extern crate num_derive; | ||
|
||
#[derive(FromPrimitive, ToPrimitive)] | ||
pub enum SomeEnum { | ||
A = 1 | ||
} | ||
|
||
#[test] | ||
fn test_trivial_numeric_casts() { | ||
use num::{FromPrimitive, ToPrimitive}; | ||
assert!(SomeEnum::from_u64(1).is_some()); | ||
assert!(SomeEnum::from_i64(-1).is_none()); | ||
assert_eq!(SomeEnum::A.to_u64(), Some(1)); | ||
} |