From: bors Date: Thu, 3 Jun 2021 15:42:41 +0000 (+0000) Subject: Auto merge of #1824 - Pointerbender:strings-test, r=RalfJung X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=44122f9ff287f6bf2f1209244631ceb544a8f90a;p=rust.git Auto merge of #1824 - Pointerbender:strings-test, r=RalfJung added a strings.rs regression test case for potential future UB This PR adds a regression test for the aliasing rules of a `Unique` pointer. At the time of writing this test case, Miri does not treat `Unique` pointers as a special case, these are treated like any other raw pointer. However, there are existing Github issues which may lead to `Unique` becoming a special case through asserting unique ownership over the pointee: - https://github.com/rust-lang/unsafe-code-guidelines/issues/258 - https://github.com/rust-lang/unsafe-code-guidelines/issues/262 In the new test case, the calls to `String::remove` and `String::insert[_str]` follow code paths that would trigger undefined behavior in case `Unique` would ever assert semantic ownership over the pointee. Internally, these methods call `self.vec.as_ptr()` and `self.vec.as_mut_ptr()` on the vector of bytes that are backing the `String`. That `Vec` holds a `Unique` internally. The second call to `Vec::as_mut_ptr(&mut self)` would then invalidate the pointers derived from `Vec::as_ptr(&self)`. Note that as long as `Unique` is treated like any other raw pointer, this test case should pass. It is merely here as a canary test for potential future undefined behavior. --- 44122f9ff287f6bf2f1209244631ceb544a8f90a