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
The IntoBytes implementation is incorrect, as shown when running this program under Miri. The correct syntax is &raw const *self (which returns a *const Self) rather than &raw const self (which returns a *const &Self).
use std::{mem, slice};/// .../// # Safety/// The type must have a defined representation and no padding.pubunsafetraitIntoBytes{fnas_bytes(&self) -> &[u8]{let len = mem::size_of_val(self);unsafe{ slice::from_raw_parts((&raw const self).cast::<u8>(), len)}}}// SAFETY: `u32` has a defined representation and no padding.unsafeimplIntoBytesforu32{}fnmain(){println!("{:?}", 42.as_bytes());}
error: Undefined Behavior: out-of-bounds pointer use: alloc811 has been freed, so this pointer is dangling
--> src/main.rs:17:22
|
17 | println!("{:?}", 42.as_bytes());
| ^^^^^^^^^^^^^ out-of-bounds pointer use: alloc811 has been freed, so this pointer is dangling
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
help: alloc811 was allocated here:
--> src/main.rs:7:17
|
7 | fn as_bytes(&self) -> &[u8] {
| ^^^^^
help: alloc811 was deallocated here:
--> src/main.rs:10:6
|
10 | }
| ^
= note: BACKTRACE (of the first span):
= note: inside `main` at src/main.rs:17:22: 17:35
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
The text was updated successfully, but these errors were encountered:
The
IntoBytes
implementation is incorrect, as shown when running this program under Miri. The correct syntax is&raw const *self
(which returns a*const Self
) rather than&raw const self
(which returns a*const &Self
).The text was updated successfully, but these errors were encountered: