about summary refs log tree commit diff
path: root/library/alloc/src
diff options
context:
space:
mode:
authorKornel <kornel@geekhood.net>2024-08-25 11:20:42 +0100
committerKornel <kornel@geekhood.net>2024-09-19 16:25:56 +0100
commit3dcb5a39622fe705647ea0764a355a10b6913832 (patch)
tree25eade9fd25534578ef23216f99198f7f8f05fc4 /library/alloc/src
parentb0af276da341bcd3fbfe71871aeacc8650f344ed (diff)
Add str.as_str() for easy dereferencing of Box<str>
Diffstat (limited to 'library/alloc/src')
-rw-r--r--library/alloc/src/lib.rs1
-rw-r--r--library/alloc/src/rc/tests.rs4
2 files changed, 5 insertions, 0 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index f0597f295b3..ff5ddd16e07 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -93,6 +93,7 @@
 // tidy-alphabetical-start
 #![cfg_attr(not(no_global_oom_handling), feature(const_alloc_error))]
 #![cfg_attr(not(no_global_oom_handling), feature(const_btree_len))]
+#![cfg_attr(test, feature(str_as_str))]
 #![feature(alloc_layout_extra)]
 #![feature(allocator_api)]
 #![feature(array_chunks)]
diff --git a/library/alloc/src/rc/tests.rs b/library/alloc/src/rc/tests.rs
index 84e8b325f71..333e1bde31c 100644
--- a/library/alloc/src/rc/tests.rs
+++ b/library/alloc/src/rc/tests.rs
@@ -448,7 +448,11 @@ fn test_from_box_str() {
     use std::string::String;
 
     let s = String::from("foo").into_boxed_str();
+    assert_eq!((&&&s).as_str(), "foo");
+
     let r: Rc<str> = Rc::from(s);
+    assert_eq!((&r).as_str(), "foo");
+    assert_eq!(r.as_str(), "foo");
 
     assert_eq!(&r[..], "foo");
 }