Skip to content

Commit 6b11ef8

Browse files
committed
Disable rustc-serialize derives for future compilers
The built-in derives are being [removed], but crater showed problems with crates depending on `num v0.1`, where this feature is enabled by default. With this PR, we detect the missing built-ins and disable the derives, adding a build-script warning about it. Cargo won't show such warnings by default from non-path dependencies, unless the build fails. [removed]: rust-lang/rust#134272
1 parent fc4d149 commit 6b11ef8

File tree

8 files changed

+54
-21
lines changed

8 files changed

+54
-21
lines changed

.travis.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ rust:
55
- nightly
66
matrix:
77
include:
8-
- rust: 1.8.0
8+
- rust: 1.19.0
99
before_script:
10-
# rand 0.3.22 started depending on rand 0.4, which requires rustc 1.15
11-
# manually hacking the lockfile due to the limitations of cargo#2773
1210
- cargo generate-lockfile
13-
- sed -i -e 's/"rand 0.[34].[0-9]\+/"rand 0.3.20/' Cargo.lock
14-
- sed -i -e '/^name = "rand"/,/^$/s/version = "0.3.[0-9]\+"/version = "0.3.20"/' Cargo.lock
11+
- cargo update -p num-integer --precise 0.1.45
12+
- cargo update -p num-traits --precise 0.2.15
13+
- cargo update -p libc --precise 0.2.163
1514
sudo: false
1615
script:
1716
- cargo build --verbose

Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ categories = [ "algorithms", "data-structures", "science" ]
88
license = "MIT/Apache-2.0"
99
name = "num-bigint"
1010
repository = "https://github.com/rust-num/num-bigint"
11-
version = "0.1.44"
11+
version = "0.1.45"
1212
readme = "README.md"
13+
build = "build.rs"
1314

1415
[[bench]]
1516
name = "bigint"
@@ -52,3 +53,6 @@ version = ">= 0.3.14, < 0.5.0"
5253

