Skip to content

Commit d25589f

Browse files
committed
Auto merge of #1307 - RalfJung:vec-extend, r=RalfJung
also test push_str ptr stability (the original report)
2 parents 350004f + 177c0d3 commit d25589f

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/run-pass/vec.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,14 @@ fn vec_truncate_ptr_stable() {
104104
let _val = *v0;
105105
}
106106

107+
fn push_str_ptr_stable() {
108+
let mut buf = String::with_capacity(11);
109+
buf.push_str("hello");
110+
let hello: &str = unsafe { &*(buf.as_str() as *const _) }; // laundering the lifetime -- we take care that `buf` does not reallocate, so that's okay.
111+
buf.push_str(" world");
112+
assert_eq!(format!("{}", hello), "hello");
113+
}
114+
107115
fn main() {
108116
assert_eq!(vec_reallocate().len(), 5);
109117

@@ -127,4 +135,5 @@ fn main() {
127135
vec_push_ptr_stable();
128136
vec_extend_ptr_stable();
129137
vec_truncate_ptr_stable();
138+
push_str_ptr_stable();
130139
}

0 commit comments

Comments
 (0)