Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.1] Disable rustc-serialize derives for future compilers #137

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
language: rust
rust:
- 1.8.0
- stable
- beta
- nightly
matrix:
include:
- rust: 1.19.0
before_script:
- cargo generate-lockfile
- cargo update -p num-traits --precise 0.2.15
sudo: false
script:
- cargo build --verbose
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ categories = [ "algorithms", "data-structures", "science" ]
license = "MIT/Apache-2.0"
name = "num-complex"
repository = "https://github.com/rust-num/num-complex"
version = "0.1.43"
version = "0.1.44"
readme = "README.md"
build = "build.rs"

[dependencies]

Expand All @@ -29,3 +30,6 @@ version = ">= 0.7.0, < 0.9.0"
[features]
default = ["rustc-serialize"]
unstable = []

[build-dependencies]
autocfg = "1.4.0"
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

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

## Compatibility

The `num-complex` crate is tested for rustc 1.8 and greater.
The `num-complex` crate is tested for rustc 1.19 and greater.
6 changes: 6 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Release 0.1.44

- [Disable `rustc-serialize` derives for future compilers.][137]

[137]: https://github.com/rust-num/num-complex/pull/137

# Release 0.1.43

- [Fix a usage typo in README.md][20].
Expand Down
30 changes: 30 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
extern crate autocfg;

fn main() {
autocfg::rerun_path("build.rs");
autocfg::emit_possibility(HAS_DERIVE);
if std::env::var_os("CARGO_FEATURE_RUSTC_SERIALIZE").is_some() {
let ac = autocfg::new();

// These built-in derives are being removed! (rust-lang/rust#134272)
//
// It's hard to directly probe for `derive(RustcDecodable, RustcEncodable)`, because that
// depends on the external `rustc-serialize` dependency. They're in `prelude::v1` where we
// can probe by path, but ironically only on relatively new versions, so we're also using
// *inaccessible* `rust_2024` as a proxy for older versions.
if ac.probe_raw(PRELUDE_DERIVE).is_ok() || !ac.probe_path(RUST_2024) {
autocfg::emit(HAS_DERIVE);
} else {
println!("cargo:warning=rustc-serialize is not supported by the current compiler");
}
}
}

const HAS_DERIVE: &str = "has_derive_rustc_serialize";

const PRELUDE_DERIVE: &str = "
#[allow(soft_unstable, deprecated)]
pub use std::prelude::v1::{RustcDecodable, RustcEncodable};
";

const RUST_2024: &str = "std::prelude::rust_2024";
8 changes: 6 additions & 2 deletions ci/rustup.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/bin/sh
# Use rustup to locally run the same suite of tests as .travis.yml.
# (You should first install/update 1.8.0, stable, beta, and nightly.)
# (You should first install/update 1.19.0, stable, beta, and nightly.)

set -ex

export TRAVIS_RUST_VERSION
for TRAVIS_RUST_VERSION in 1.8.0 stable beta nightly; do
for TRAVIS_RUST_VERSION in 1.19.0 stable beta nightly; do
run="rustup run $TRAVIS_RUST_VERSION"
$run cargo generate-lockfile
if [ "$TRAVIS_RUST_VERSION" = 1.19.0 ]; then
$run cargo update -p num-traits --precise 0.2.15
fi
$run cargo build --verbose
$run $PWD/ci/test_full.sh
done
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
//!
//! ## Compatibility
//!
//! The `num-complex` crate is tested for rustc 1.8 and greater.
//! The `num-complex` crate is tested for rustc 1.19 and greater.

#![doc(html_root_url = "https://docs.rs/num-complex/0.1")]
#![cfg_attr(has_derive_rustc_serialize, warn(soft_unstable))] // un-deny

extern crate num_traits as traits;

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