From 296a04a27427b0d1c1b9f4c619facc0205e19b8c Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Thu, 24 Mar 2022 17:55:21 -0700 Subject: [PATCH 1/3] Run docs tests that failed prior to Rust 1.57 --- provider/core/src/data_provider.rs | 85 ++---------------------------- utils/yoke/src/yoke.rs | 10 +--- 2 files changed, 7 insertions(+), 88 deletions(-) diff --git a/provider/core/src/data_provider.rs b/provider/core/src/data_provider.rs index 30a86f99abe..b1d2e97a5fe 100644 --- a/provider/core/src/data_provider.rs +++ b/provider/core/src/data_provider.rs @@ -455,10 +455,7 @@ where /// /// Same example as above, but this time, do not move out of `p1`: /// - /// ***[#1061](https://github.com/unicode-org/icu4x/issues/1061): The following example - /// requires Rust 1.57.*** - /// - /// ```ignore + /// ``` /// // Same imports and definitions as above /// # use icu_provider::hello_world::*; /// # use icu_provider::prelude::*; @@ -504,10 +501,7 @@ where /// /// Capture a string from the context and append it to the message: /// - /// ***[#1061](https://github.com/unicode-org/icu4x/issues/1061): The following example - /// requires Rust 1.57.*** - /// - /// ```ignore + /// ``` /// // Same imports and definitions as above /// # use icu_provider::hello_world::*; /// # use icu_provider::prelude::*; @@ -532,34 +526,6 @@ where /// /// assert_eq!("Hello WorldExtra", p2.get()); /// ``` - /// - /// Prior to Rust 1.57, pass the capture by value instead of by reference: - /// - /// ``` - /// // Same imports and definitions as above - /// # use icu_provider::hello_world::*; - /// # use icu_provider::prelude::*; - /// # use std::borrow::Cow; - /// # struct HelloWorldV1MessageMarker; - /// # impl DataMarker for HelloWorldV1MessageMarker { - /// # type Yokeable = Cow<'static, str>; - /// # } - /// - /// let p1: DataPayload = DataPayload::from_owned(HelloWorldV1 { - /// message: Cow::Borrowed("Hello World") - /// }); - /// - /// assert_eq!("Hello World", p1.get().message); - /// - /// let p2: DataPayload = p1.map_project_with_capture( - /// "Extra".to_string(), - /// |mut obj, capture, _| { - /// obj.message.to_mut().push_str(&capture); - /// obj.message - /// }); - /// - /// assert_eq!("Hello WorldExtra", p2.get()); - /// ``` #[allow(clippy::type_complexity)] pub fn map_project_with_capture( self, @@ -585,10 +551,7 @@ where /// /// Same example as above, but this time, do not move out of `p1`: /// - /// ***[#1061](https://github.com/unicode-org/icu4x/issues/1061): The following example - /// requires Rust 1.57.*** - /// - /// ```ignore + /// ``` /// // Same imports and definitions as above /// # use icu_provider::hello_world::*; /// # use icu_provider::prelude::*; @@ -641,10 +604,7 @@ where /// /// Same example as above, but bubble up an error: /// - /// ***[#1061](https://github.com/unicode-org/icu4x/issues/1061): The following example - /// requires Rust 1.57.*** - /// - /// ```ignore + /// ``` /// // Same imports and definitions as above /// # use icu_provider::hello_world::*; /// # use icu_provider::prelude::*; @@ -673,38 +633,6 @@ where /// assert_eq!("Hello WorldExtra", p2.get()); /// # Ok::<(), &'static str>(()) /// ``` - /// - /// Prior to Rust 1.57, pass the capture by value instead of by reference: - /// - /// ``` - /// // Same imports and definitions as above - /// # use icu_provider::hello_world::*; - /// # use icu_provider::prelude::*; - /// # use std::borrow::Cow; - /// # struct HelloWorldV1MessageMarker; - /// # impl DataMarker for HelloWorldV1MessageMarker { - /// # type Yokeable = Cow<'static, str>; - /// # } - /// - /// let p1: DataPayload = DataPayload::from_owned(HelloWorldV1 { - /// message: Cow::Borrowed("Hello World") - /// }); - /// - /// assert_eq!("Hello World", p1.get().message); - /// - /// let p2: DataPayload = p1.try_map_project_with_capture( - /// "Extra".to_string(), - /// |mut obj, capture, _| { - /// if obj.message.is_empty() { - /// return Err(()) - /// } - /// obj.message.to_mut().push_str(&capture); - /// Ok(obj.message) - /// })?; - /// - /// assert_eq!("Hello WorldExtra", p2.get()); - /// # Ok::<(), ()>(()) - /// ``` #[allow(clippy::type_complexity)] pub fn try_map_project_with_capture( self, @@ -730,10 +658,7 @@ where /// /// Same example as above, but bubble up an error: /// - /// ***[#1061](https://github.com/unicode-org/icu4x/issues/1061): The following example - /// requires Rust 1.57.*** - /// - /// ```ignore + /// ``` /// // Same imports and definitions as above /// # use icu_provider::hello_world::*; /// # use icu_provider::prelude::*; diff --git a/utils/yoke/src/yoke.rs b/utils/yoke/src/yoke.rs index 578be09e92a..7dca0f89cb7 100644 --- a/utils/yoke/src/yoke.rs +++ b/utils/yoke/src/yoke.rs @@ -592,10 +592,7 @@ impl Yokeable<'a>, C> Yoke { /// /// This can be used, for example, to transform data from one format to another: /// - /// ***[#1061](https://github.com/unicode-org/icu4x/issues/1061): The following example - /// requires Rust 1.56.*** - /// - /// ```rust,ignore + /// ``` /// # use std::rc::Rc; /// # use yoke::Yoke; /// # @@ -607,10 +604,7 @@ impl Yokeable<'a>, C> Yoke { /// /// This can also be used to create a yoke for a subfield /// - /// ***[#1061](https://github.com/unicode-org/icu4x/issues/1061): The following example - /// requires Rust 1.56.*** - /// - /// ```rust,ignore + /// ``` /// # use std::borrow::Cow; /// # use yoke::{Yoke, Yokeable}; /// # use std::mem; From fae33731e9ecf339586b75235ef1ae9596ba0ea9 Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Thu, 24 Mar 2022 18:22:00 -0700 Subject: [PATCH 2/3] Update docs to point to #1061 --- utils/yoke/src/yoke.rs | 51 ++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/utils/yoke/src/yoke.rs b/utils/yoke/src/yoke.rs index 7dca0f89cb7..1432baaca38 100644 --- a/utils/yoke/src/yoke.rs +++ b/utils/yoke/src/yoke.rs @@ -88,9 +88,35 @@ impl Yokeable<'a>, C: StableDeref> Yoke { /// /// See also [`Yoke::try_attach_to_cart()`] to return a `Result` from the closure. /// - /// Due to [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937), call sites - /// for this function may not compile; if this happens, use + /// Call sites for this function may not compile; if this happens, use /// [`Yoke::attach_to_cart_badly()`] instead. + /// + /// # Examples + /// + /// The following code does not currently compile. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). + /// + /// ```compile_fail + /// # use yoke::{Yoke, Yokeable}; + /// # use std::rc::Rc; + /// # use std::borrow::Cow; + /// # fn load_from_cache(_filename: &str) -> Rc<[u8]> { + /// # // dummy implementation + /// # Rc::new([0x5, 0, 0, 0, 0, 0, 0, 0, 0x68, 0x65, 0x6c, 0x6c, 0x6f]) + /// # } + /// + /// fn load_object(filename: &str) -> Yoke, Rc<[u8]>> { + /// let rc: Rc<[u8]> = load_from_cache(filename); + /// Yoke::, Rc<[u8]>>::attach_to_cart(rc, |data: &[u8]| { + /// // essentially forcing a #[serde(borrow)] + /// Cow::Borrowed(bincode::deserialize(data).unwrap()) + /// }) + /// } + /// + /// let yoke: Yoke, _> = load_object("filename.bincode"); + /// assert_eq!(&**yoke.get(), "hello"); + /// assert!(matches!(yoke.get(), &Cow::Borrowed(_))); + /// ``` pub fn attach_to_cart(cart: C, f: F) -> Self where F: for<'de> FnOnce(&'de ::Target) -> >::Output, @@ -105,9 +131,9 @@ impl Yokeable<'a>, C: StableDeref> Yoke { /// Construct a [`Yoke`] by yokeing an object to a cart. If an error occurs in the /// deserializer function, the error is passed up to the caller. /// - /// Due to [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937), call sites - /// for this function may not compile; if this happens, use + /// Call sites for this function may not compile; if this happens, use /// [`Yoke::try_attach_to_cart_badly()`] instead. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). pub fn try_attach_to_cart(cart: C, f: F) -> Result where F: for<'de> FnOnce(&'de ::Target) -> Result<>::Output, E>, @@ -584,11 +610,8 @@ impl Yokeable<'a>, C> Yoke { /// described in [#86702](https://github.com/rust-lang/rust/issues/86702). This parameter /// should just be ignored in the function. /// - /// Furthermore, - /// [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937) prevents - /// this from taking a capturing closure, however [`Yoke::project_with_capture()`] - /// can be used for the same use cases. - /// + /// To capture data and pass it to the closure, use [`Yoke::project_with_capture()`]. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). /// /// This can be used, for example, to transform data from one format to another: /// @@ -688,9 +711,9 @@ impl Yokeable<'a>, C> Yoke { } } - /// This is similar to [`Yoke::project`], however it works around it not being able to - /// use `FnOnce` by using an explicit capture input, until [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937) - /// is fixed. + /// This is similar to [`Yoke::project`], but it works around it not being able to + /// use `FnOnce` by using an explicit capture input. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). /// /// See the docs of [`Yoke::project`] for how this works. pub fn project_with_capture( @@ -713,8 +736,8 @@ impl Yokeable<'a>, C> Yoke { } /// This is similar to [`Yoke::project_cloned`], however it works around it not being able to - /// use `FnOnce` by using an explicit capture input, until [compiler bug #84937](https://github.com/rust-lang/rust/issues/84937) - /// is fixed. + /// use `FnOnce` by using an explicit capture input. + /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). /// /// See the docs of [`Yoke::project_cloned`] for how this works. pub fn project_cloned_with_capture<'this, P, T>( From 95e5304d8a7023a99cba2b66972d9719d4ad3c09 Mon Sep 17 00:00:00 2001 From: Shane Carr Date: Thu, 24 Mar 2022 18:28:06 -0700 Subject: [PATCH 3/3] fmt --- utils/yoke/src/yoke.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/yoke/src/yoke.rs b/utils/yoke/src/yoke.rs index 1432baaca38..8bd3c0340db 100644 --- a/utils/yoke/src/yoke.rs +++ b/utils/yoke/src/yoke.rs @@ -90,12 +90,12 @@ impl Yokeable<'a>, C: StableDeref> Yoke { /// /// Call sites for this function may not compile; if this happens, use /// [`Yoke::attach_to_cart_badly()`] instead. - /// + /// /// # Examples - /// + /// /// The following code does not currently compile. /// See [#1061](https://github.com/unicode-org/icu4x/issues/1061). - /// + /// /// ```compile_fail /// # use yoke::{Yoke, Yokeable}; /// # use std::rc::Rc;