Skip to content

Commit

Permalink
Merge #9
Browse files Browse the repository at this point in the history
9: unused qualifications r=cuviper a=Pzixel

This code won't work on 0.1.43:
```rust
#![deny(trivial_numeric_casts)]
#![deny(unused_qualifications)]
extern crate num;
#[macro_use]
extern crate num_derive;
use num::ToPrimitive;

#[derive(ToPrimitive)]
pub enum SomeEnum {
    A = 1
}

fn main() {
    println!("{}", SomeEnum::A.to_i64().unwrap())
}
```
This is an attempt to fix it
  • Loading branch information
bors[bot] committed Jan 26, 2018
2 parents 6f94c33 + 13e8c1f commit 6f8d5e6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ categories = [ "science" ]
license = "MIT/Apache-2.0"
name = "num-derive"
repository = "https://github.com/rust-num/num-derive"
version = "0.1.43"
version = "0.1.44"
readme = "README.md"

[dependencies]
Expand Down
7 changes: 7 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Release 0.1.44

- [The derived code now explicitly allows `unused_qualifications`][9], so users
that globally deny that lint don't encounter an error.

[9]: https://github.com/rust-num/num-derive/pull/9

# Release 0.1.43

- [The derived code now explicitly allows `trivial_numeric_casts`][7], so users
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {

let res = quote! {
#[allow(non_upper_case_globals)]
#[allow(unused_qualifications)]
const #dummy_const: () = {
extern crate num as _num;

Expand Down Expand Up @@ -148,6 +149,7 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {

let res = quote! {
#[allow(non_upper_case_globals)]
#[allow(unused_qualifications)]
const #dummy_const: () = {
extern crate num as _num;

Expand Down
18 changes: 18 additions & 0 deletions tests/issue-9.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![deny(unused_qualifications)]
extern crate num;
#[macro_use]
extern crate num_derive;
use num::FromPrimitive;
use num::ToPrimitive;

#[derive(FromPrimitive, ToPrimitive)]
pub enum SomeEnum {
A = 1
}

#[test]
fn test_unused_qualifications() {
assert!(SomeEnum::from_u64(1).is_some());
assert!(SomeEnum::from_i64(-1).is_none());
assert!(SomeEnum::A.to_i64().is_some());
}

0 comments on commit 6f8d5e6

Please sign in to comment.