@@ -2732,6 +2732,10 @@ impl<A: Allocator> From<Box<str, A>> for String<A> {
2732
2732
}
2733
2733
}
2734
2734
2735
+ // When compiling in test mode, `Box` is not actually local, so this impl is incoherent
2736
+ // since `A` is the "main" type.
2737
+ // To work around this, restrict this impl to `A = Global` under cfg(test).
2738
+ #[ cfg( not( test) ) ]
2735
2739
#[ cfg( not( no_global_oom_handling) ) ]
2736
2740
#[ stable( feature = "box_from_str" , since = "1.20.0" ) ]
2737
2741
impl < A : Allocator > From < String < A > > for Box < str , A > {
@@ -2751,6 +2755,27 @@ impl<A: Allocator> From<String<A>> for Box<str, A> {
2751
2755
}
2752
2756
}
2753
2757
2758
+ // See above `impl<A: Allocator> From<String<A>> for Box<str, A>`
2759
+ #[ cfg( test) ]
2760
+ #[ cfg( not( no_global_oom_handling) ) ]
2761
+ #[ stable( feature = "box_from_str" , since = "1.20.0" ) ]
2762
+ impl From < String > for Box < str > {
2763
+ /// Converts the given [`String`] to a boxed `str` slice that is owned.
2764
+ ///
2765
+ /// # Examples
2766
+ ///
2767
+ /// ```
2768
+ /// let s1: String = String::from("hello world");
2769
+ /// let s2: Box<str> = Box::from(s1);
2770
+ /// let s3: String = String::from(s2);
2771
+ ///
2772
+ /// assert_eq!("hello world", s3)
2773
+ /// ```
2774
+ fn from ( s : String ) -> Box < str > {
2775
+ s. into_boxed_str ( )
2776
+ }
2777
+ }
2778
+
2754
2779
#[ cfg( not( no_global_oom_handling) ) ]
2755
2780
#[ stable( feature = "string_from_cow_str" , since = "1.14.0" ) ]
2756
2781
impl < ' a > From < Cow < ' a , str > > for String {
0 commit comments