diff --git a/Cargo.toml b/Cargo.toml index 571b2e9f70..92b75e0d21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ std = [] clock = ["std", "winapi", "iana-time-zone", "android-tzdata"] oldtime = [] wasmbind = ["wasm-bindgen", "js-sys"] -unstable-locales = ["pure-rust-locales", "alloc"] +unstable-locales = ["pure-rust-locales"] __internal_bench = [] [dependencies] diff --git a/src/date.rs b/src/date.rs index 6cbe851fac..126fbca9b1 100644 --- a/src/date.rs +++ b/src/date.rs @@ -14,7 +14,7 @@ use core::{fmt, hash}; use rkyv::{Archive, Deserialize, Serialize}; use crate::duration::Duration as OldDuration; -#[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}; @@ -355,7 +355,7 @@ where } /// Formats the date with the specified formatting items and locale. - #[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>( @@ -379,7 +379,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(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 12e2660297..63c30c7123 100644 --- a/src/datetime/mod.rs +++ b/src/datetime/mod.rs @@ -15,7 +15,7 @@ use core::{fmt, hash, str}; use std::time::{SystemTime, UNIX_EPOCH}; use crate::duration::Duration as OldDuration; -#[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, parse_rfc3339, Fixed, Item, ParseError, ParseResult, Parsed, @@ -891,7 +891,7 @@ where } /// Formats the combined date and time with the specified formatting items and locale. - #[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>( @@ -918,7 +918,7 @@ where /// /// See the [`crate::format::strftime`] module on the supported escape /// sequences. - #[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 4e572d548a..830a083877 100644 --- a/src/format/formatting.rs +++ b/src/format/formatting.rs @@ -40,7 +40,10 @@ use super::locales; ))] use super::{Colons, OffsetFormat, OffsetPrecision, Pad}; #[cfg(any(feature = "alloc", feature = "std"))] -use super::{Fixed, InternalFixed, InternalInternal, Item, Locale, Numeric}; +use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric}; +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] +use super::Locale; + #[cfg(any(feature = "alloc", feature = "std"))] use locales::*; @@ -203,7 +206,7 @@ pub fn format_item( /// Tries to format given arguments with given formatting items. /// Internally used by `DelayedFormat`. -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")] pub fn format_localized<'a, I, B>( w: &mut fmt::Formatter, @@ -228,7 +231,7 @@ where } /// Formats single formatting item -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")] pub fn format_item_localized( w: &mut fmt::Formatter, diff --git a/src/format/mod.rs b/src/format/mod.rs index d5256ab1e9..a2f7af1666 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -48,7 +48,7 @@ pub(crate) mod scan; pub mod strftime; -#[cfg(any(feature = "alloc", feature = "std"))] +#[allow(unused)] // TODO: remove once we use this module for parsing or something else that does not require `alloc`. pub(crate) mod locales; pub(crate) use formatting::write_hundreds; @@ -64,13 +64,11 @@ pub(crate) use formatting::write_rfc3339; #[cfg(any(feature = "alloc", feature = "std"))] #[allow(deprecated)] pub use formatting::{format, format_item, DelayedFormat}; -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[allow(deprecated)] pub use formatting::{format_item_localized, format_localized}; -#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] +#[cfg(feature = "unstable-locales")] pub use locales::Locale; -#[cfg(all(not(feature = "unstable-locales"), any(feature = "alloc", feature = "std")))] -pub(crate) use locales::Locale; pub(crate) use parse::parse_rfc3339; pub use parse::{parse, parse_and_remainder}; pub use parsed::Parsed; diff --git a/src/lib.rs b/src/lib.rs index c91bc06777..8a3b19683e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -227,7 +227,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"); @@ -244,9 +244,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(); //! # } //! ``` @@ -489,7 +489,7 @@ pub mod prelude { #[cfg(feature = "clock")] #[doc(no_inline)] pub use crate::Local; - #[cfg(feature = "unstable-locales")] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[doc(no_inline)] pub use crate::Locale; #[doc(no_inline)] diff --git a/src/naive/date.rs b/src/naive/date.rs index 886dbb4f95..4758b131e1 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; use crate::duration::Duration as OldDuration; @@ -1319,7 +1319,7 @@ impl NaiveDate { } /// Formats the date with the specified formatting items and locale. - #[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>( @@ -1338,7 +1338,7 @@ impl NaiveDate { /// /// See the [`crate::format::strftime`] module on the supported escape /// sequences. - #[cfg(feature = "unstable-locales")] + #[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))] #[inline] #[must_use] pub fn format_localized<'a>(