From a3cd28bd469a81ae720ba3af2c03b3a38cf85c06 Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Tue, 14 Nov 2023 20:48:18 +0100 Subject: [PATCH 1/2] msrv --- provider/datagen/src/baked_exporter.rs | 33 +++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/provider/datagen/src/baked_exporter.rs b/provider/datagen/src/baked_exporter.rs index 9165820018c..70314255efe 100644 --- a/provider/datagen/src/baked_exporter.rs +++ b/provider/datagen/src/baked_exporter.rs @@ -109,7 +109,16 @@ macro_rules! move_out { // TokenStream isn't Send/Sync type SyncTokenStream = String; -const MSRV: &str = std::env!("CARGO_PKG_RUST_VERSION"); +// Produces an MSRV clippy annotation if the `CARGO_PKG_RUST_VERSION` is set. +fn maybe_msrv() -> TokenStream { + std::option_env!("CARGO_PKG_RUST_VERSION") + .map(|msrv| { + quote! { + #[clippy::msrv = #msrv] + } + }) + .unwrap_or_default() +} /// Options for configuring the output of [`BakedExporter`]. #[non_exhaustive] @@ -288,6 +297,8 @@ impl BakedExporter { let prefixed_macro_ident = format!("__impl_{ident}").parse::().unwrap(); + let maybe_msrv = maybe_msrv(); + self.write_to_file( PathBuf::from(format!("macros/{}.rs.data", ident)), quote! { @@ -298,7 +309,7 @@ impl BakedExporter { #[macro_export] macro_rules! #prefixed_macro_ident { ($provider:ty) => { - #[clippy::msrv = #MSRV] + #maybe_msrv const _: () = <$provider>::MUST_USE_MAKE_PROVIDER_MACRO; #body } @@ -355,15 +366,17 @@ impl DataExporter for BakedExporter { let bake = payload.tokenize(&self.dependencies); + let maybe_msrv = maybe_msrv(); + self.write_impl_macro(quote! { - #[clippy::msrv = #MSRV] + #maybe_msrv impl $provider { // Exposing singleton structs as consts allows us to get rid of fallibility #[doc(hidden)] pub const #singleton_ident: &'static <#marker as icu_provider::DataMarker>::Yokeable = &#bake; } - #[clippy::msrv = #MSRV] + #maybe_msrv impl icu_provider::DataProvider<#marker> for $provider { fn load( &self, @@ -450,6 +463,8 @@ impl BakedExporter { .remove(&key) .unwrap_or_default(); + let maybe_msrv = maybe_msrv(); + let body = if values.is_empty() { quote!(Err(icu_provider::DataErrorKind::MissingLocale.with_req(<#marker as icu_provider::KeyedDataMarker>::KEY, req))) } else { @@ -559,7 +574,7 @@ impl BakedExporter { self.write_impl_macro( quote! { - #[clippy::msrv = #MSRV] + #maybe_msrv impl icu_provider::DataProvider<#marker> for $provider { fn load( &self, @@ -624,6 +639,8 @@ impl BakedExporter { ) })); + let maybe_msrv = maybe_msrv(); + // macros.rs is the interface for built-in data. It exposes one macro per data key. self.write_to_file( PathBuf::from("macros.rs"), @@ -643,7 +660,7 @@ impl BakedExporter { #[macro_export] macro_rules! __make_provider { ($name:ty) => { - #[clippy::msrv = #MSRV] + #maybe_msrv impl $name { #[doc(hidden)] #[allow(dead_code)] @@ -686,7 +703,7 @@ impl BakedExporter { #[allow(unused_macros)] macro_rules! impl_any_provider { ($provider:ty) => { - #[clippy::msrv = #MSRV] + #maybe_msrv impl icu_provider::AnyProvider for $provider { fn load_any(&self, key: icu_provider::DataKey, req: icu_provider::DataRequest) -> Result { match key.hashed() { @@ -703,7 +720,7 @@ impl BakedExporter { } // For backwards compatibility - #[clippy::msrv = #MSRV] + #maybe_msrv pub struct BakedDataProvider; impl_data_provider!(BakedDataProvider); }, From a6a5201eff98088e32c397c1baf6ce6fe81275aa Mon Sep 17 00:00:00 2001 From: Robert Bastian <4706271+robertbastian@users.noreply.github.com> Date: Tue, 14 Nov 2023 21:18:02 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 386014ec258..e343e229e86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ - New CLI option `--format=blob2` (https://github.com/unicode-org/icu4x/pull/4207) - CLDR 44 compatibility fixes (https://github.com/unicode-org/icu4x/pull/4134, https://github.com/unicode-org/icu4x/pull/4156, https://github.com/unicode-org/icu4x/pull/4158) - Fix `supported_locales` for collator keys (https://github.com/unicode-org/icu4x/pull/4169) + - Make datagen work without `CARGO_PKG_RUST_VERSION` environment variable (https://github.com/unicode-org/icu4x/pull/4292) - Utilities - `databake` - Improvements `databake::test_bake!()` (https://github.com/unicode-org/icu4x/pull/4182)