From fd902670b4bb8e7fe865317dceea0222d7467429 Mon Sep 17 00:00:00 2001 From: tyranron Date: Wed, 26 Oct 2022 17:20:35 +0200 Subject: [PATCH] Fix workspace tests --- Cargo.toml | 8 ++++---- impl/Cargo.toml | 12 ++++++------ impl/build.rs | 15 +++++++++++++++ impl/doc/error.md | 6 +++--- 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 impl/build.rs diff --git a/Cargo.toml b/Cargo.toml index d985fb6c..e87d466c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,8 @@ include = [ "tests/**/*.rs", # debian packaging wants this ] +[workspace] +members = ["impl"] [dependencies] derive_more-impl = { version = "=0.99.17", path = "impl" } @@ -29,9 +31,6 @@ derive_more-impl = { version = "=0.99.17", path = "impl" } [build-dependencies] rustc_version = { version = "0.4", optional = true } -[workspace] -members = ["impl"] - [dev-dependencies] rustversion = "1.0" trybuild = "1.0.56" @@ -64,7 +63,6 @@ mul = ["derive_more-impl/mul"] not = ["derive_more-impl/not"] sum = ["derive_more-impl/sum"] try_into = ["derive_more-impl/try_into"] -testing-helpers = ["rustc_version"] is_variant = ["derive_more-impl/is_variant"] unwrap = ["derive_more-impl/unwrap"] @@ -94,6 +92,8 @@ default = [ "unwrap" ] +testing-helpers = ["derive_more-impl/testing-helpers", "rustc_version"] + [[test]] name = "add_assign" path = "tests/add_assign.rs" diff --git a/impl/Cargo.toml b/impl/Cargo.toml index abebeddc..ef75ee67 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "derive_more-impl" -version = "0.99.17" +version = "0.99.17" # should be the same as main crate version edition = "2021" rust-version = "1.56.0" -description = "Adds #[derive(x)] macros for more traits" +description = "Internal implementation of `derive_more` crate" authors = ["Jelte Fennema "] license = "MIT" repository = "https://github.com/JelteF/derive_more" @@ -32,8 +32,7 @@ unicode-xid = { version = "0.2.2", optional = true } rustc_version = { version = "0.4", optional = true } [dev-dependencies] -rustversion = "1.0" -trybuild = "1.0.56" +derive_more = { path = ".." } [badges] github = { repository = "JelteF/derive_more", workflow = "CI" } @@ -63,8 +62,9 @@ mul = ["syn/extra-traits"] not = ["syn/extra-traits"] sum = [] try_into = ["syn/extra-traits"] -testing-helpers = ["rustc_version"] is_variant = ["convert_case"] -unwrap = ["convert_case", "rustc_version"] +unwrap = ["convert_case"] default = [] + +testing-helpers = ["rustc_version"] diff --git a/impl/build.rs b/impl/build.rs new file mode 100644 index 00000000..dbd20bb6 --- /dev/null +++ b/impl/build.rs @@ -0,0 +1,15 @@ +#[cfg(not(feature = "testing-helpers"))] +fn detect_nightly() {} + +#[cfg(feature = "testing-helpers")] +fn detect_nightly() { + use rustc_version::{version_meta, Channel}; + + if version_meta().unwrap().channel == Channel::Nightly { + println!("cargo:rustc-cfg=nightly"); + } +} + +fn main() { + detect_nightly(); +} diff --git a/impl/doc/error.md b/impl/doc/error.md index 35bd273f..4643cef3 100644 --- a/impl/doc/error.md +++ b/impl/doc/error.md @@ -47,11 +47,11 @@ ignored for one of these methods by using `#[error(not(backtrace))]` or ## Example usage ```rust -# #![cfg_attr(feature = "nightly", feature(error_generic_member_access, provide_any))] +# #![cfg_attr(nightly, feature(error_generic_member_access, provide_any))] // Nightly requires enabling this features: // #![feature(error_generic_member_access, provide_any)] -# #[cfg(not(feature = "nightly"))] fn main() {} -# #[cfg(feature = "nightly")] fn main() { +# #[cfg(not(nightly))] fn main() {} +# #[cfg(nightly)] fn main() { # use std::{any, error::Error as _, backtrace::Backtrace}; # # use derive_more::{Display, Error, From};