bytes icon indicating copy to clipboard operation
bytes copied to clipboard

Not compatible with Miri's stacked borrow implementation

Open CodesInChaos opened this issue 4 years ago • 2 comments

If you run the following code in miri:

bytes::Bytes::from_static(b"abc").slice_from(1)

you get the error:

error[E0080]: Miri evaluation error: trying to reborrow for Unique, but parent tag does not have an appropriate item in the borrow stack --> /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/slice/mod.rs:5256:5 | 5256 | &mut *ptr::slice_from_raw_parts_mut(data, len) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Miri evaluation error: trying to reborrow for Unique, but parent tag does not have an appropriate item in the borrow stack | = note: inside call to std::slice::from_raw_parts_mut::<u8> at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bytes-0.4.12/src/bytes.rs:1864:13 = note: inside call to bytes::bytes::Inner::as_raw at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bytes-0.4.12/src/bytes.rs:1635:17 = note: inside call to <bytes::bytes::BytesMut as std::convert::From<&[u8]>>::from at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bytes-0.4.12/src/bytes.rs:897:9 = note: inside call to <bytes::bytes::Bytes as std::convert::From<&[u8]>>::from at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bytes-0.4.12/src/bytes.rs:515:20 = note: inside call to bytes::bytes::Bytes::slice at /root/.cargo/registry/src/github.com-1ecc6299db9ec823/bytes-0.4.12/src/bytes.rs:551:9 note: inside call to bytes::bytes::Bytes::slice_from at src/main.rs:2:5 --> src/main.rs:2:5 | 2 | bytes::Bytes::from_static(b"abc").slice_from(1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = note: inside call to main at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:64:34 = note: inside call to closure at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:53 = note: inside call to closure at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:292:40 = note: inside call to std::panicking::try::do_call::<[closure@DefId(1:6019 ~ std[82ff]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32> at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:288:5 = note: inside call to std::panicking::try::<i32, [closure@DefId(1:6019 ~ std[82ff]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]> at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394:9 = note: inside call to std::panic::catch_unwind::<[closure@DefId(1:6019 ~ std[82ff]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32> at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:25 = note: inside call to std::rt::lang_start_internal at /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:64:5 = note: inside call to std::rt::lang_start::<()>

playground (choose Tools|Miri in the menu)

CodesInChaos avatar Oct 01 '19 12:10 CodesInChaos

I can't reproduce this, albeit I had to update the code to

bytes::Bytes::from_static(b"abc").slice(1..)

since Bytes::slice_from has been superseded. (Playground.)

cole-miller avatar Nov 23 '20 22:11 cole-miller

Not sure if it still applies to the current version of bytes. You can either hope it was fixed by unrelated changes, or reproduce it in 0.4.12, figure out why it happened then and check if the affected code is still used.

CodesInChaos avatar Nov 24 '20 09:11 CodesInChaos

Closing -- fixed

taiki-e avatar Dec 20 '22 07:12 taiki-e