diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 9446afd4b24b0..f5168b4e559e6 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1081,6 +1081,7 @@ impl String { pub const fn as_str(&self) -> &str { // SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error // at construction. + // FIXME(const-hack): just deref `self` instead unsafe { str::from_utf8_unchecked(self.vec.as_slice()) } } @@ -1104,6 +1105,7 @@ impl String { pub const fn as_mut_str(&mut self) -> &mut str { // SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error // at construction. + // FIXME(const-hack): just deref `self` instead unsafe { str::from_utf8_unchecked_mut(self.vec.as_mut_slice()) } } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 7d02a15ed7a51..e8307762bc981 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1572,6 +1572,7 @@ impl Vec { // * We only construct `&mut` references to `self.buf` through `&mut self` methods; borrow- // check ensures that it is not possible to mutably alias `self.buf` within the // returned lifetime. + // FIXME(const-hack): just deref `self` instead unsafe { slice::from_raw_parts(self.as_ptr(), self.len) } } @@ -1604,6 +1605,7 @@ impl Vec { // * We only construct references to `self.buf` through `&self` and `&mut self` methods; // borrow-check ensures that it is not possible to construct a reference to `self.buf` // within the returned lifetime. + // FIXME(const-hack): just deref `self` instead unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) } }