From 041c795fa76a2ba9ca286b3d8f6fb7d477673895 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Thu, 2 May 2024 11:57:24 -0700 Subject: [PATCH] More assorted datagen renames (#4854) Part of #4629 --- provider/blob/tests/test_versions.rs | 2 +- provider/datagen/src/bin/icu4x-datagen.rs | 8 +++--- provider/datagen/src/driver.rs | 34 +++++++++++------------ provider/datagen/tests/test-options.rs | 8 +++--- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/provider/blob/tests/test_versions.rs b/provider/blob/tests/test_versions.rs index 269bda809da..e3326bdc9c9 100644 --- a/provider/blob/tests/test_versions.rs +++ b/provider/blob/tests/test_versions.rs @@ -17,7 +17,7 @@ const BLOB_V2: &[u8] = include_bytes!("data/v2.postcard"); fn run_driver(exporter: BlobExporter) -> Result<(), DataError> { DatagenDriver::new() .with_keys([icu_provider::hello_world::HelloWorldV1Marker::KEY]) - .with_locales_and_fallback([LocaleFamily::full()], Default::default()) + .with_locales_and_fallback([LocaleFamily::FULL], Default::default()) .export(&icu_provider::hello_world::HelloWorldProvider, exporter) } diff --git a/provider/datagen/src/bin/icu4x-datagen.rs b/provider/datagen/src/bin/icu4x-datagen.rs index 0c2c014a4a2..c73e7585478 100644 --- a/provider/datagen/src/bin/icu4x-datagen.rs +++ b/provider/datagen/src/bin/icu4x-datagen.rs @@ -336,7 +336,7 @@ fn main() -> eyre::Result<()> { let mut preprocessed_locales = if cli.locales.as_slice() == ["none"] { Some(PreprocessedLocales::LanguageIdentifiers(vec![])) } else if cli.locales.as_slice() == ["full"] || cli.all_locales { - Some(PreprocessedLocales::All) + Some(PreprocessedLocales::Full) } else { if cli.locales.as_slice() == ["all"] { log::warn!( @@ -490,13 +490,13 @@ fn main() -> eyre::Result<()> { enum PreprocessedLocales { LanguageIdentifiers(Vec), - All, + Full, } if cli.without_fallback || matches!(cli.fallback, Fallback::Preresolved) { driver = driver.with_locales_no_fallback( match preprocessed_locales { - Some(PreprocessedLocales::All) => { + Some(PreprocessedLocales::Full) => { eyre::bail!("--without-fallback needs an explicit locale list") } Some(PreprocessedLocales::LanguageIdentifiers(lids)) => lids, @@ -510,7 +510,7 @@ fn main() -> eyre::Result<()> { ); } else { let locale_families = match preprocessed_locales { - Some(PreprocessedLocales::All) => vec![LocaleFamily::full()], + Some(PreprocessedLocales::Full) => vec![LocaleFamily::FULL], Some(PreprocessedLocales::LanguageIdentifiers(lids)) => lids .into_iter() .map(LocaleFamily::with_descendants) diff --git a/provider/datagen/src/driver.rs b/provider/datagen/src/driver.rs index 2c7517e4ca7..b640d47d40d 100644 --- a/provider/datagen/src/driver.rs +++ b/provider/datagen/src/driver.rs @@ -195,15 +195,13 @@ impl LocaleFamily { /// The family containing all locales. /// /// Stylized on the CLI as: "full" - pub const fn full() -> Self { - Self { - langid: None, - annotations: LocaleFamilyAnnotations { - include_ancestors: false, - include_descendants: true, - }, - } - } + pub const FULL: Self = Self { + langid: None, + annotations: LocaleFamilyAnnotations { + include_ancestors: false, + include_descendants: true, + }, + }; pub(crate) fn into_parts(self) -> (Option, LocaleFamilyAnnotations) { (self.langid, self.annotations) @@ -311,7 +309,7 @@ impl FromStr for LocaleFamily { type Err = LocaleFamilyParseError; fn from_str(s: &str) -> Result { if s == "full" { - return Ok(Self::full()); + return Ok(Self::FULL); } let (first, remainder) = s .as_bytes() @@ -637,7 +635,7 @@ impl DatagenDriver { .map(LocaleFamily::with_descendants) .map(LocaleFamily::into_parts) .collect(), - None => [LocaleFamily::full()] + None => [LocaleFamily::FULL] .into_iter() .map(LocaleFamily::into_parts) .collect(), @@ -707,14 +705,14 @@ impl DatagenDriver { let (uses_internal_fallback, deduplication_strategy) = match &locales_fallback { LocalesWithOrWithoutFallback::WithoutFallback { langids } => { - let mut sorted_locales = langids + let mut sorted_locale_strs = langids .iter() .map(|x| x.write_to_string()) .collect::>(); - sorted_locales.sort_unstable(); + sorted_locale_strs.sort_unstable(); log::info!( "Datagen configured without fallback with these locales: {:?}", - sorted_locales + sorted_locale_strs ); (false, DeduplicationStrategy::None) } @@ -735,12 +733,12 @@ impl DatagenDriver { } Some(x) => x, }; - let mut sorted_locales = families + let mut sorted_locale_strs = families .iter() .map(LocaleFamilyBorrowed::from_parts) .map(|family| family.write_to_string().into_owned()) .collect::>(); - sorted_locales.sort_unstable(); + sorted_locale_strs.sort_unstable(); log::info!( "Datagen configured with {}, {}, and these locales: {:?}", if uses_internal_fallback { @@ -754,7 +752,7 @@ impl DatagenDriver { "deduplication retaining base languages", DeduplicationStrategy::None => "no deduplication", }, - sorted_locales + sorted_locale_strs ); (uses_internal_fallback, deduplication_strategy) } @@ -1035,7 +1033,7 @@ fn select_locales_for_key( } } else { // Full locale family: set the bit instead of adding to the set - debug_assert_eq!(annotations, &LocaleFamily::full().annotations); + debug_assert_eq!(annotations, &LocaleFamily::FULL.annotations); include_full = true; None } diff --git a/provider/datagen/tests/test-options.rs b/provider/datagen/tests/test-options.rs index ba5c7db895b..50099bee645 100644 --- a/provider/datagen/tests/test-options.rs +++ b/provider/datagen/tests/test-options.rs @@ -235,7 +235,7 @@ fn all_preferred() { .with_fallback_mode(FallbackMode::PreferredForExporter), DatagenDriver::new() .with_keys([HelloWorldV1Marker::KEY]) - .with_locales_and_fallback([LocaleFamily::full()], Default::default()), + .with_locales_and_fallback([LocaleFamily::FULL], Default::default()), &TestingProvider::with_decimal_symbol_like_data(), ); @@ -280,7 +280,7 @@ fn all_hybrid() { .with_fallback_mode(FallbackMode::Hybrid), DatagenDriver::new() .with_keys([HelloWorldV1Marker::KEY]) - .with_locales_and_fallback([LocaleFamily::full()], { + .with_locales_and_fallback([LocaleFamily::FULL], { let mut options = FallbackOptions::default(); options.deduplication_strategy = Some(DeduplicationStrategy::None); options @@ -329,7 +329,7 @@ fn all_runtime() { .with_fallback_mode(FallbackMode::RuntimeManual), DatagenDriver::new() .with_keys([HelloWorldV1Marker::KEY]) - .with_locales_and_fallback([LocaleFamily::full()], { + .with_locales_and_fallback([LocaleFamily::FULL], { let mut options = FallbackOptions::default(); options.deduplication_strategy = Some(DeduplicationStrategy::Maximal); options @@ -373,7 +373,7 @@ fn all_runtime_retain_base() { let exported = export_to_map_1_5( DatagenDriver::new() .with_keys([HelloWorldV1Marker::KEY]) - .with_locales_and_fallback([LocaleFamily::full()], { + .with_locales_and_fallback([LocaleFamily::FULL], { let mut options = FallbackOptions::default(); options.deduplication_strategy = Some(DeduplicationStrategy::RetainBaseLanguages); options