5354
[features]
5455
default = ["rand", "rustc-serialize"]
56+
57+
[build-dependencies]
58+
autocfg = "1.4.0"

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![crate](https://img.shields.io/crates/v/num-bigint.svg)](https://crates.io/crates/num-bigint)
44
[![documentation](https://docs.rs/num-bigint/badge.svg)](https://docs.rs/num-bigint)
5-
![minimum rustc 1.8](https://img.shields.io/badge/rustc-1.8+-red.svg)
5+
![minimum rustc 1.19](https://img.shields.io/badge/rustc-1.19+-red.svg)
66
[![Travis status](https://travis-ci.org/rust-num/num-bigint.svg?branch=master)](https://travis-ci.org/rust-num/num-bigint)
77

88
Big integer types for Rust, `BigInt` and `BigUint`.
@@ -28,7 +28,7 @@ Release notes are available in [RELEASES.md](RELEASES.md).
2828

2929
## Compatibility
3030

31-
The `num-bigint` crate is tested for rustc 1.8 and greater.
31+
The `num-bigint` crate is tested for rustc 1.19 and greater.
3232

3333
## Alternatives
3434

@@ -38,7 +38,7 @@ table offers a brief comparison to a few alternatives.
3838

3939
| Crate | License | Min rustc | Implementation |
4040
| :--------------- | :------------- | :-------- | :------------- |
41-
| **`num-bigint`** | MIT/Apache-2.0 | 1.8 | pure rust |
41+
| **`num-bigint`** | MIT/Apache-2.0 | 1.19 | pure rust |
4242
| [`ramp`] | Apache-2.0 | nightly | rust and inline assembly |
4343
| [`rug`] | LGPL-3.0+ | 1.18 | bundles [GMP] via [`gmp-mpfr-sys`] |
4444
| [`rust-gmp`] | MIT | stable? | links to [GMP] |

build.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extern crate autocfg;
2+
3+
fn main() {
4+
autocfg::rerun_path("build.rs");
5+
autocfg::emit_possibility(HAS_DERIVE);
6+
if std::env::var_os("CARGO_FEATURE_RUSTC_SERIALIZE").is_some() {
7+
let ac = autocfg::new();
8+
9+
// These built-in derives are being removed! (rust-lang/rust#134272)
10+
//
11+
// It's hard to directly probe for `derive(RustcDecodable, RustcEncodable)`, because that
12+
// depends on the external `rustc-serialize` dependency. They're in `prelude::v1` where we
13+
// can probe by path, but ironically only on relatively new versions, so we're also using
14+
// *inaccessible* `rust_2024` as a proxy for older versions.
15+
if ac.probe_raw(PRELUDE_DERIVE).is_ok() || !ac.probe_path(RUST_2024) {
16+
autocfg::emit(HAS_DERIVE);
17+
} else {
18+
println!("cargo:warning=rustc-serialize is not supported by the current compiler");
19+
}
20+
}
21+
}
22+
23+
const HAS_DERIVE: &str = "has_derive_rustc_serialize";
24+
25+
const PRELUDE_DERIVE: &str = "
26+
#[allow(soft_unstable, deprecated)]
27+
pub use std::prelude::v1::{RustcDecodable, RustcEncodable};
28+
";
29+
30+
const RUST_2024: &str = "std::prelude::rust_2024";

ci/rustup.sh

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
#!/bin/sh
22
# Use rustup to locally run the same suite of tests as .travis.yml.
3-
# (You should first install/update 1.8.0, stable, beta, and nightly.)
3+
# (You should first install/update 1.19.0, stable, beta, and nightly.)
44

55
set -ex
66

77
export TRAVIS_RUST_VERSION
8-
for TRAVIS_RUST_VERSION in 1.8.0 stable beta nightly; do
8+
for TRAVIS_RUST_VERSION in 1.19.0 stable beta nightly; do
99
run="rustup run $TRAVIS_RUST_VERSION"
10-
if [ "$TRAVIS_RUST_VERSION" = 1.8.0 ]; then
11-
# rand 0.3.22 started depending on rand 0.4, which requires rustc 1.15
12-
# manually hacking the lockfile due to the limitations of cargo#2773
13-
$run cargo generate-lockfile
14-
$run sed -i -e 's/"rand 0.[34].[0-9]\+/"rand 0.3.20/' Cargo.lock
15-
$run sed -i -e '/^name = "rand"/,/^$/s/version = "0.3.[0-9]\+"/version = "0.3.20"/' Cargo.lock
10+
$run cargo generate-lockfile
11+
if [ "$TRAVIS_RUST_VERSION" = 1.19.0 ]; then
12+
$run cargo update -p num-integer --precise 0.1.45
13+
$run cargo update -p num-traits --precise 0.2.15
14+
$run cargo update -p libc --precise 0.2.163
1615
fi
1716
$run cargo build --verbose
1817
$run $PWD/ci/test_full.sh

src/bigint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ mod bigint_tests;
3838

3939
/// A Sign is a `BigInt`'s composing element.
4040
#[derive(PartialEq, PartialOrd, Eq, Ord, Copy, Clone, Debug, Hash)]
41-
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
41+
#[cfg_attr(has_derive_rustc_serialize, derive(RustcEncodable, RustcDecodable))]
4242
pub enum Sign {
4343
Minus,
4444
NoSign,
@@ -104,7 +104,7 @@ impl serde::Deserialize for Sign {
104104

105105
/// A big signed integer type.
106106
#[derive(Clone, Debug, Hash)]
107-
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
107+
#[cfg_attr(has_derive_rustc_serialize, derive(RustcEncodable, RustcDecodable))]
108108
pub struct BigInt {
109109
sign: Sign,
110110
data: BigUint,

src/biguint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ mod biguint_tests;
4747
/// A `BigUint`-typed value `BigUint { data: vec!(a, b, c) }` represents a number
4848
/// `(a + b * big_digit::BASE + c * big_digit::BASE^2)`.
4949
#[derive(Clone, Debug, Hash)]
50-
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
50+
#[cfg_attr(has_derive_rustc_serialize, derive(RustcEncodable, RustcDecodable))]
5151
pub struct BigUint {
5252
data: Vec<BigDigit>,
5353
}

src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@
7272
//!
7373
//! ## Compatibility
7474
//!
75-
//! The `num-bigint` crate is tested for rustc 1.8 and greater.
75+
//! The `num-bigint` crate is tested for rustc 1.19 and greater.
7676
7777
#![doc(html_root_url = "https://docs.rs/num-bigint/0.1")]
78+
#![cfg_attr(has_derive_rustc_serialize, warn(soft_unstable))] // un-deny
7879

7980
#[cfg(any(feature = "rand", test))]
8081
extern crate rand;

0 commit comments

Comments
 (0)