From bbac3bf45621b3f35ddd1f312be9a92193470738 Mon Sep 17 00:00:00 2001 From: Nova Date: Fri, 15 Sep 2023 10:15:47 -0500 Subject: [PATCH] Improve docs.rs builds (#195) --- CHANGELOG.md | 3 +++ Cargo.toml | 11 +++++++++-- build/generic_const_mappings.rs | 5 +---- build/main.rs | 12 ++++++++++-- build/op.rs | 2 -- src/lib.rs | 11 ++--------- src/type_operators.rs | 8 ++++++-- 7 files changed, 31 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac6e065f3..e6b57c606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ The MSRV (Minimum Supported Rust Version) is 1.37.0, and typenum is tested against this Rust version. ### Unreleased +- [removed] Remove `force_unix_path_separator` feature, make it the default +- [added] docs.rs metadata and cfg options +- [added] Playground metadata ### 1.16.0 (2022-12-05) - [added] `const INT` field to the `ToInt` trait. diff --git a/Cargo.toml b/Cargo.toml index 6724b3ef1..ab4542ba7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,9 +25,16 @@ scale-info = { version = "1.0", default-features = false, optional = true } name = "typenum" [features] - no_std = [] + no_std = [] # Deprecated i128 = [] strict = [] - force_unix_path_separator = [] + force_unix_path_separator = [] # Deprecated const-generics = [] scale_info = ["scale-info/derive"] + +[package.metadata.docs.rs] + features = ["i128", "const-generics"] + rustdoc-args = ["--cfg", "docsrs"] + +[package.metadata.playground] + features = ["i128", "const-generics"] diff --git a/build/generic_const_mappings.rs b/build/generic_const_mappings.rs index 9ed761347..641d4e3e9 100644 --- a/build/generic_const_mappings.rs +++ b/build/generic_const_mappings.rs @@ -3,10 +3,6 @@ use super::*; pub fn emit_impls() -> ::std::io::Result<()> { let out_dir = ::std::env::var("OUT_DIR").unwrap(); let dest = ::std::path::Path::new(&out_dir).join("generic_const_mappings.rs"); - println!( - "cargo:rustc-env=TYPENUM_BUILD_GENERIC_CONSTS={}", - dest.display() - ); let mut f = ::std::fs::File::create(&dest).unwrap(); #[allow(clippy::write_literal)] @@ -22,6 +18,7 @@ use generic_const_mappings::*; /// The main type to use here is [`U`], although [`Const`] and [`ToUInt`] may be needed /// in a generic context. #[allow(warnings)] // script-generated code +#[cfg(feature = \"const-generics\")] // hints at doc_auto_cfg pub mod generic_const_mappings { use crate::*; diff --git a/build/main.rs b/build/main.rs index 68a97af82..ae430d289 100644 --- a/build/main.rs +++ b/build/main.rs @@ -77,6 +77,15 @@ pub fn gen_int(i: i64) -> IntCode { )] pub fn no_std() {} +#[cfg_attr( + feature = "force_unix_path_separator", + deprecated( + since = "1.17.0", + note = "the `force_unix_path_separator` flag is no longer necessary and will be removed in the future" + ) +)] +pub fn force_unix_path_separator() {} + const HIGHEST: u64 = 1024; fn uints() -> impl Iterator { // Use hardcoded values to avoid issues with cross-compilation. @@ -95,12 +104,11 @@ fn main() { let out_dir = env::var("OUT_DIR").unwrap(); let dest = Path::new(&out_dir).join("consts.rs"); - #[cfg(not(feature = "force_unix_path_separator"))] - println!("cargo:rustc-env=TYPENUM_BUILD_CONSTS={}", dest.display()); let mut f = File::create(&dest).unwrap(); no_std(); + force_unix_path_separator(); // Header stuff here! write!( diff --git a/build/op.rs b/build/op.rs index f567a88c8..d4de6904d 100644 --- a/build/op.rs +++ b/build/op.rs @@ -18,8 +18,6 @@ struct Op { pub fn write_op_macro() -> ::std::io::Result<()> { let out_dir = ::std::env::var("OUT_DIR").unwrap(); let dest = ::std::path::Path::new(&out_dir).join("op.rs"); - #[cfg(not(feature = "force_unix_path_separator"))] - println!("cargo:rustc-env=TYPENUM_BUILD_OP={}", dest.display()); let mut f = ::std::fs::File::create(&dest).unwrap(); // Operator precedence is taken from diff --git a/src/lib.rs b/src/lib.rs index b4a722cb6..12862e0d6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,6 +60,7 @@ )] #![cfg_attr(feature = "cargo-clippy", deny(clippy::missing_inline_in_public_items))] #![doc(html_root_url = "https://docs.rs/typenum/1.16.0")] +#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))] // For debugging macros: // #![feature(trace_macros)] @@ -67,20 +68,12 @@ use core::cmp::Ordering; -#[cfg(feature = "force_unix_path_separator")] mod generated { include!(concat!(env!("OUT_DIR"), "/op.rs")); include!(concat!(env!("OUT_DIR"), "/consts.rs")); - #[cfg(feature = "const-generics")] - include!(concat!(env!("OUT_DIR"), "/generic_const_mappings.rs")); -} -#[cfg(not(feature = "force_unix_path_separator"))] -mod generated { - include!(env!("TYPENUM_BUILD_OP")); - include!(env!("TYPENUM_BUILD_CONSTS")); #[cfg(feature = "const-generics")] - include!(env!("TYPENUM_BUILD_GENERIC_CONSTS")); + include!(concat!(env!("OUT_DIR"), "/generic_const_mappings.rs")); } pub mod bit; diff --git a/src/type_operators.rs b/src/type_operators.rs index d476614ae..c4e859a69 100644 --- a/src/type_operators.rs +++ b/src/type_operators.rs @@ -189,7 +189,8 @@ impl_pow_f!(f64); macro_rules! impl_pow_i { () => (); - ($t: ty $(, $tail:tt)*) => ( + ($(#[$meta:meta])* $t: ty $(, $tail:tt)*) => ( + $(#[$meta])* impl Pow for $t { type Output = $t; #[inline] @@ -198,6 +199,7 @@ macro_rules! impl_pow_i { } } + $(#[$meta])* impl Pow> for $t { type Output = $t; #[inline] @@ -206,6 +208,7 @@ macro_rules! impl_pow_i { } } + $(#[$meta])* impl Pow for $t { type Output = $t; #[inline] @@ -214,6 +217,7 @@ macro_rules! impl_pow_i { } } + $(#[$meta])* impl Pow> for $t { type Output = $t; #[inline] @@ -228,7 +232,7 @@ macro_rules! impl_pow_i { impl_pow_i!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize); #[cfg(feature = "i128")] -impl_pow_i!(u128, i128); +impl_pow_i!(#[cfg_attr(docsrs, doc(cfg(feature = "i128")))] u128, i128); #[test] fn pow_test() {