Rollup merge of #129550 - kornelski:boxasstr, r=joshtriplett,dtolnay · qinheping/verify-rust-std@8ffc170 (original) (raw)

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -93,6 +93,7 @@
93 93 // tidy-alphabetical-start
94 94 #![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
95 95 #![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
96 +#![cfg_attr(test, feature(str_as_str))]
96 97 #![feature(alloc_layout_extra)]
97 98 #![feature(allocator_api)]
98 99 #![feature(array_chunks)]
Original file line number Diff line number Diff line change
@@ -448,7 +448,11 @@ fn test_from_box_str() {
448 448 use std:🧵:String;
449 449
450 450 let s = String::from("foo").into_boxed_str();
451 +assert_eq!((&&&s).as_str(), "foo");
452 +
451 453 let r: Rc<str> = Rc::from(s);
454 +assert_eq!((&r).as_str(), "foo");
455 +assert_eq!(r.as_str(), "foo");
452 456
453 457 assert_eq!(&r[..], "foo");
454 458 }
Original file line number Diff line number Diff line change
@@ -2740,6 +2740,17 @@ impl str {
2740 2740 pub fn substr_range(&self, substr: &str) -> Option<Range<usize>> {
2741 2741 self.as_bytes().subslice_range(substr.as_bytes())
2742 2742 }
2743 +
2744 +/// Returns the same string as a string slice `&str`.
2745 + ///
2746 + /// This method is redundant when used directly on `&str`, but
2747 + /// it helps dereferencing other string-like types to string slices,
2748 + /// for example references to `Box` or `Arc`.
2749 + #[inline]
2750 +#[unstable(feature = "str_as_str", issue = "130366")]
2751 +pub fn as_str(&self) -> &str {
2752 +self
2753 +}
2743 2754 }
2744 2755
2745 2756 #[stable(feature = "rust1", since = "1.0.0")]