From 73ce4adc05ee7da7d45c7396a53a353f4e073ca5 Mon Sep 17 00:00:00 2001 From: dylni <46035563+dylni@users.noreply.github.com> Date: Sat, 14 Oct 2023 16:42:54 -0400 Subject: [PATCH] Prevent "nightly" feature use in libraries --- .github/workflows/build.yml | 1 + src/lib.rs | 34 ++++++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0cc5f9a..28afac2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,6 +2,7 @@ name: build env: OS_STR_BYTES_CHECKED_CONVERSIONS: 1 + OS_STR_BYTES_NIGHTLY: 1 on: pull_request: diff --git a/src/lib.rs b/src/lib.rs index e8ebba0..f77fd8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,7 +137,12 @@ //! //! This feature will cause memory leaks for some newly deprecated methods. //! Therefore, it is not recommended to use this feature until the next major -//! version, when those methods will be removed. +//! version, when those methods will be removed. However, it can be used to +//! prepare for upgrading and determine impact of the new feature. +//! +//! Because this feature should not be used in libraries, the +//! "OS_STR_BYTES_NIGHTLY" environment variable must be defined during +//! compilation. //! //! # Implementation //! @@ -246,6 +251,15 @@ if_checked_conversions! { ); } +#[cfg(not(os_str_bytes_docs_rs))] +if_nightly! { + const _: &str = env!( + "OS_STR_BYTES_NIGHTLY", + "The 'OS_STR_BYTES_NIGHTLY' environment variable must be defined to \ + use the 'nightly' feature.", + ); +} + #[rustfmt::skip] macro_rules! deprecated_checked_conversion { ( $message:expr , $item:item ) => { @@ -257,6 +271,15 @@ macro_rules! deprecated_checked_conversion { }; } +macro_rules! if_nightly { + ( $($item:item)+ ) => { + $( + #[cfg(feature = "nightly")] + $item + )+ + }; +} + #[rustfmt::skip] macro_rules! deprecated_conversions { ( $($item:item)+ ) => { @@ -280,15 +303,6 @@ macro_rules! if_raw_str { } if_raw_str! { - macro_rules! if_nightly { - ( $($item:item)+ ) => { - $( - #[cfg(feature = "nightly")] - $item - )+ - }; - } - macro_rules! if_not_nightly { ( $($item:item)+ ) => { $(