The Release team would like assistance verifying and finding potential problems introduced by the patch contained in https://github.com/rust-lang/rust/pull/52232. Specifically, please update your nightly locally today, and either use Rust normally, or, if you’re willing to put in a little extra effort, try out variants of the reported regression which we’re fixing.
If you find any problems, please let us know on the GitHub issue tracking the stable backport process: https://github.com/rust-lang/rust/issues/52312.
As some starter code, you can try to alter the following couple of snippets to try and introduce uncaught, unsound behavior.
enum Inner {
Stack {
data: [u8;23]
},
Heap {
capacity: usize,
data: *mut u8
}
}
struct SmallString {
len: usize,
inner: Inner
}
impl SmallString {
fn push_str(&mut self, item: &str) {
match (&mut self.inner, self.len + item.len()) {
(Inner::Heap { capacity, ref data }, x) => {
if x > *capacity {
self.grow();
// data is now null pointer
}
unsafe {
::std::ptr::copy_nonoverlapping(item.as_ptr(), data.add(self.len), item.len())
}
},
_ => ()
}
}
fn grow(&mut self){
// Invalidate borrowed Heap.data
self.inner = Inner::Stack { data: [0;23] };
}
}
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t, ()) {
((t,), ()) => t,
}
}
fn main() {
let x = {
let y = Box::new((42,));
transmute_lifetime(&y)
};
println!("{}", x);
}