-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
miri:error printing the return value of align_to_mut #68549
Comments
Code of that function: pub unsafe fn align_to_mut<U>(&mut self) -> (&mut [T], &mut [U], &mut [T]) {
// Note that most of this function will be constant-evaluated,
if mem::size_of::<U>() == 0 || mem::size_of::<T>() == 0 {
// handle ZSTs specially, which is – don't handle them at all.
return (self, &mut [], &mut []);
}
// First, find at what point do we split between the first and 2nd slice. Easy with
// ptr.align_offset.
let ptr = self.as_ptr();
let offset = crate::ptr::align_offset(ptr, mem::align_of::<U>());
if offset > self.len() {
(self, &mut [], &mut [])
} else {
let (left, rest) = self.split_at_mut(offset);
// now `rest` is definitely aligned, so `from_raw_parts_mut` below is okay
let (us_len, ts_len) = rest.align_to_offsets::<U>();
let mut_ptr = rest.as_mut_ptr();
(
left,
from_raw_parts_mut(mut_ptr as *mut U, us_len),
from_raw_parts_mut(mut_ptr.add(rest.len() - ts_len), ts_len),
)
}
} |
Somewhat simplified: fn main() {
unsafe {
([1u8,2,3,4,5].align_to_mut::<[u8;2]>().1)[0]
};
} Replacing If it is really a problem with how the cc @RalfJung |
This is where the tag gets removed from the borrow stack:
The problem is that
It also makes the middle slice empty, so there is no overlap. |
Attempting to run this code:
in miri 2020-01-15 in the playground,results in this error:
The text was updated successfully, but these errors were encountered: