diff --git a/Cargo.toml b/Cargo.toml index 195cf4434d..c5f2c8cbf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,7 +25,7 @@ std = ["alloc"] 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 78d5dc9f01..e82a3f0eee 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", feature = "alloc"))] use crate::format::Locale; #[cfg(feature = "alloc")] 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", feature = "alloc"))] #[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", feature = "alloc"))] #[inline] #[must_use] pub fn format_localized<'a>( diff --git a/src/datetime/mod.rs b/src/datetime/mod.rs index cfd2815153..d0e63d5732 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", feature = "alloc"))] 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", feature = "alloc"))] #[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", feature = "alloc"))] #[inline] #[must_use] pub fn format_localized<'a>( diff --git a/src/format/formatting.rs b/src/format/formatting.rs index 805866bb4a..46e9663440 100644 --- a/src/format/formatting.rs +++ b/src/format/formatting.rs @@ -22,10 +22,12 @@ use crate::{NaiveDate, NaiveTime, Weekday}; #[cfg(feature = "alloc")] use super::locales; +#[cfg(all(feature = "unstable-locales", feature = "alloc"))] +use super::Locale; #[cfg(any(feature = "alloc", feature = "serde", feature = "rustc-serialize"))] use super::{Colons, OffsetFormat, OffsetPrecision, Pad}; #[cfg(feature = "alloc")] -use super::{Fixed, InternalFixed, InternalInternal, Item, Locale, Numeric}; +use super::{Fixed, InternalFixed, InternalInternal, Item, Numeric}; #[cfg(feature = "alloc")] use locales::*; @@ -188,7 +190,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", feature = "alloc"))] #[deprecated(since = "0.4.32", note = "Use DelayedFormat::fmt instead")] pub fn format_localized<'a, I, B>( w: &mut fmt::Formatter, @@ -213,7 +215,7 @@ where } /// Formats single formatting item -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", feature = "alloc"))] #[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 58e6a4d027..46723eff9c 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -48,7 +48,9 @@ pub(crate) mod scan; pub mod strftime; -#[cfg(feature = "alloc")] +#[allow(unused)] +// TODO: remove '#[allow(unused)]' 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; @@ -59,13 +61,11 @@ pub(crate) use formatting::write_rfc3339; #[cfg(feature = "alloc")] #[allow(deprecated)] pub use formatting::{format, format_item, DelayedFormat}; -#[cfg(feature = "unstable-locales")] +#[cfg(all(feature = "unstable-locales", feature = "alloc"))] #[allow(deprecated)] pub use formatting::{format_item_localized, format_localized}; -#[cfg(all(feature = "unstable-locales", feature = "alloc"))] +#[cfg(feature = "unstable-locales")] pub use locales::Locale; -#[cfg(all(not(feature = "unstable-locales"), feature = "alloc"))] -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..7841afb42c 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", feature = "alloc"))] //! # 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", feature = "alloc")))] //! # fn test() {} -//! # if cfg!(feature = "unstable-locales") { +//! # if cfg!(all(feature = "unstable-locales", feature = "alloc")) { //! # 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", feature = "alloc"))] #[doc(no_inline)] pub use crate::Locale; #[doc(no_inline)] diff --git a/src/naive/date.rs b/src/naive/date.rs index 0990e2d5a7..907b1285d1 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", feature = "alloc"))] 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", feature = "alloc"))] #[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", feature = "alloc"))] #[inline] #[must_use] pub fn format_localized<'a>(