Skip to content

Commit 1359337

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 48ea1e1 commit 1359337

File tree

6 files changed

+52
-8
lines changed

6 files changed

+52
-8
lines changed

.travis.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
language: rust
22
rust:
3-
- 1.8.0
43
- stable
54
- beta
65
- nightly
6+
matrix:
7+
include:
8+
- rust: 1.19.0
9+
before_script:
10+
- cargo generate-lockfile
11+
- cargo update -p num-traits --precise 0.2.15
712
sudo: false
813
script:
914
- 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-complex"
1010
repository = "https://github.com/rust-num/num-complex"
11-
version = "0.1.43"
11+
version = "0.1.44"
1212
readme = "README.md"
13+
build = "build.rs"
1314

1415
[dependencies]
1516

@@ -29,3 +30,6 @@ version = ">= 0.7.0, < 0.9.0"
2930
[features]
3031
default = ["rustc-serialize"]
3132
unstable = []
33+
34+
[build-dependencies]
35+
autocfg = "1.4.0"

README.md

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

33
[![crate](https://img.shields.io/crates/v/num-complex.svg)](https://crates.io/crates/num-complex)
44
[![documentation](https://docs.rs/num-complex/badge.svg)](https://docs.rs/num-complex)
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-complex.svg?branch=master)](https://travis-ci.org/rust-num/num-complex)
77

88
`Complex` numbers for Rust.
@@ -28,4 +28,4 @@ Release notes are available in [RELEASES.md](RELEASES.md).
2828

2929
## Compatibility
3030

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

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
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+
$run cargo generate-lockfile
11+
if [ "$TRAVIS_RUST_VERSION" = 1.19.0 ]; then
12+
$run cargo update -p num-traits --precise 0.2.15
13+
fi
1014
$run cargo build --verbose
1115
$run $PWD/ci/test_full.sh
1216
done

src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
//!
1313
//! ## Compatibility
1414
//!
15-
//! The `num-complex` crate is tested for rustc 1.8 and greater.
15+
//! The `num-complex` crate is tested for rustc 1.19 and greater.
1616
1717
#![doc(html_root_url = "https://docs.rs/num-complex/0.1")]
18+
#![cfg_attr(has_derive_rustc_serialize, warn(soft_unstable))] // un-deny
1819

1920
extern crate num_traits as traits;
2021

@@ -62,7 +63,7 @@ use traits::{Zero, One, Num, Float};
6263
/// }
6364
/// ```
6465
#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug, Default)]
65-
#[cfg_attr(feature = "rustc-serialize", derive(RustcEncodable, RustcDecodable))]
66+
#[cfg_attr(has_derive_rustc_serialize, derive(RustcEncodable, RustcDecodable))]
6667
#[repr(C)]
6768
pub struct Complex<T> {
6869
/// Real portion of the complex number

0 commit comments

Comments
 (0)