Skip to content

Commit

Permalink
Prevent "nightly" feature use in libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
dylni committed Oct 14, 2023
1 parent 79f1a53 commit 73ce4ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: build

env:
OS_STR_BYTES_CHECKED_CONVERSIONS: 1
OS_STR_BYTES_NIGHTLY: 1

on:
pull_request:
Expand Down
34 changes: 24 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -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 ) => {
Expand All @@ -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)+ ) => {
Expand All @@ -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)+ ) => {
$(
Expand Down

0 comments on commit 73ce4ad

Please sign in to comment.