Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't let unstable-locales imply the alloc feature #1307

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ default = ["clock", "std", "oldtime", "wasmbind"]
alloc = []
libc = []
winapi = ["windows-targets"]
std = []
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]
Expand Down
14 changes: 7 additions & 7 deletions src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! ISO 8601 calendar date with time zone.
#![allow(deprecated)]

#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
use core::borrow::Borrow;
use core::cmp::Ordering;
use core::ops::{Add, AddAssign, Sub, SubAssign};
Expand All @@ -14,9 +14,9 @@ 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(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
use crate::format::{DelayedFormat, Item, StrftimeItems};
use crate::naive::{IsoWeek, NaiveDate, NaiveTime};
use crate::offset::{TimeZone, Utc};
Expand Down Expand Up @@ -333,7 +333,7 @@ where
Tz::Offset: fmt::Display,
{
/// Formats the date with the specified formatting items.
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
#[inline]
#[must_use]
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
Expand All @@ -347,15 +347,15 @@ where
/// Formats the date with the specified format string.
/// See the [`crate::format::strftime`] module
/// on the supported escape sequences.
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
#[inline]
#[must_use]
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>> {
self.format_with_items(StrftimeItems::new(fmt))
}

/// 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>(
Expand All @@ -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>(
Expand Down
18 changes: 9 additions & 9 deletions src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ 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,
StrftimeItems, TOO_LONG,
};
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
use crate::format::{write_rfc3339, DelayedFormat};
use crate::naive::{Days, IsoWeek, NaiveDate, NaiveDateTime, NaiveTime};
#[cfg(feature = "clock")]
Expand Down Expand Up @@ -536,7 +536,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
///
/// Panics if the date can not be represented in this format: the year may not be negative and
/// can not have more than 4 digits.
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
#[must_use]
pub fn to_rfc2822(&self) -> String {
let mut result = String::with_capacity(32);
Expand All @@ -546,7 +546,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
}

/// Returns an RFC 3339 and ISO 8601 date and time string such as `1996-12-19T16:39:57-08:00`.
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
#[must_use]
pub fn to_rfc3339(&self) -> String {
// For some reason a string with a capacity less than 32 is ca 20% slower when benchmarking.
Expand Down Expand Up @@ -582,7 +582,7 @@ impl<Tz: TimeZone> DateTime<Tz> {
/// assert_eq!(dt.to_rfc3339_opts(SecondsFormat::Secs, true),
/// "2018-01-26T10:30:09+08:00");
/// ```
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
#[must_use]
pub fn to_rfc3339_opts(&self, secform: SecondsFormat, use_z: bool) -> String {
let mut result = String::with_capacity(38);
Expand Down Expand Up @@ -859,7 +859,7 @@ where
Tz::Offset: fmt::Display,
{
/// Formats the combined date and time with the specified formatting items.
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
#[inline]
#[must_use]
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
Expand All @@ -883,15 +883,15 @@ where
/// let formatted = format!("{}", date_time.format("%d/%m/%Y %H:%M"));
/// assert_eq!(formatted, "02/04/2017 12:50");
/// ```
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
#[inline]
#[must_use]
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>> {
self.format_with_items(StrftimeItems::new(fmt))
}

/// 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>(
Expand All @@ -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>(
Expand Down
16 changes: 8 additions & 8 deletions src/datetime/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ fn ymdhms_milli(

// local helper function to easily create a DateTime<FixedOffset>
#[allow(clippy::too_many_arguments)]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
fn ymdhms_micro(
fixedoffset: &FixedOffset,
year: i32,
Expand All @@ -293,7 +293,7 @@ fn ymdhms_micro(

// local helper function to easily create a DateTime<FixedOffset>
#[allow(clippy::too_many_arguments)]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
fn ymdhms_nano(
fixedoffset: &FixedOffset,
year: i32,
Expand All @@ -312,7 +312,7 @@ fn ymdhms_nano(
}

// local helper function to easily create a DateTime<Utc>
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
fn ymdhms_utc(year: i32, month: u32, day: u32, hour: u32, min: u32, sec: u32) -> DateTime<Utc> {
Utc.with_ymd_and_hms(year, month, day, hour, min, sec).unwrap()
}
Expand Down Expand Up @@ -451,7 +451,7 @@ fn test_datetime_with_timezone() {
}

#[test]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
fn test_datetime_rfc2822() {
let edt = FixedOffset::east_opt(5 * 60 * 60).unwrap();

Expand Down Expand Up @@ -577,7 +577,7 @@ fn test_datetime_rfc2822() {
}

#[test]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
fn test_datetime_rfc3339() {
let edt5 = FixedOffset::east_opt(5 * 60 * 60).unwrap();
let edt0 = FixedOffset::east_opt(0).unwrap();
Expand Down Expand Up @@ -663,7 +663,7 @@ fn test_datetime_rfc3339() {
}

#[test]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
fn test_rfc3339_opts() {
use crate::SecondsFormat::*;
let pst = FixedOffset::east_opt(8 * 60 * 60).unwrap();
Expand Down Expand Up @@ -694,7 +694,7 @@ fn test_rfc3339_opts() {

#[test]
#[should_panic]
#[cfg(any(feature = "alloc", feature = "std"))]
#[cfg(feature = "alloc")]
fn test_rfc3339_opts_nonexhaustive() {
use crate::SecondsFormat;
let dt = Utc.with_ymd_and_hms(1999, 10, 9, 1, 2, 3).unwrap();
Expand Down Expand Up @@ -1470,7 +1470,7 @@ fn test_test_deprecated_from_offset() {
}

#[test]
#[cfg(all(feature = "unstable-locales", any(feature = "alloc", feature = "std")))]
#[cfg(all(feature = "unstable-locales", feature = "alloc"))]
fn locale_decimal_point() {
use crate::Locale::{ar_SY, nl_NL};
let dt =
Expand Down
Loading
Loading