Hi, I'm trying to use this library to make some form of a type-erased map data structure. I am running cargo miri test
on my tests, and I came across a failure that seems to originate from this crate. I've been able reproduce it with the following:
let mut vec: AnyVec = AnyVec::new::<usize>();
vec.push(AnyValueWrapper::new(1usize));
let iter = vec.iter().map(|v| v.downcast_ref::<usize>().unwrap());
assert!(iter.eq([&1]));
The error miri outputs is:
error: Undefined Behavior: trying to reborrow <untagged> for Unique permission at alloc86017[0x0], but that tag only grants SharedReadOnly permission for this location
--> C:\Users\sgodw\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\non_null.rs:432:18
|
432 | unsafe { &mut *self.as_ptr() }
| ^^^^^^^^^^^^^^^^^^^
| |
| trying to reborrow <untagged> for Unique permission at alloc86017[0x0], but that tag only grants SharedReadOnly permission for this location
| this error occurs as part of a reborrow at alloc86017[0x0..0x38]
|
= 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: tag was most recently created at offsets [0x0..0x38]
--> src\lib.rs:18:17
|
18 | assert!(iter.eq([&1]));
| ^^^^^^^^^^^^^
help: this tag was also created here at offsets [0x0..0x38]
--> src\lib.rs:17:20
|
17 | let iter = vec.iter().map(|v| v.downcast_ref::<usize>().unwrap());
| ^^^^^^^^^^
= note: inside `std::ptr::NonNull::<any_vec::any_vec_raw::AnyVecRaw<any_vec::mem::Heap>>::as_mut` at C:\Users\sgodw\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\non_null.rs:432:18
= note: inside `any_vec::any_vec_ptr::utils::element_ptr_at::<any_vec::any_vec_ptr::AnyVecPtr<dyn any_vec::traits::None, any_vec::mem::Heap>>` at C:\Users\sgodw\.cargo\registry\src\github.com-1ecc6299db9ec823\any_vec-0.9.1\src\any_vec_ptr.rs:126:27
= note: inside `<any_vec::Iter<any_vec::any_vec_ptr::AnyVecPtr<dyn any_vec::traits::None, any_vec::mem::Heap>, any_vec::iter::ElementRefIterItem<dyn any_vec::traits::None, any_vec::mem::Heap>> as std::iter::Iterator>::next` at C:\Users\sgodw\.cargo\registry\src\github.com-1ecc6299db9ec823\any_vec-0.9.1\src\iter.rs:83:31
= note: inside `<std::iter::Map<any_vec::Iter<any_vec::any_vec_ptr::AnyVecPtr<dyn any_vec::traits::None, any_vec::mem::Heap>, any_vec::iter::ElementRefIterItem<dyn any_vec::traits::None, any_vec::mem::Heap>>, [closure@src\lib.rs:17:35: 17:73]> as std::iter::Iterator>::next` at C:\Users\sgodw\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\iter\adapters\map.rs:103:9
= note: inside `<std::iter::Map<any_vec::Iter<any_vec::any_vec_ptr::AnyVecPtr<dyn any_vec::traits::None, any_vec::mem::Heap>, any_vec::iter::ElementRefIterItem<dyn any_vec::traits::None, any_vec::mem::Heap>>, [closure@src\lib.rs:17:35: 17:73]> as std::iter::Iterator>::eq_by::<[&usize; 1], [closure@<std::iter::Map<any_vec::Iter<any_vec::any_vec_ptr::AnyVecPtr<dyn any_vec::traits::None, any_vec::mem::Heap>, any_vec::iter::ElementRefIterItem<dyn any_vec::traits::None, any_vec::mem::Heap>>, [closure@src\lib.rs:17:35: 17:73]> as std::iter::Iterator>::eq<[&usize; 1]>::{closure#0}]>` at C:\Users\sgodw\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\iter\traits\iterator.rs:3538:27
= note: inside `<std::iter::Map<any_vec::Iter<any_vec::any_vec_ptr::AnyVecPtr<dyn any_vec::traits::None, any_vec::mem::Heap>, any_vec::iter::ElementRefIterItem<dyn any_vec::traits::None, any_vec::mem::Heap>>, [closure@src\lib.rs:17:35: 17:73]> as std::iter::Iterator>::eq::<[&usize; 1]>` at C:\Users\sgodw\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\iter\traits\iterator.rs:3510:9
note: inside `test::test` at src\lib.rs:18:17
--> src\lib.rs:18:17
|
18 | assert!(iter.eq([&1]));
| ^^^^^^^^^^^^^
note: inside closure at src\lib.rs:12:5
--> src\lib.rs:12:5
|
11 | #[test]
| ------- in this procedural macro expansion
12 | / fn test() {
13 | | let mut vec: AnyVec = AnyVec::new::<usize>();
14 | |
15 | | vec.push(AnyValueWrapper::new(1usize));
... |
18 | | assert!(iter.eq([&1]));
19 | | }
| |_____^
= note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
It looks like it's violating stacked borrows which are experimental (not too familiar with the details to be honest), so not sure if it's an actual problem at the moment.