Skip to content

Commit 7807a1b

Browse files
committed
Vec, String: add some missing const-hack comments
1 parent 28b83ee commit 7807a1b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

library/alloc/src/string.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,7 @@ impl String {
10811081
pub const fn as_str(&self) -> &str {
10821082
// SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error
10831083
// at construction.
1084+
// FIXME(const-hack): just deref `self` instead
10841085
unsafe { str::from_utf8_unchecked(self.vec.as_slice()) }
10851086
}
10861087

@@ -1104,6 +1105,7 @@ impl String {
11041105
pub const fn as_mut_str(&mut self) -> &mut str {
11051106
// SAFETY: String contents are stipulated to be valid UTF-8, invalid contents are an error
11061107
// at construction.
1108+
// FIXME(const-hack): just deref `self` instead
11071109
unsafe { str::from_utf8_unchecked_mut(self.vec.as_mut_slice()) }
11081110
}
11091111

library/alloc/src/vec/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,7 @@ impl<T, A: Allocator> Vec<T, A> {
15721572
// * We only construct `&mut` references to `self.buf` through `&mut self` methods; borrow-
15731573
// check ensures that it is not possible to mutably alias `self.buf` within the
15741574
// returned lifetime.
1575+
// FIXME(const-hack): just deref `self` instead
15751576
unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
15761577
}
15771578

@@ -1604,6 +1605,7 @@ impl<T, A: Allocator> Vec<T, A> {
16041605
// * We only construct references to `self.buf` through `&self` and `&mut self` methods;
16051606
// borrow-check ensures that it is not possible to construct a reference to `self.buf`
16061607
// within the returned lifetime.
1608+
// FIXME(const-hack): just deref `self` instead
16071609
unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
16081610
}
16091611

0 commit comments

Comments
 (0)