Open
Description
I tried this code:
fn main() {
let mut x = *b"hello";
let p: &mut [u8] = &mut x;
let q: *mut [u8] = &mut p[..3];
assert_eq!(p as *mut [u8], q);
}
I expected to see this happen:
assertion `left == right` failed
left: { ptr: 0x7ffdd41d89f3, meta: 5 }
right: { ptr: 0x7ffdd41d89f3, meta: 3 }
Instead, this happened:
assertion `left == right` failed
left: 0x7ffdd41d89f3
right: 0x7ffdd41d89f3
Note: The pointer address is non-deterministic, so the output may differ. What matters is that the pointer address is the same, only the metadata differ.
Meta
rustc --version --verbose
:
rustc 1.82.0-nightly (f8060d282 2024-07-30)
binary: rustc
commit-hash: f8060d282d42770fadd73905e3eefb85660d3278
commit-date: 2024-07-30
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7
Backtrace
thread 'main' panicked at src/main.rs:5:5:
assertion `left == right` failed
left: 0x7ffca57ef663
right: 0x7ffca57ef663
stack backtrace:
0: rust_begin_unwind
at /rustc/f8060d282d42770fadd73905e3eefb85660d3278/library/std/src/panicking.rs:662:5
1: core::panicking::panic_fmt
at /rustc/f8060d282d42770fadd73905e3eefb85660d3278/library/core/src/panicking.rs:74:14
2: core::panicking::assert_failed_inner
at /rustc/f8060d282d42770fadd73905e3eefb85660d3278/library/core/src/panicking.rs:412:17
3: core::panicking::assert_failed
at /rustc/f8060d282d42770fadd73905e3eefb85660d3278/library/core/src/panicking.rs:367:5
4: foo::main
at ./src/main.rs:5:5
5: core::ops::function::FnOnce::call_once
at /rustc/f8060d282d42770fadd73905e3eefb85660d3278/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
Activity