Commit 86119bc6 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1587468 - Update num_derive to 0.3. r=boris

Differential Revision: https://phabricator.services.mozilla.com/D48731

--HG--
extra : moz-landing-system : lando
parent ac939a34
......@@ -2030,12 +2030,12 @@ dependencies = [
[[package]]
name = "num-derive"
version = "0.2.5"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 0.15.30 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
......@@ -2929,7 +2929,7 @@ dependencies = [
"matches 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"nsstring 0.1.0",
"num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
"num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
......@@ -3969,7 +3969,7 @@ dependencies = [
"checksum new_debug_unreachable 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0cdc457076c78ab54d5e0d6fa7c47981757f1e34dc39ff92787f217dede586c4"
"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2"
"checksum nom 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9c349f68f25f596b9f44cf0e7c69752a5c633b0550c3ff849518bfba0233774a"
"checksum num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "eafd0b45c5537c3ba526f79d3e75120036502bebacbb3f3220914067ce39dbf2"
"checksum num-derive 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c8b15b261814f992e33760b1fca9fe8b693d8a65299f20c9901688636cfb746"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
......
......@@ -55,7 +55,7 @@ nsstring = {path = "../../../xpcom/rust/nsstring/", optional = true}
num_cpus = {version = "1.1.0"}
num-integer = "0.1"
num-traits = "0.2"
num-derive = "0.2"
num-derive = "0.3"
ordered-float = "1.0"
owning_ref = "0.4"
parking_lot = "0.9"
......
{"files":{"Cargo.toml":"24357f38521e03dbc562a42d44139d615a922406fb2bb122e17df29bc9bbb586","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"5c81631711af54d31e40841cd0153a95d9e505d8eba7503d114789ffb5e232c6","RELEASES.md":"62d6fef92273d9ee0e520ba611562b744e775318f5f6ae8e042ed94a3e19b2d6","build.rs":"16de2aa57e754fc1526d0400b5d87a3f771296705fca54601aa598b6f74ded8f","src/lib.rs":"5860c6007ea74b7b58033c15beae7c9e0859205e3ca1b76af9dc3e82914e08a2","tests/empty_enum.rs":"1b2312ec2fc9866fce7172e71e0aa2efcc3cb9d7659d0b633eb352bb1e080d53","tests/issue-6.rs":"b03b7382de854f30b84fd39d11b2c09aa97c136408942841cfc2c30c31b3f1a7","tests/issue-9.rs":"1aa7353078321a964c70986ceb071569290509b70faa9825e8b584165865ea7e","tests/newtype.rs":"1b60f13afbed8f18e94fe37141543d0c8d265419e1c2447b84ce14ac82af48e8","tests/num_derive_without_num.rs":"3ce528221a2cb752859e20c5423c4b474fec714b41d8c1b62f5614b165d7262b","tests/trivial.rs":"a6b0faab04527f6835f43cd72317a00065a7a6cf4c506d04e77f898134f7a59b","tests/with_custom_values.rs":"81ed60b50726555ee840ca773335aae68ac425d5af9ebbcbb3c6d6834358c73c"},"package":"eafd0b45c5537c3ba526f79d3e75120036502bebacbb3f3220914067ce39dbf2"}
\ No newline at end of file
{"files":{"Cargo.toml":"f333817f961b4090590b753fbc8caa1628f7f67fd1b9fa6be6867e39edd8e29d","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"6485b8ed310d3f0340bf1ad1f47645069ce4069dcc6bb46c7d5c6faf41de1fdb","README.md":"fad4fc4a86958ac1829580bc03cfb231a1c564f503fcfd2249438de19723e7d4","RELEASES.md":"b82c27aa244710cd51b150ab1efee48dd8c7f9405ae18b50d2a749bcdfc255aa","src/lib.rs":"2b3371455c11ea4c14d16f32a5a3de7e642f3fa259a55b4d7e80de81f23ee90a","tests/empty_enum.rs":"1b2312ec2fc9866fce7172e71e0aa2efcc3cb9d7659d0b633eb352bb1e080d53","tests/issue-6.rs":"b7fbbe86ff82933c15ec09fabadca02d2c70e184af30b9887cae83ed2f60367e","tests/issue-9.rs":"4c87f70a63e56c24480028fafa39a845d127620141df21bc0abfa23f84ff9bb7","tests/newtype-2015.rs":"163f76f0c139c3621ba7416cec5f9fb966c86c5ebed270df77196cf75d62402f","tests/newtype.rs":"bc1ff3fb3680935c2280cc91441c91ea104be24f525428987b49b86bc880217a","tests/num_derive_without_num.rs":"3ce528221a2cb752859e20c5423c4b474fec714b41d8c1b62f5614b165d7262b","tests/trivial-2015.rs":"1745e23dfafb8c717365e57d79323c61c7d4ceaa092d7399ed793fd4f2de8ff6","tests/trivial.rs":"a6b0faab04527f6835f43cd72317a00065a7a6cf4c506d04e77f898134f7a59b","tests/with_custom_values.rs":"9f15c4b732050a5498a9691c2b41902bd9172f0c7c5d3af152ea9bd4a272e885"},"package":"0c8b15b261814f992e33760b1fca9fe8b693d8a65299f20c9901688636cfb746"}
\ No newline at end of file
......@@ -11,10 +11,10 @@
# will likely look very different (and much more reasonable)
[package]
edition = "2018"
name = "num-derive"
version = "0.2.5"
version = "0.3.0"
authors = ["The Rust Project Developers"]
build = "build.rs"
exclude = ["/ci/*", "/.travis.yml", "/bors.toml"]
description = "Numeric syntax extensions"
homepage = "https://github.com/rust-num/num-derive"
......@@ -29,14 +29,22 @@ repository = "https://github.com/rust-num/num-derive"
name = "num_derive"
test = false
proc-macro = true
[[test]]
name = "newtype-2015"
edition = "2015"
[[test]]
name = "trivial-2015"
edition = "2015"
[dependencies.proc-macro2]
version = "0.4.2"
version = "1"
[dependencies.quote]
version = "0.6"
version = "1"
[dependencies.syn]
version = "0.15"
version = "1"
[dev-dependencies.num]
version = "0.2"
......
......@@ -2,6 +2,7 @@
[![crate](https://img.shields.io/crates/v/num-derive.svg)](https://crates.io/crates/num-derive)
[![documentation](https://docs.rs/num-derive/badge.svg)](https://docs.rs/num-derive)
![minimum rustc 1.31](https://img.shields.io/badge/rustc-1.31+-red.svg)
[![Travis status](https://travis-ci.org/rust-num/num-derive.svg?branch=master)](https://travis-ci.org/rust-num/num-derive)
Procedural macros to derive numeric traits in Rust.
......@@ -13,7 +14,7 @@ Add this to your `Cargo.toml`:
```toml
[dependencies]
num-traits = "0.2"
num-derive = "0.2"
num-derive = "0.3"
```
and this to your crate root:
......@@ -50,4 +51,4 @@ Release notes are available in [RELEASES.md](RELEASES.md).
## Compatibility
The `num-derive` crate is tested for rustc 1.15 and greater.
The `num-derive` crate is tested for rustc 1.31 and greater.
# Release 0.3.0 (2019-09-27)
- [Updated the `proc-macro2`, `quote`, and `syn` dependencies to 1.0][28],
which raises the minimum supported rustc to 1.31.
[28]: https://github.com/rust-num/num-derive/pull/28
# Release 0.2.5 (2019-04-23)
- [Improved the masking of lints in derived code][23].
......
use std::env;
use std::io::Write;
use std::process::{Command, Stdio};
fn main() {
if probe("fn main() { 0i128; }") {
println!("cargo:rustc-cfg=has_i128");
} else if env::var_os("CARGO_FEATURE_I128").is_some() {
panic!("i128 support was not detected!");
}
}
/// Test if a code snippet can be compiled
fn probe(code: &str) -> bool {
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");
let mut child = Command::new(rustc)
.arg("--out-dir")
.arg(out_dir)
.arg("--emit=obj")
.arg("-")
.stdin(Stdio::piped())
.spawn()
.expect("rustc probe");
child
.stdin
.as_mut()
.expect("rustc stdin")
.write_all(code.as_bytes())
.expect("write rustc stdin");
child.wait().expect("rustc probe").success()
}
......@@ -9,7 +9,7 @@
// except according to those terms.
#![crate_type = "proc-macro"]
#![doc(html_root_url = "https://docs.rs/num-derive/0.2")]
#![doc(html_root_url = "https://docs.rs/num-derive/0.3")]
#![recursion_limit = "512"]
//! Procedural macros to derive numeric traits in Rust.
......@@ -21,7 +21,7 @@
//! ```toml
//! [dependencies]
//! num-traits = "0.2"
//! num-derive = "0.2"
//! num-derive = "0.3"
//! ```
//!
//! Then you can derive traits on your own types:
......@@ -41,14 +41,9 @@
extern crate proc_macro;
extern crate proc_macro2;
#[macro_use]
extern crate quote;
extern crate syn;
use proc_macro::TokenStream;
use proc_macro2::Span;
use quote::quote;
use syn::{Data, Fields, Ident};
// Within `exp`, you can bring things into scope with `extern crate`.
......@@ -78,10 +73,9 @@ fn dummy_const_trick<T: quote::ToTokens>(
Span::call_site(),
);
quote! {
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications)]
#[allow(non_upper_case_globals, unused_qualifications)]
const #dummy_const: () = {
#[allow(unknown_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(useless_attribute))]
#[allow(clippy::useless_attribute)]
#[allow(rust_2018_idioms)]
extern crate num_traits as _num_traits;
#exp
......@@ -89,12 +83,8 @@ fn dummy_const_trick<T: quote::ToTokens>(
}
}
#[allow(deprecated)]
fn unraw(ident: &proc_macro2::Ident) -> String {
// str::trim_start_matches was added in 1.30, trim_left_matches deprecated
// in 1.33. We currently support rustc back to 1.15 so we need to continue
// to use the deprecated one.
ident.to_string().trim_left_matches("r#").to_owned()
ident.to_string().trim_start_matches("r#").to_owned()
}
// If `data` is a newtype, return the type it's wrapping.
......@@ -177,19 +167,6 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
let name = &ast.ident;
let impl_ = if let Some(inner_ty) = newtype_inner(&ast.data) {
let i128_fns = if cfg!(has_i128) {
quote! {
fn from_i128(n: i128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_i128(n).map(#name)
}
fn from_u128(n: u128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_u128(n).map(#name)
}
}
} else {
quote! {}
};
quote! {
impl _num_traits::FromPrimitive for #name {
fn from_i64(n: i64) -> Option<Self> {
......@@ -210,6 +187,9 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
fn from_i32(n: i32) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_i32(n).map(#name)
}
fn from_i128(n: i128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_i128(n).map(#name)
}
fn from_usize(n: usize) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_usize(n).map(#name)
}
......@@ -222,13 +202,15 @@ pub fn from_primitive(input: TokenStream) -> TokenStream {
fn from_u32(n: u32) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_u32(n).map(#name)
}
fn from_u128(n: u128) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_u128(n).map(#name)
}
fn from_f32(n: f32) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_f32(n).map(#name)
}
fn from_f64(n: f64) -> Option<Self> {
<#inner_ty as _num_traits::FromPrimitive>::from_f64(n).map(#name)
}
#i128_fns
}
}
} else {
......@@ -341,19 +323,6 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
let name = &ast.ident;
let impl_ = if let Some(inner_ty) = newtype_inner(&ast.data) {
let i128_fns = if cfg!(has_i128) {
quote! {
fn to_i128(&self) -> Option<i128> {
<#inner_ty as _num_traits::ToPrimitive>::to_i128(&self.0)
}
fn to_u128(&self) -> Option<u128> {
<#inner_ty as _num_traits::ToPrimitive>::to_u128(&self.0)
}
}
} else {
quote! {}
};
quote! {
impl _num_traits::ToPrimitive for #name {
fn to_i64(&self) -> Option<i64> {
......@@ -374,6 +343,9 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
fn to_i32(&self) -> Option<i32> {
<#inner_ty as _num_traits::ToPrimitive>::to_i32(&self.0)
}
fn to_i128(&self) -> Option<i128> {
<#inner_ty as _num_traits::ToPrimitive>::to_i128(&self.0)
}
fn to_usize(&self) -> Option<usize> {
<#inner_ty as _num_traits::ToPrimitive>::to_usize(&self.0)
}
......@@ -386,13 +358,15 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
fn to_u32(&self) -> Option<u32> {
<#inner_ty as _num_traits::ToPrimitive>::to_u32(&self.0)
}
fn to_u128(&self) -> Option<u128> {
<#inner_ty as _num_traits::ToPrimitive>::to_u128(&self.0)
}
fn to_f32(&self) -> Option<f32> {
<#inner_ty as _num_traits::ToPrimitive>::to_f32(&self.0)
}
fn to_f64(&self) -> Option<f64> {
<#inner_ty as _num_traits::ToPrimitive>::to_f64(&self.0)
}
#i128_fns
}
}
} else {
......@@ -452,9 +426,7 @@ pub fn to_primitive(input: TokenStream) -> TokenStream {
dummy_const_trick("ToPrimitive", &name, impl_).into()
}
#[allow(renamed_and_removed_lints)]
#[cfg_attr(feature = "cargo-clippy", allow(const_static_lifetime))]
const NEWTYPE_ONLY: &'static str = "This trait can only be derived for newtypes";
const NEWTYPE_ONLY: &str = "This trait can only be derived for newtypes";
/// Derives [`num_traits::NumOps`][num_ops] for newtypes. The inner type must already implement
/// `NumOps`.
......
#![deny(trivial_numeric_casts)]
extern crate num;
#[macro_use]
extern crate num_derive;
......
#![deny(unused_qualifications)]
extern crate num;
#[macro_use]
extern crate num_derive;
use num::FromPrimitive;
......
// Same source, just compiled for 2015 edition
include!("newtype.rs");
......@@ -2,7 +2,7 @@ extern crate num as num_renamed;
#[macro_use]
extern crate num_derive;
use num_renamed::{Float, FromPrimitive, Num, NumCast, One, ToPrimitive, Zero};
use crate::num_renamed::{Float, FromPrimitive, Num, NumCast, One, ToPrimitive, Zero};
use std::ops::Neg;
#[derive(
......@@ -35,7 +35,6 @@ fn test_from_primitive() {
}
#[test]
#[cfg(has_i128)]
fn test_from_primitive_128() {
assert_eq!(
MyFloat::from_i128(std::i128::MIN),
......@@ -49,7 +48,6 @@ fn test_to_primitive() {
}
#[test]
#[cfg(has_i128)]
fn test_to_primitive_128() {
let f = MyFloat::from_f32(std::f32::MAX).unwrap();
assert_eq!(f.to_i128(), None);
......
// Same source, just compiled for 2015 edition
include!("trivial.rs");
......@@ -64,7 +64,7 @@ fn test_reflexive_for_enum_with_custom_value() {
.map(|&x| -> Option<Color> { num_renamed::FromPrimitive::from_u64(x) })
.map(|x| x.and_then(|x| num_renamed::ToPrimitive::to_u64(&x)))
.collect();
let before = before.into_iter().cloned().map(Some).collect::<Vec<_>>();
let before = before.iter().cloned().map(Some).collect::<Vec<_>>();
assert_eq!(before, after);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment