You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::mem;// We have three fields to avoid the ScalarPair optimization.#[allow(unused)]enumE{None,Some(&'static(),&'static(),usize),}fnmain(){unsafe{letmut p: mem::MaybeUninit<E> = mem::MaybeUninit::zeroed();// The copy when `E` is returned from `transmute` should destroy padding// (even when we use `write_unaligned`, which under the hood uses an untyped copy).
p.as_mut_ptr().write_unaligned(mem::transmute((0usize,0usize,0usize)));// This is a `None`, so everything but the discriminant is padding.assert!(matches!(*p.as_ptr(),E::None));// Turns out the discriminant is (currently) stored// in the 2nd pointer, so the first half is padding.let c = &p as*const_as*constu8;let _val = *c.add(0);// Get a padding byte.//~^ERROR: uninitialized}}
Strangely, even the "properly formatted" version of this file causes the same error:
use std::mem;
// We have three fields to avoid the ScalarPair optimization.
#[allow(unused)]
enum E {
None,
Some(&'static (), &'static (), usize),
}
fn main() {
unsafe {
let mut p: mem::MaybeUninit<E> = mem::MaybeUninit::zeroed();
// The copy when `E` is returned from `transmute` should destroy padding
// (even when we use `write_unaligned`, which under the hood uses an untyped copy).
p.as_mut_ptr().write_unaligned(mem::transmute((0usize, 0usize, 0usize)));
// This is a `None`, so everything but the discriminant is padding.
assert!(matches!(*p.as_ptr(), E::None));
// Turns out the discriminant is (currently) stored
// in the 2nd pointer, so the first half is padding.
let c = &p as *const _ as *const u8;
let _val = *c.add(0); // Get a padding byte.
//~^ERROR: uninitialized
}
}
It always adds an empty line with 8 spaces before the //~^ERROR: uninitialized comment.
ah 😆 I also just found this, looking at new rustfmt failures.
with
version = "Two"merge_derives = falseimports_granularity = "Module"
use std::mem;#[allow(unused)]#[repr(C)]unionU{field:(u8,u16),}fnmain(){unsafe{let p:U = mem::transmute(0u32);// The copy when `U` is returned from `transmute` should destroy padding.let c = &p as*const_as*const[u8;4];let _val = *c;// Read the entire thing, definitely contains the padding byte.//~^ERROR: uninitialized}}
Rustfmt fails to format this file:
with these settings:
The error is:
If I comment out the "version" setting, formatting works fine.
I saw a bunch of other issues with similar errors but it is not clear to me which one of them this could be a duplicate of.
The text was updated successfully, but these errors were encountered: