diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
commit | 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch) | |
tree | d325add32978dbdc1db975a438b3a77d571b1ab8 /vendor/icu_provider/src | |
parent | Releasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/icu_provider/src')
-rw-r--r-- | vendor/icu_provider/src/any.rs | 60 | ||||
-rw-r--r-- | vendor/icu_provider/src/buf.rs | 6 | ||||
-rw-r--r-- | vendor/icu_provider/src/constructors.rs | 6 | ||||
-rw-r--r-- | vendor/icu_provider/src/datagen/mod.rs | 2 | ||||
-rw-r--r-- | vendor/icu_provider/src/error.rs | 12 | ||||
-rw-r--r-- | vendor/icu_provider/src/hello_world.rs | 2 | ||||
-rw-r--r-- | vendor/icu_provider/src/key.rs | 6 | ||||
-rw-r--r-- | vendor/icu_provider/src/lib.rs | 2 | ||||
-rw-r--r-- | vendor/icu_provider/src/request.rs | 40 | ||||
-rw-r--r-- | vendor/icu_provider/src/response.rs | 10 | ||||
-rw-r--r-- | vendor/icu_provider/src/serde/mod.rs | 18 |
11 files changed, 107 insertions, 57 deletions
diff --git a/vendor/icu_provider/src/any.rs b/vendor/icu_provider/src/any.rs index 1c7a60435..989438c6b 100644 --- a/vendor/icu_provider/src/any.rs +++ b/vendor/icu_provider/src/any.rs @@ -18,7 +18,7 @@ use alloc::rc::Rc as SelectedRc; use alloc::sync::Arc as SelectedRc; /// A trait that allows to specify `Send + Sync` bounds that are only required when -/// the `sync` feature is enabled. Without the feature, this is an empty bound. +/// the `sync` Cargo feature is enabled. Without the Cargo feature, this is an empty bound. #[cfg(feature = "sync")] pub trait MaybeSendSync: Send + Sync {} #[cfg(feature = "sync")] @@ -115,6 +115,19 @@ impl AnyPayload { } } + /// Clones and then transforms a type-erased `AnyPayload` into a concrete `DataPayload<M>`. + pub fn downcast_cloned<M>(&self) -> Result<DataPayload<M>, DataError> + where + M: DataMarker + 'static, + // For the StructRef case: + M::Yokeable: ZeroFrom<'static, M::Yokeable>, + // For the PayloadRc case: + M::Yokeable: MaybeSendSync, + for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone, + { + self.clone().downcast() + } + /// Creates an `AnyPayload` from a static reference to a data struct. /// /// # Examples @@ -230,7 +243,7 @@ impl From<AnyResponse> for DataResponse<AnyMarker> { } impl AnyResponse { - /// Transforms a type-erased `DataResponse<AnyMarker>` into a concrete `DataResponse<M>`. + /// Transforms a type-erased `AnyResponse` into a concrete `DataResponse<M>`. #[inline] pub fn downcast<M>(self) -> Result<DataResponse<M>, DataError> where @@ -244,6 +257,39 @@ impl AnyResponse { payload: self.payload.map(|p| p.downcast()).transpose()?, }) } + + /// Clones and then transforms a type-erased `AnyResponse` into a concrete `DataResponse<M>`. + pub fn downcast_cloned<M>(&self) -> Result<DataResponse<M>, DataError> + where + M: DataMarker + 'static, + M::Yokeable: ZeroFrom<'static, M::Yokeable>, + M::Yokeable: MaybeSendSync, + for<'a> YokeTraitHack<<M::Yokeable as Yokeable<'a>>::Output>: Clone, + { + Ok(DataResponse { + metadata: self.metadata.clone(), + payload: self + .payload + .as_ref() + .map(|p| p.downcast_cloned()) + .transpose()?, + }) + } +} + +impl<M> DataResponse<M> +where + M: DataMarker + 'static, + M::Yokeable: MaybeSendSync, +{ + /// Moves the inner DataPayload to the heap (requiring an allocation) and returns it as an + /// erased `AnyResponse`. + pub fn wrap_into_any_response(self) -> AnyResponse { + AnyResponse { + metadata: self.metadata, + payload: self.payload.map(|p| p.wrap_into_any_payload()), + } + } } /// An object-safe data provider that returns data structs cast to `dyn Any` trait objects. @@ -345,7 +391,10 @@ where { #[inline] fn load(&self, req: DataRequest) -> Result<DataResponse<M>, DataError> { - self.0.load_any(M::KEY, req)?.downcast() + self.0 + .load_any(M::KEY, req)? + .downcast() + .map_err(|e| e.with_req(M::KEY, req)) } } @@ -359,7 +408,10 @@ where { #[inline] fn load_data(&self, key: DataKey, req: DataRequest) -> Result<DataResponse<M>, DataError> { - self.0.load_any(key, req)?.downcast() + self.0 + .load_any(key, req)? + .downcast() + .map_err(|e| e.with_req(key, req)) } } diff --git a/vendor/icu_provider/src/buf.rs b/vendor/icu_provider/src/buf.rs index 73bc0f165..796ad32f3 100644 --- a/vendor/icu_provider/src/buf.rs +++ b/vendor/icu_provider/src/buf.rs @@ -21,7 +21,11 @@ impl DataMarker for BufferMarker { /// /// Generally, these bytes are expected to be deserializable with Serde. To get an object /// implementing [`DataProvider`] via Serde, use [`as_deserializing()`], which requires -/// enabling at least one of the Serde features. +/// enabling at least one of the deserialization Cargo features: +/// +/// - `deserialize_json` +/// - `deserialize_postcard_1` +/// - `deserialize_bincode_1` /// /// Along with [`DataProvider`], this is one of the two foundational traits in this crate. /// diff --git a/vendor/icu_provider/src/constructors.rs b/vendor/icu_provider/src/constructors.rs index a9330c3f2..053da0320 100644 --- a/vendor/icu_provider/src/constructors.rs +++ b/vendor/icu_provider/src/constructors.rs @@ -54,7 +54,7 @@ //! 2. [`FsDataProvider`] //! 3. [`ForkByKeyProvider`] between any of the above //! -//! Please note that you must enable the `"serde"` feature on each crate in which you use the +//! Please note that you must enable the `"serde"` Cargo feature on each crate in which you use the //! `*_with_buffer_provider` constructor. //! //! # Data Versioning Policy @@ -78,8 +78,8 @@ //! Over FFI, there is only one data provider type: [`ICU4XDataProvider`]. Internally, it is an //! `enum` between `dyn `[`AnyProvider`] and `dyn `[`BufferProvider`]. //! -//! To control for code size, there are two features, `any_provider` and `buffer_provider`, that -//! enable the corresponding items in the enum. +//! To control for code size, there are two Cargo features, `any_provider` and `buffer_provider`, +//! that enable the corresponding items in the enum. //! //! In Rust ICU4X, a similar buffer/any enum approach was not taken because: //! diff --git a/vendor/icu_provider/src/datagen/mod.rs b/vendor/icu_provider/src/datagen/mod.rs index 5ede82275..e52a19c4d 100644 --- a/vendor/icu_provider/src/datagen/mod.rs +++ b/vendor/icu_provider/src/datagen/mod.rs @@ -6,7 +6,7 @@ //! via the `icu_datagen` reference crate. End users should not need to consume anything in //! this module as a library unless defining new types that integrate with `icu_datagen`. //! -//! This module can be enabled with the `datagen` feature on `icu_provider`. +//! This module can be enabled with the `datagen` Cargo feature on `icu_provider`. mod data_conversion; mod heap_measure; diff --git a/vendor/icu_provider/src/error.rs b/vendor/icu_provider/src/error.rs index 39bd1d0bb..05a48f9b7 100644 --- a/vendor/icu_provider/src/error.rs +++ b/vendor/icu_provider/src/error.rs @@ -64,8 +64,8 @@ pub enum DataErrorKind { MissingSourceData, /// An error indicating that the desired buffer format is not available. This usually - /// means that a required feature was not enabled - #[displaydoc("Unavailable buffer format: {0:?} (does icu_provider need to be compiled with an additional feature?)")] + /// means that a required Cargo feature was not enabled + #[displaydoc("Unavailable buffer format: {0:?} (does icu_provider need to be compiled with an additional Cargo feature?)")] UnavailableBufferFormat(BufferFormat), } @@ -196,7 +196,7 @@ impl DataError { /// Logs the data error with the given request, returning an error containing the resource key. /// - /// If the "log_error_context" feature is enabled, this logs the whole request. Either way, + /// If the "log_error_context" Cargo feature is enabled, this logs the whole request. Either way, /// it returns an error with the resource key portion of the request as context. #[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))] pub fn with_req(self, key: DataKey, req: DataRequest) -> Self { @@ -210,7 +210,7 @@ impl DataError { /// Logs the data error with the given context, then return self. /// - /// This does not modify the error, but if the "log_error_context" feature is enabled, + /// This does not modify the error, but if the "log_error_context" Cargo feature is enabled, /// it will print out the context. #[cfg(feature = "std")] #[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))] @@ -222,7 +222,7 @@ impl DataError { /// Logs the data error with the given context, then return self. /// - /// This does not modify the error, but if the "log_error_context" feature is enabled, + /// This does not modify the error, but if the "log_error_context" Cargo feature is enabled, /// it will print out the context. #[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))] #[inline] @@ -234,7 +234,7 @@ impl DataError { /// Logs the data error with the given context, then return self. /// - /// This does not modify the error, but if the "log_error_context" feature is enabled, + /// This does not modify the error, but if the "log_error_context" Cargo feature is enabled, /// it will print out the context. #[cfg_attr(not(feature = "log_error_context"), allow(unused_variables))] #[inline] diff --git a/vendor/icu_provider/src/hello_world.rs b/vendor/icu_provider/src/hello_world.rs index 5fa671d84..7fd8289df 100644 --- a/vendor/icu_provider/src/hello_world.rs +++ b/vendor/icu_provider/src/hello_world.rs @@ -266,6 +266,8 @@ impl<'l> Writeable for FormattedHelloWorld<'l> { } } +writeable::impl_display_with_writeable!(FormattedHelloWorld<'_>); + #[cfg(feature = "datagen")] impl IterableDataProvider<HelloWorldV1Marker> for HelloWorldProvider { fn supported_locales(&self) -> Result<Vec<DataLocale>, DataError> { diff --git a/vendor/icu_provider/src/key.rs b/vendor/icu_provider/src/key.rs index 2f55e4d46..d4d6905c9 100644 --- a/vendor/icu_provider/src/key.rs +++ b/vendor/icu_provider/src/key.rs @@ -140,11 +140,6 @@ impl DataKeyPath { /// Gets the path as a static string slice. #[inline] pub const fn get(self) -> &'static str { - /// core::slice::from_raw_parts(a, b) = core::mem::transmute((a, b)) hack - /// ```compile_fail - /// const unsafe fn canary() { core::slice::from_raw_parts(0 as *const u8, 0); } - /// ``` - const _: () = (); unsafe { // Safe due to invariant that self.path is tagged correctly core::str::from_utf8_unchecked(core::mem::transmute(( @@ -624,7 +619,6 @@ fn test_key_to_string() { expected: "core/cardinal@65535", }, ] { - assert_eq!(cas.expected, cas.key.to_string()); writeable::assert_writeable_eq!(&cas.key, cas.expected); } } diff --git a/vendor/icu_provider/src/lib.rs b/vendor/icu_provider/src/lib.rs index 594e872f4..7ee5b34e2 100644 --- a/vendor/icu_provider/src/lib.rs +++ b/vendor/icu_provider/src/lib.rs @@ -94,7 +94,7 @@ //! //! ## Data generation API //! -//! *This functionality is enabled with the "datagen" feature* +//! *This functionality is enabled with the "datagen" Cargo feature* //! //! The [`datagen`] module contains several APIs for data generation. See [`icu_datagen`] for the reference //! data generation implementation. diff --git a/vendor/icu_provider/src/request.rs b/vendor/icu_provider/src/request.rs index 7f6bb5911..5f51f3a2c 100644 --- a/vendor/icu_provider/src/request.rs +++ b/vendor/icu_provider/src/request.rs @@ -53,11 +53,11 @@ pub struct DataRequestMetadata; /// use icu_locid::locale; /// use icu_provider::DataLocale; /// -/// let locale1 = locale!("en-u-ca-buddhist"); -/// let data_locale = DataLocale::from(locale1); -/// let locale2 = data_locale.into_locale(); +/// let locale = locale!("en-u-ca-buddhist"); +/// let data_locale = DataLocale::from(locale); +/// let locale = data_locale.into_locale(); /// -/// assert_eq!(locale2.to_string(), "en-u-ca-buddhist"); +/// assert_eq!(locale, locale!("en-u-ca-buddhist")); /// ``` /// /// You can alternatively create a [`DataLocale`] from a borrowed [`Locale`], which is more @@ -81,18 +81,18 @@ pub struct DataRequestMetadata; /// use icu_locid::langid; /// use icu_provider::DataLocale; /// -/// let langid1 = langid!("es-CA-valencia"); -/// let data_locale = DataLocale::from(langid1); -/// let langid2 = data_locale.get_langid(); +/// let langid = langid!("es-CA-valencia"); +/// let data_locale = DataLocale::from(langid); +/// let langid = data_locale.get_langid(); /// -/// assert_eq!(langid2.to_string(), "es-CA-valencia"); +/// assert_eq!(langid, langid!("es-CA-valencia")); /// ``` /// /// [`DataLocale`] only supports `-u` keywords, to reflect the current state of CLDR data /// lookup and fallback. This may change in the future. /// /// ``` -/// use icu_locid::Locale; +/// use icu_locid::{locale, Locale}; /// use icu_provider::DataLocale; /// /// let locale = "hi-t-en-h0-hybrid-u-attr-ca-buddhist" @@ -100,7 +100,7 @@ pub struct DataRequestMetadata; /// .unwrap(); /// let data_locale = DataLocale::from(locale); /// -/// assert_eq!(data_locale.to_string(), "hi-u-ca-buddhist"); +/// assert_eq!(data_locale.into_locale(), locale!("hi-u-ca-buddhist")); /// ``` #[derive(PartialEq, Clone, Default, Eq, Hash)] pub struct DataLocale { @@ -225,7 +225,6 @@ impl DataLocale { /// let b = ab[1]; /// assert!(a.cmp(b) == Ordering::Less); /// let a_loc: DataLocale = a.parse::<Locale>().unwrap().into(); - /// assert_eq!(a, a_loc.to_string()); /// assert!( /// a_loc.strict_cmp(a.as_bytes()) == Ordering::Equal, /// "{} == {}", @@ -239,7 +238,6 @@ impl DataLocale { /// b /// ); /// let b_loc: DataLocale = b.parse::<Locale>().unwrap().into(); - /// assert_eq!(b, b_loc.to_string()); /// assert!( /// b_loc.strict_cmp(b.as_bytes()) == Ordering::Equal, /// "{} == {}", @@ -338,21 +336,20 @@ impl DataLocale { /// /// ``` /// use icu_locid::{ - /// langid, subtags_language as language, subtags_region as region, Locale, + /// langid, locale, subtags_language as language, subtags_region as region, + /// Locale, /// }; /// use icu_provider::prelude::*; /// - /// let locale: Locale = "it-IT-u-ca-coptic".parse().expect("Valid BCP-47"); - /// let locale: DataLocale = locale.into(); + /// let locale: DataLocale = locale!("it-IT-u-ca-coptic").into(); /// - /// assert_eq!(locale.to_string(), "it-IT-u-ca-coptic"); /// assert_eq!(locale.get_langid(), langid!("it-IT")); /// assert_eq!(locale.language(), language!("it")); /// assert_eq!(locale.script(), None); /// assert_eq!(locale.region(), Some(region!("IT"))); /// /// let locale = locale.into_locale(); - /// assert_eq!(locale.to_string(), "it-IT-u-ca-coptic"); + /// assert_eq!(locale, locale!("it-IT-u-ca-coptic")); /// ``` pub fn into_locale(self) -> Locale { let mut loc = Locale { @@ -488,6 +485,8 @@ impl DataLocale { #[test] fn test_data_locale_to_string() { + use icu_locid::locale; + struct TestCase { pub locale: DataLocale, pub expected: &'static str, @@ -499,15 +498,14 @@ fn test_data_locale_to_string() { expected: "und", }, TestCase { - locale: "und-u-cu-gbp".parse::<Locale>().unwrap().into(), + locale: locale!("und-u-cu-gbp").into(), expected: "und-u-cu-gbp", }, TestCase { - locale: "en-ZA-u-cu-gbp".parse::<Locale>().unwrap().into(), + locale: locale!("en-ZA-u-cu-gbp").into(), expected: "en-ZA-u-cu-gbp", }, ] { - assert_eq!(cas.expected, cas.locale.to_string()); - writeable::assert_writeable_eq!(&cas.locale, cas.expected); + writeable::assert_writeable_eq!(cas.locale, cas.expected); } } diff --git a/vendor/icu_provider/src/response.rs b/vendor/icu_provider/src/response.rs index 653d20a68..1ea6c8a76 100644 --- a/vendor/icu_provider/src/response.rs +++ b/vendor/icu_provider/src/response.rs @@ -51,10 +51,10 @@ pub struct DataResponseMetadata { /// To transform a [`DataPayload`] to a different type backed by the same data store (cart), use /// [`DataPayload::map_project()`] or one of its sister methods. /// -/// # `sync` feature +/// # Cargo feature: `sync` /// /// By default, the payload uses non-concurrent reference counting internally, and hence is neither -/// [`Sync`] nor [`Send`]; if these traits are required, the `sync` feature can be enabled. +/// [`Sync`] nor [`Send`]; if these traits are required, the `sync` Cargo feature can be enabled. /// /// # Examples /// @@ -183,7 +183,7 @@ where /// use std::borrow::Cow; /// /// let local_struct = HelloWorldV1 { - /// message: Cow::Owned("example".to_string()), + /// message: Cow::Owned("example".to_owned()), /// }; /// /// let payload = @@ -236,8 +236,8 @@ where /// let mut payload = /// DataPayload::<HelloWorldV1Marker>::from_static_str("Hello"); /// - /// let suffix = " World".to_string(); - /// payload.with_mut(move |s| s.message.to_mut().push_str(&suffix)); + /// let suffix = " World"; + /// payload.with_mut(move |s| s.message.to_mut().push_str(suffix)); /// /// assert_eq!("Hello World", payload.get().message); /// ``` diff --git a/vendor/icu_provider/src/serde/mod.rs b/vendor/icu_provider/src/serde/mod.rs index d32148f02..2e96b3cb3 100644 --- a/vendor/icu_provider/src/serde/mod.rs +++ b/vendor/icu_provider/src/serde/mod.rs @@ -94,7 +94,7 @@ impl DataPayload<BufferMarker> { /// /// # Examples /// - /// Requires the `deserialize_json` feature: + /// Requires the `deserialize_json` Cargo feature: /// /// ``` /// use icu_provider::buf::BufferFormat; @@ -136,16 +136,16 @@ where { fn load_data(&self, key: DataKey, req: DataRequest) -> Result<DataResponse<M>, DataError> { let buffer_response = BufferProvider::load_buffer(self.0, key, req)?; - let buffer_format = buffer_response - .metadata - .buffer_format - .ok_or_else(|| DataError::custom("BufferProvider didn't set BufferFormat"))?; + let buffer_format = buffer_response.metadata.buffer_format.ok_or_else(|| { + DataError::custom("BufferProvider didn't set BufferFormat").with_req(key, req) + })?; Ok(DataResponse { metadata: buffer_response.metadata, payload: buffer_response .payload .map(|p| p.into_deserialized(buffer_format)) - .transpose()?, + .transpose() + .map_err(|e| e.with_req(key, req))?, }) } } @@ -165,21 +165,21 @@ where } } -#[cfg(feature = "serde_json")] +#[cfg(feature = "deserialize_json")] impl From<serde_json::error::Error> for crate::DataError { fn from(e: serde_json::error::Error) -> Self { crate::DataError::custom("JSON deserialize").with_display_context(&e) } } -#[cfg(feature = "bincode")] +#[cfg(feature = "deserialize_bincode_1")] impl From<bincode::Error> for crate::DataError { fn from(e: bincode::Error) -> Self { crate::DataError::custom("Bincode deserialize").with_display_context(&e) } } -#[cfg(feature = "postcard")] +#[cfg(feature = "deserialize_postcard_1")] impl From<postcard::Error> for crate::DataError { fn from(e: postcard::Error) -> Self { crate::DataError::custom("Postcard deserialize").with_display_context(&e) |