dashmap
dashmap copied to clipboard
miri failure in `entry`
dashmap 5.4.0 has a miri failure when its entry method is called with a Box value. Here is a minimal reproducible example:
#[test]
fn just_dashmap() {
let m: DashMap<Box<&'static str>, ()> = DashMap::new();
match m.entry(Box::new("hello")) {
Entry::Vacant(e) => {
e.insert(());
}
Entry::Occupied(_) => {
panic!("Should not exist yet");
}
};
}
I run this with
cargo +nightly miri test just_dashmap
and get the following error:
$ cargo +nightly miri test --features arc just_dashmap
Preparing a sysroot for Miri (target: x86_64-unknown-linux-gnu)... done
Finished test [unoptimized + debuginfo] target(s) in 0.03s
Running unittests src/lib.rs (target/miri/x86_64-unknown-linux-gnu/debug/deps/internment-70bb0e72db6e1fd0)
running 1 test
test arc::just_dashmap ... error: Undefined Behavior: trying to retag from <250988> for SharedReadOnly permission at alloc105584[0x0], but that tag does not exist in the borrow stack for this location
--> /home/droundy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1383:9
|
1383 | (**self).hash(state);
| ^^^^^^^^^^^^^^^^^^^^
| |
| trying to retag from <250988> for SharedReadOnly permission at alloc105584[0x0], but that tag does not exist in the borrow stack for this location
| this error occurs as part of retag at alloc105584[0x0..0x10]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <250988> was created by a Unique retag at offsets [0x0..0x10]
--> src/arc.rs:506:13
|
506 | e.insert(());
| ^^^^^^^^^^^^
help: <250988> was later invalidated at offsets [0x0..0x10] by a Unique retag
--> src/arc.rs:506:13
|
506 | e.insert(());
| ^^^^^^^^^^^^
= note: BACKTRACE:
= note: inside `<std::boxed::Box<&str> as std::hash::Hash>::hash::<std::collections::hash_map::DefaultHasher>` at /home/droundy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/boxed.rs:1383:9
= note: inside `hashbrown::map::make_hash::<std::boxed::Box<&str>, std::boxed::Box<&str>, std::collections::hash_map::RandomState>` at /home/droundy/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.3/src/map.rs:253:5
= note: inside `hashbrown::HashMap::<std::boxed::Box<&str>, dashmap::util::SharedValue<()>, std::collections::hash_map::RandomState>::get_inner::<std::boxed::Box<&str>>` at /home/droundy/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.3/src/map.rs:1270:24
= note: inside `hashbrown::HashMap::<std::boxed::Box<&str>, dashmap::util::SharedValue<()>, std::collections::hash_map::RandomState>::get_key_value::<std::boxed::Box<&str>>` at /home/droundy/.cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.3/src/map.rs:1255:15
= note: inside `dashmap::mapref::entry::VacantEntry::<'_, std::boxed::Box<&str>, ()>::insert` at /home/droundy/.cargo/registry/src/github.com-1ecc6299db9ec823/dashmap-5.4.0/src/mapref/entry.rs:106:26
note: inside `arc::just_dashmap` at src/arc.rs:506:13
--> src/arc.rs:506:13
|
506 | e.insert(());
| ^^^^^^^^^^^^
note: inside closure at src/arc.rs:502:19
--> src/arc.rs:502:19
|
501 | #[test]
| ------- in this procedural macro expansion
502 | fn just_dashmap() {
| ^
= note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to previous error
error: test failed, to rerun pass `--lib`
Caused by:
process didn't exit successfully: `/home/droundy/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo-miri runner /home/droundy/src/internment/target/miri/x86_64-unknown-linux-gnu/debug/deps/internment-70bb0e72db6e1fd0 just_dashmap` (exit status: 1)
I'll look into this but it seems new, the rules violated also seem new and experimental so it'll be interesting.
Does anyone know what consequences this error could have in terms of undefined behavior when compiling with the latest stable rustc?