From e22178ba10b69cea91b0f600449e79b6f7fe48bb Mon Sep 17 00:00:00 2001 From: Paul Dicker Date: Wed, 12 Jul 2023 07:50:41 +0200 Subject: [PATCH] Don't require `alloc` for `unstable-locales` feature --- Cargo.toml | 2 +- src/date.rs | 8 +++----- src/datetime/mod.rs | 8 +++----- src/format/formatting.rs | 6 ++---- src/format/mod.rs | 2 +- src/lib.rs | 10 ++++------ src/naive/date.rs | 8 +++----- 7 files changed, 17 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2c27250ca7..274c1832e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ std = [] clock = ["std", "winapi", "iana-time-zone"] oldtime = ["time"] wasmbind = ["wasm-bindgen", "js-sys"] -unstable-locales = ["pure-rust-locales", "alloc"] +unstable-locales = ["pure-rust-locales"] __internal_bench = ["criterion"] __doctest = [] diff --git a/src/date.rs b/src/date.rs index 15f3d436d1..d8c5a6bd70 100644 --- a/src/date.rs +++ b/src/date.rs @@ -13,7 +13,7 @@ use core::{fmt, hash}; #[cfg(feature = "rkyv")] use rkyv::{Archive, Deserialize, Serialize}; -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] use crate::format::Locale; #[cfg(any(feature = "alloc", feature = "std"))] use crate::format::{DelayedFormat, Item, StrftimeItems}; @@ -357,8 +357,7 @@ where } /// Formats the date with the specified formatting items and locale. - #[cfg(feature = "unstable-locales")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[inline] #[must_use] pub fn format_localized_with_items<'a, I, B>( @@ -382,8 +381,7 @@ where /// Formats the date with the specified format string and locale. /// See the [`crate::format::strftime`] module /// on the supported escape sequences. - #[cfg(feature = "unstable-locales")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[inline] #[must_use] pub fn format_localized<'a>( diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index 21a2b172ab..f09dca7958 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -13,7 +13,7 @@ use core::{fmt, hash, str}; #[cfg(feature = "std")] use std::time::{SystemTime, UNIX_EPOCH}; -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] use crate::format::Locale; use crate::format::{parse, parse_and_remainder, ParseError, ParseResult, Parsed, StrftimeItems}; #[cfg(any(feature = "alloc", feature = "std"))] @@ -803,8 +803,7 @@ where } /// Formats the combined date and time with the specified formatting items and locale. - #[cfg(feature = "unstable-locales")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[inline] #[must_use] pub fn format_localized_with_items<'a, I, B>( @@ -831,8 +830,7 @@ where /// /// See the [`crate::format::strftime`] module on the supported escape /// sequences. - #[cfg(feature = "unstable-locales")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[inline] #[must_use] pub fn format_localized<'a>( diff --git a/src/format/formatting.rs b/src/format/formatting.rs index ad5ec02c11..26e58f6a4b 100644 --- a/src/format/formatting.rs +++ b/src/format/formatting.rs @@ -487,8 +487,7 @@ pub fn format_item( /// Tries to format given arguments with given formatting items. /// Internally used by `DelayedFormat`. -#[cfg(feature = "unstable-locales")] -#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[deprecated(since = "0.4.27")] pub fn format_localized<'a, I, B>( w: &mut fmt::Formatter, @@ -507,8 +506,7 @@ where } /// Formats single formatting item -#[cfg(feature = "unstable-locales")] -#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[deprecated(since = "0.4.27")] pub fn format_item_localized( w: &mut fmt::Formatter, diff --git a/src/format/mod.rs b/src/format/mod.rs index 12e188535a..8fdf8395b5 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -59,7 +59,7 @@ pub use formatting::Formatter; #[cfg(any(feature = "alloc", feature = "std"))] pub use formatting::{format, format_item, DelayedFormat}; #[allow(deprecated)] -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] pub use formatting::{format_item_localized, format_localized}; #[cfg(feature = "unstable-locales")] pub use locales::Locale; diff --git a/src/lib.rs b/src/lib.rs index 7da889b9d6..4ff022ffd6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -229,7 +229,7 @@ //! # #[allow(unused_imports)] //! use chrono::prelude::*; //! -//! # #[cfg(feature = "unstable-locales")] +//! # #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] //! # fn test() { //! let dt = Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(); //! assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2014-11-28 12:00:09"); @@ -246,9 +246,9 @@ //! let dt_nano = NaiveDate::from_ymd_opt(2014, 11, 28).unwrap().and_hms_nano_opt(12, 0, 9, 1).unwrap().and_local_timezone(Utc).unwrap(); //! assert_eq!(format!("{:?}", dt_nano), "2014-11-28T12:00:09.000000001Z"); //! # } -//! # #[cfg(not(feature = "unstable-locales"))] +//! # #[cfg(not(all(feature = "unstable-locales", any(feature = "alloc", feature = "std"))))] //! # fn test() {} -//! # if cfg!(feature = "unstable-locales") { +//! # if cfg!(all(feature = "unstable-locales", any(feature = "alloc", feature = "std"))) { //! # test(); //! # } //! ``` @@ -426,8 +426,7 @@ pub mod prelude { #[cfg_attr(docsrs, doc(cfg(feature = "clock")))] #[doc(no_inline)] pub use crate::Local; - #[cfg(feature = "unstable-locales")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[doc(no_inline)] pub use crate::Locale; #[doc(no_inline)] @@ -458,7 +457,6 @@ pub use datetime::{DateTime, SecondsFormat, MAX_DATETIME, MIN_DATETIME}; pub mod format; /// L10n locales. #[cfg(feature = "unstable-locales")] -#[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] pub use format::Locale; pub use format::{ParseError, ParseResult}; diff --git a/src/naive/date.rs b/src/naive/date.rs index a56e3628da..6847d160cb 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -13,7 +13,7 @@ use core::{fmt, str}; use rkyv::{Archive, Deserialize, Serialize}; /// L10n locales. -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] use pure_rust_locales::Locale; #[cfg(any(feature = "alloc", feature = "std"))] @@ -1311,8 +1311,7 @@ impl NaiveDate { } /// Formats the date with the specified formatting items and locale. - #[cfg(feature = "unstable-locales")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[inline] #[must_use] pub fn format_localized_with_items<'a, I, B>( @@ -1331,8 +1330,7 @@ impl NaiveDate { /// /// See the [`crate::format::strftime`] module on the supported escape /// sequences. - #[cfg(feature = "unstable-locales")] - #[cfg_attr(docsrs, doc(cfg(feature = "unstable-locales")))] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[inline] #[must_use] pub fn format_localized<'a>(