Skip to content

Commit

Permalink
Use core::error (#5973)
Browse files Browse the repository at this point in the history
Fixes #5964 

The only remaining uses of `std` are:
* `DataError::Io` and `DataError::with_path`
* `with_path` can be replaced by `with_display_context(path.display())`,
but the `std::io::ErrorKind` is not in `core` (it could be, it's a
fieldless enum).
* `icu_provider::log` falling back to `println!` (negative `logging`
feature)
* `icu_capi` keeps its std feature, as that's required to build a static
library with panic=unwind. I'm not sure what the use case for this is,
but we use it as a baseline in the size benchmark.
  • Loading branch information
robertbastian authored Jan 13, 2025
1 parent 3878cf1 commit 263fdc2
Show file tree
Hide file tree
Showing 116 changed files with 186 additions and 186 deletions.
1 change: 0 additions & 1 deletion components/calendar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ criterion = { workspace = true }
default = ["compiled_data", "ixdtf"]
ixdtf = ["dep:ixdtf"]
logging = ["calendrical_calculations/logging"]
std = ["icu_provider/std", "icu_locale_core/std", "calendrical_calculations/std"]
serde = ["dep:serde", "zerovec/serde", "tinystr/serde", "icu_provider/serde"]
datagen = ["serde", "dep:databake", "zerovec/databake", "tinystr/databake"]
bench = []
Expand Down
4 changes: 4 additions & 0 deletions components/calendar/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub enum DateError {
UnknownMonthCode(MonthCode),
}

impl core::error::Error for DateError {}

#[derive(Debug, Copy, Clone, PartialEq, Display)]
/// An argument is out of range for its domain.
#[displaydoc("The {field} = {value} argument is out of range {min}..={max}")]
Expand All @@ -44,6 +46,8 @@ pub struct RangeError {
pub max: i32,
}

impl core::error::Error for RangeError {}

impl From<RangeError> for DateError {
fn from(value: RangeError) -> Self {
let RangeError {
Expand Down
2 changes: 1 addition & 1 deletion components/calendar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
//! [`ICU4X`]: ../icu/index.html
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(any(test, doc)), no_std)]
#![cfg_attr(
not(test),
deny(
Expand Down
1 change: 0 additions & 1 deletion components/casemap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ criterion = { workspace = true }

[features]
default = ["compiled_data"]
std = ["icu_collections/std", "icu_provider/std"]
bench = []
serde = ["dep:serde", "zerovec/serde", "icu_collections/serde", "icu_provider/serde", "icu_properties/serde", "potential_utf/serde"]
datagen = ["serde", "dep:databake", "zerovec/databake", "icu_collections/databake"]
Expand Down
2 changes: 1 addition & 1 deletion components/casemap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
//! [`ICU4X`]: ../icu/index.html
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(any(test, doc)), no_std)]
#![cfg_attr(
not(test),
deny(
Expand Down
1 change: 0 additions & 1 deletion components/collator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ criterion = { workspace = true }

[features]
default = ["compiled_data"]
std = ["icu_collections/std", "icu_locale_core/std", "icu_normalizer/std", "icu_properties/std", "icu_provider/std"]
serde = ["dep:serde", "zerovec/serde", "icu_properties/serde", "icu_normalizer/serde", "icu_collections/serde", "icu_provider/serde"]
datagen = ["serde", "dep:databake", "zerovec/databake", "icu_properties/datagen", "icu_normalizer/datagen", "icu_collections/databake"]
compiled_data = ["dep:icu_collator_data", "icu_normalizer/compiled_data"]
Expand Down
2 changes: 1 addition & 1 deletion components/collator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// described in LICENSE.

// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(any(test, doc)), no_std)]
#![cfg_attr(
not(test),
deny(
Expand Down
1 change: 0 additions & 1 deletion components/collections/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ toml = { workspace = true }
criterion = { workspace = true }

[features]
std = []
serde = ["dep:serde", "zerovec/serde", "potential_utf/serde"]
databake = ["dep:databake", "zerovec/databake"]
bench = []
Expand Down
2 changes: 2 additions & 0 deletions components/collections/src/codepointtrie/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ pub enum Error {
#[displaydoc("CodePointTrie must be constructed from data vector with at least one element")]
EmptyDataVector,
}

impl core::error::Error for Error {}
2 changes: 1 addition & 1 deletion components/collections/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//! / [ICU4J CharsTrie](https://unicode-org.github.io/icu-docs/apidoc/released/icu4j/com/ibm/icu/util/CharsTrie.html) API.
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(any(test, doc)), no_std)]
#![cfg_attr(
not(test),
deny(
Expand Down
9 changes: 0 additions & 9 deletions components/datetime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ criterion = { workspace = true }

[features]
default = ["compiled_data"]
std = [
"icu_calendar/std",
"icu_decimal/std",
"icu_locale_core/std",
"icu_plurals/std",
"icu_provider/std",
"icu_timezone/std",
]
serde = [
"dep:serde",
"icu_calendar/serde",
Expand All @@ -93,7 +85,6 @@ datagen = [
"icu_plurals/datagen",
"icu_timezone/datagen",
"serde",
"std",
]
logging = ["icu_calendar/logging"]
experimental = ["dep:litemap"]
Expand Down
2 changes: 2 additions & 0 deletions components/datetime/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ pub enum BuilderError {
InvalidOptions,
}

impl core::error::Error for BuilderError {}

/// A builder for [dynamic field sets](crate::fieldsets::enums).
///
/// This builder is useful if you do not know the field set at code compilation time. If you do,
Expand Down
6 changes: 6 additions & 0 deletions components/datetime/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum DateTimeFormatterLoadError {
Data(DataError),
}

impl core::error::Error for DateTimeFormatterLoadError {}

impl From<DataError> for DateTimeFormatterLoadError {
fn from(error: DataError) -> Self {
Self::Data(error)
Expand All @@ -52,6 +54,8 @@ pub struct MismatchedCalendarError {
pub date_kind: Option<AnyCalendarKind>,
}

impl core::error::Error for MismatchedCalendarError {}

#[non_exhaustive]
#[derive(Debug, PartialEq, Copy, Clone, displaydoc::Display)]
/// Error for `TryWriteable` implementations
Expand Down Expand Up @@ -129,3 +133,5 @@ pub enum DateTimeWriteError {
#[displaydoc("Unsupported field {0:?}")]
UnsupportedField(ErrorField),
}

impl core::error::Error for DateTimeWriteError {}
2 changes: 1 addition & 1 deletion components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
//! ```
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(any(test, doc)), no_std)]
#![cfg_attr(
not(test),
deny(
Expand Down
2 changes: 2 additions & 0 deletions components/datetime/src/neo_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum CompositeFieldSetSerdeError {
InvalidFields,
}

impl core::error::Error for CompositeFieldSetSerdeError {}

/// 🚧 \[Experimental\] A type corresponding to [`CompositeFieldSet`] that implements
/// [`serde::Serialize`] and [`serde::Deserialize`].
///
Expand Down
2 changes: 2 additions & 0 deletions components/datetime/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,8 @@ pub enum FractionalSecondError {
OutOfRange,
}

impl core::error::Error for FractionalSecondError {}

impl From<FractionalSecondDigits> for u8 {
fn from(value: FractionalSecondDigits) -> u8 {
use FractionalSecondDigits::*;
Expand Down
2 changes: 2 additions & 0 deletions components/datetime/src/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ pub enum PatternLoadError {
#[displaydoc("Problem loading data for field {1:?}: {0}")]
Data(icu_provider::DataError, ErrorField),
}

impl core::error::Error for PatternLoadError {}
3 changes: 1 addition & 2 deletions components/datetime/src/provider/fields/length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ pub enum LengthError {
InvalidLength,
}

#[cfg(feature = "std")]
impl std::error::Error for LengthError {}
impl core::error::Error for LengthError {}

/// An enum representing the length of a field within a date or time formatting pattern string.
///
Expand Down
3 changes: 1 addition & 2 deletions components/datetime/src/provider/fields/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ pub enum Error {
InvalidLength(FieldSymbol),
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
impl core::error::Error for Error {}

/// A field within a date pattern string, also referred to as a date field.
///
Expand Down
3 changes: 1 addition & 2 deletions components/datetime/src/provider/fields/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub enum SymbolError {
Invalid(u8),
}

#[cfg(feature = "std")]
impl std::error::Error for SymbolError {}
impl core::error::Error for SymbolError {}

/// A field symbol for a date formatting pattern.
///
Expand Down
3 changes: 1 addition & 2 deletions components/datetime/src/provider/pattern/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ pub enum PatternError {
UnsupportedPluralPivot,
}

#[cfg(feature = "std")]
impl std::error::Error for PatternError {}
impl core::error::Error for PatternError {}

impl From<fields::Error> for PatternError {
fn from(input: fields::Error) -> Self {
Expand Down
3 changes: 1 addition & 2 deletions components/datetime/src/provider/skeleton/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ pub enum SkeletonError {
Fields(fields::Error),
}

#[cfg(feature = "std")]
impl std::error::Error for SkeletonError {}
impl core::error::Error for SkeletonError {}

impl From<fields::Error> for SkeletonError {
fn from(e: fields::Error) -> Self {
Expand Down
5 changes: 4 additions & 1 deletion components/datetime/src/provider/skeleton/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

use alloc::format;
#[cfg(feature = "datagen")]
use alloc::string::ToString;
use core::convert::TryFrom;
use smallvec::SmallVec;

Expand Down Expand Up @@ -75,11 +77,12 @@ pub mod reference {

pub mod runtime {
use super::super::runtime::Skeleton;
use zerovec::ZeroVec;
use super::*;

#[cfg(feature = "datagen")]
use ::serde::{ser, Serialize};
use serde::{de, Deserialize, Deserializer};
use zerovec::ZeroVec;
/// This is an implementation of the serde deserialization visitor pattern.
#[allow(clippy::upper_case_acronyms)]
struct DeserializeSkeletonUTS35String;
Expand Down
6 changes: 5 additions & 1 deletion components/datetime/src/scaffold/names_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ impl_holder_trait!(tz::MzPeriodV1Marker);

/// An error returned by [`MaybePayload`].
#[allow(missing_docs)]
#[derive(Debug)]
#[derive(Debug, displaydoc::Display)]
#[non_exhaustive]
pub enum MaybePayloadError {
/// TODO
TypeTooSpecific,
/// TODO
ConflictingField,
}

impl core::error::Error for MaybePayloadError {}

impl MaybePayloadError {
pub(crate) fn into_load_error(self, error_field: ErrorField) -> PatternLoadError {
match self {
Expand Down
1 change: 0 additions & 1 deletion components/decimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ criterion = { workspace = true }

[features]
default = ["compiled_data"]
std = ["fixed_decimal/std", "icu_locale_core/std", "icu_provider/std"]
serde = ["dep:serde", "icu_provider/serde", "zerovec/serde", "tinystr/serde"]
datagen = ["serde", "dep:databake", "zerovec/databake", "tinystr/databake"]
bench = ["serde"]
Expand Down
2 changes: 1 addition & 1 deletion components/decimal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
//! [`FixedDecimalFormatter`]: FixedDecimalFormatter
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(any(test, doc)), no_std)]
#![cfg_attr(
not(test),
deny(
Expand Down
3 changes: 1 addition & 2 deletions components/experimental/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ icu_normalizer_data = { workspace = true }
[features]
default = ["compiled_data"]
compiled_data = ["dep:icu_experimental_data", "icu_decimal/compiled_data", "icu_list/compiled_data", "icu_plurals/compiled_data", "icu_properties/compiled_data", "icu_normalizer/compiled_data"]
datagen = ["serde", "std", "dep:databake", "zerovec/databake", "zerotrie/databake", "tinystr/databake", "icu_collections/databake", "std", "log", "icu_pattern/databake", "icu_plurals/datagen", "icu_pattern/alloc"]
datagen = ["serde", "dep:databake", "zerovec/databake", "zerotrie/databake", "tinystr/databake", "icu_collections/databake", "log", "icu_pattern/databake", "icu_plurals/datagen", "icu_pattern/alloc"]
ryu = ["fixed_decimal/ryu"]
serde = ["dep:serde", "zerovec/serde", "potential_utf/serde", "tinystr/serde", "icu_collections/serde", "icu_decimal/serde", "icu_list/serde", "icu_pattern/serde", "icu_plurals/serde", "icu_provider/serde", "zerotrie/serde", "icu_normalizer/serde"]
std = ["fixed_decimal/std", "icu_decimal/std", "icu_pattern/std", "icu_plurals/std", "icu_provider/std", "icu_locale_core/std"]

bench = []

Expand Down
2 changes: 2 additions & 0 deletions components/experimental/src/compactdecimal/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ pub struct ExponentError {
/// The magnitude of the number being formatted.
pub(crate) log10_type: i16,
}

impl core::error::Error for ExponentError {}
2 changes: 2 additions & 0 deletions components/experimental/src/duration/validated_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub enum DurationFormatterOptionsError {
FractionalDigitsOutOfRange,
}

impl core::error::Error for DurationFormatterOptionsError {}

impl ValidatedDurationFormatterOptions {
pub fn validate(
value: DurationFormatterOptions,
Expand Down
2 changes: 1 addition & 1 deletion components/experimental/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! crate will eventually stabilize and move to their own top-level components.
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations
#![cfg_attr(not(any(test, feature = "std")), no_std)]
#![cfg_attr(not(any(test, doc)), no_std)]
// No boilerplate, each module has their own
#![allow(clippy::module_inception)]

Expand Down
2 changes: 2 additions & 0 deletions components/experimental/src/personnames/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ pub enum PersonNamesFormatterError {
Pattern(icu_pattern::Error),
}

impl core::error::Error for PersonNamesFormatterError {}

impl From<DataError> for PersonNamesFormatterError {
fn from(e: DataError) -> Self {
PersonNamesFormatterError::Data(e)
Expand Down
2 changes: 1 addition & 1 deletion components/experimental/src/transliterate/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ where
+ DataProvider<XidStartV1Marker>,
NP: ?Sized,
{
fn iter_ids(&self) -> Result<std::collections::BTreeSet<DataIdentifierCow>, DataError> {
fn iter_ids(&self) -> Result<alloc::collections::BTreeSet<DataIdentifierCow>, DataError> {
let exclusive_data = self.collection.data.borrow();
Ok(exclusive_data
.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ type Env = LiteMap<String, InternalTransliterator>;
/// #[derive(Debug)]
/// struct AsciiUpperTransliterator;
/// impl CustomTransliterator for AsciiUpperTransliterator {
/// fn transliterate(&self, input: &str, range: std::ops::Range<usize>) -> String {
/// fn transliterate(&self, input: &str, range: core::ops::Range<usize>) -> String {
/// input.to_ascii_uppercase()
/// }
/// }
Expand Down
2 changes: 2 additions & 0 deletions components/experimental/src/units/ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub enum RatioFromStrError {
ParsingBigIntError(num_bigint::ParseBigIntError),
}

impl core::error::Error for RatioFromStrError {}

impl IcuRatio {
/// Creates a new `IcuRatio` from the given numerator and denominator.
pub fn from_big_ints(numerator: BigInt, denominator: BigInt) -> Self {
Expand Down
18 changes: 0 additions & 18 deletions components/icu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,6 @@ default = [
"icu_experimental?/default",
"icu_pattern?/default",
]
std = [
"icu_calendar/std",
"icu_casemap/std",
"icu_collator/std",
"icu_collections/std",
"icu_datetime/std",
"icu_decimal/std",
"icu_list/std",
"icu_locale/std",
"icu_normalizer/std",
"icu_plurals/std",
"icu_properties/std",
"icu_segmenter/std",
"icu_timezone/std",
"icu_experimental?/std",
"icu_pattern?/std",
]
serde = [
"icu_calendar/serde",
"icu_casemap/serde",
Expand Down Expand Up @@ -116,7 +99,6 @@ compiled_data = [
"icu_experimental?/compiled_data",
]
datagen = [
"std",
"dep:icu_provider_registry",
"dep:memchr",
"icu_calendar/datagen",
Expand Down
Loading

0 comments on commit 263fdc2

Please sign in to comment.