Skip to content

Commit

Permalink
Remove compiled_data Default ctors from types which are prone to chan…
Browse files Browse the repository at this point in the history
…ge sufficiently often

unicode-org#5554 (comment)
  • Loading branch information
Manishearth committed Jan 7, 2025
1 parent ebc88a4 commit eb9fe77
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 35 deletions.
8 changes: 1 addition & 7 deletions components/locale/src/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,14 @@ fn uts35_check_language_rules(
TransformResult::Unmodified
}

#[cfg(feature = "compiled_data")]
impl Default for LocaleCanonicalizer<LocaleExpander> {
fn default() -> Self {
Self::new()
}
}

impl LocaleCanonicalizer<LocaleExpander> {
/// A constructor which creates a [`LocaleCanonicalizer`] from compiled data.
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
///
/// [📚 Help choosing a constructor](icu_provider::constructors)
#[cfg(feature = "compiled_data")]
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
Self::new_with_expander(LocaleExpander::new_extended())
}
Expand Down
8 changes: 1 addition & 7 deletions components/locale/src/expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,6 @@ fn update_langid_minimize(
}
}

#[cfg(feature = "compiled_data")]
impl Default for LocaleExpander {
fn default() -> Self {
Self::new()
}
}

impl LocaleExpander {
/// Creates a [`LocaleExpander`] with compiled data for commonly-used locales
/// (locales with *Basic* or higher [CLDR coverage]).
Expand All @@ -228,6 +221,7 @@ impl LocaleExpander {
///
/// [CLDR coverage]: https://www.unicode.org/reports/tr35/tr35-info.html#Coverage_Levels
#[cfg(feature = "compiled_data")]
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
LocaleExpander {
likely_subtags_l: DataPayload::from_static_ref(
Expand Down
8 changes: 1 addition & 7 deletions components/locale/src/fallback/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,14 @@ impl<'a> LocaleFallbackerBorrowed<'a> {
}
}

#[cfg(feature = "compiled_data")]
impl Default for LocaleFallbackerBorrowed<'static> {
fn default() -> Self {
Self::new()
}
}

impl LocaleFallbackerBorrowed<'static> {
/// Creates a [`LocaleFallbackerBorrowed`] with compiled fallback data (likely subtags and parent locales).
///
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
///
/// [📚 Help choosing a constructor](icu_provider::constructors)
#[cfg(feature = "compiled_data")]
#[allow(clippy::new_without_default)]
pub const fn new() -> Self {
Self {
likely_subtags: crate::provider::Baked::SINGLETON_LIKELY_SUBTAGS_FOR_LANGUAGE_V1_MARKER,
Expand Down
7 changes: 0 additions & 7 deletions components/segmenter/src/grapheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,6 @@ pub struct GraphemeClusterSegmenter {
payload: DataPayload<GraphemeClusterBreakDataV2Marker>,
}

#[cfg(feature = "compiled_data")]
impl Default for GraphemeClusterSegmenter {
fn default() -> Self {
Self::new()
}
}

impl GraphemeClusterSegmenter {
/// Constructs a [`GraphemeClusterSegmenter`] with an invariant locale from compiled data.
///
Expand Down
7 changes: 0 additions & 7 deletions components/segmenter/src/sentence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ pub struct SentenceSegmenter {
payload_locale_override: Option<DataPayload<SentenceBreakDataOverrideV1Marker>>,
}

#[cfg(feature = "compiled_data")]
impl Default for SentenceSegmenter {
fn default() -> Self {
Self::new()
}
}

impl SentenceSegmenter {
/// Constructs a [`SentenceSegmenter`] with an invariant locale and compiled data.
///
Expand Down

0 comments on commit eb9fe77

Please sign in to comment.