Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miri errors on tests #5

Closed
WaffleLapkin opened this issue Mar 20, 2020 · 2 comments · Fixed by #7
Closed

miri errors on tests #5

WaffleLapkin opened this issue Mar 20, 2020 · 2 comments · Fixed by #7
Labels
bug Something isn't working help wanted Extra attention is needed unsafe Issue with unsafe code

Comments

@WaffleLapkin
Copy link
Owner

cargo +nightly-2020-03-16 miri test fails on util::init::tests::drop_on_panic and util::init::tests::drop_on_fail tests with following errors:

`drop_on_panic`

error: Miri evaluation error: trying to reborrow for Unique, but parent tag <untagged> does not have an appropriate item in the borrow stack
    --> /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/slice/mod.rs:5709:5
     |
5709 |     &mut *ptr::slice_from_raw_parts_mut(data, len)
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for Unique, but parent tag <untagged> does not have an appropriate item in the borrow stack
     |
note: inside call to `std::slice::from_raw_parts_mut::<std::mem::MaybeUninit<util::init::tests::DropCount>>` at src/util/init.rs:115:25
    --> src/util/init.rs:115:25
     |
115  |                         slice::from_raw_parts_mut(self.array_base_ptr, self.initialized_count)
     |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside call to `<util::init::try_unfold_array::DropGuard<util::init::tests::DropCount> as std::ops::Drop>::drop` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ptr/mod.rs:177:1
note: inside call to `std::intrinsics::drop_in_place::<util::init::try_unfold_array::DropGuard<util::init::tests::DropCount>> - shim(Some(util::init::try_unfold_array::DropGuard<util::init::tests::DropCount>))` at src/util/init.rs:155:9
    --> src/util/init.rs:155:9
     |
155  |         }
     |         ^
note: inside call to `util::init::try_unfold_array::<[util::init::tests::DropCount; 16], usize, [closure@src/util/init.rs:47:30: 51:6 f:&mut [closure@src/util/init.rs:27:23: 27:55 init:&mut [closure@src/util/init.rs:210:52: 216:14 counter:&std::sync::Mutex<usize>]]], std::convert::Infallible>` at src/util/init.rs:47:5
    --> src/util/init.rs:47:5
     |
47   | /     try_unfold_array(0usize, |state| {
48   | |         let item = f(*state);
49   | |         *state += 1;
50   | |         item
51   | |     })
     | |______^
note: inside call to `util::init::try_array_init_fn::<[util::init::tests::DropCount; 16], std::convert::Infallible, [closure@src/util/init.rs:27:23: 27:55 init:&mut [closure@src/util/init.rs:210:52: 216:14 counter:&std::sync::Mutex<usize>]]>` at src/util/init.rs:27:5
    --> src/util/init.rs:27:5
     |
27   |     try_array_init_fn(|i| Ok::<_, Infallible>(init(i))).unwrap_or_else(|inf| match inf {})
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `util::init::array_init_fn::<[util::init::tests::DropCount; 16], [closure@src/util/init.rs:210:52: 216:14 counter:&std::sync::Mutex<usize>]>` at src/util/init.rs:210:38
    --> src/util/init.rs:210:38
     |
210  |               let _: [DropCount; 16] = array_init_fn(|i| {
     |  ______________________________________^
211  | |                 if i == 10 {
212  | |                     panic!()
213  | |                 } else {
214  | |                     DropCount(&counter)
215  | |                 }
216  | |             });
     | |______________^
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:329:40
     = note: inside call to `std::panicking::r#try::do_call::<[closure@src/util/init.rs:209:42: 217:10 counter:&std::sync::Mutex<usize>], ()>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:285:13
     = note: inside call to `std::panicking::r#try::do_try` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:274:15
     = note: inside call to `std::panicking::r#try::<(), [closure@src/util/init.rs:209:42: 217:10 counter:&std::sync::Mutex<usize>]>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394:14
note: inside call to `std::panic::catch_unwind::<[closure@src/util/init.rs:209:42: 217:10 counter:&std::sync::Mutex<usize>], ()>` at src/util/init.rs:209:17
    --> src/util/init.rs:209:17
     |
209  |           let r = std::panic::catch_unwind(|| {
     |  _________________^
210  | |             let _: [DropCount; 16] = array_init_fn(|i| {
211  | |                 if i == 10 {
212  | |                     panic!()
...    |
216  | |             });
217  | |         });
     | |__________^
note: inside call to `util::init::tests::drop_on_panic` at src/util/init.rs:206:5
    --> src/util/init.rs:206:5
     |
206  | /     fn drop_on_panic() {
207  | |         let counter = Mutex::new(0);
208  | |
209  | |         let r = std::panic::catch_unwind(|| {
...    |
220  | |         assert_eq!(*counter.lock().unwrap(), 10);
221  | |     }
     | |_____^
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232:5
     = note: inside call to `<[closure@src/util/init.rs:206:5: 221:6] as std::ops::FnOnce<()>>::call_once - shim` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232:5
     = note: inside call to `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:518:5
     = note: inside call to `test::__rust_begin_short_backtrace::<fn()>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:509:30
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232:5
     = note: inside call to `<[closure@DefId(14:631 ~ test[e807]::run_test[0]::{{closure}}[2]) 0:fn()] as std::ops::FnOnce<()>>::call_once - shim(vtable)` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc/boxed.rs:1017:9
     = note: inside call to `<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send> as std::ops::FnOnce<()>>::call_once` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:318:9
     = note: inside call to `<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>> as std::ops::FnOnce<()>>::call_once` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:329:40
     = note: inside call to `std::panicking::r#try::do_call::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>, ()>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:285:13
     = note: inside call to `std::panicking::r#try::do_try` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:274:15
     = note: inside call to `std::panicking::r#try::<(), std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394:14
     = note: inside call to `std::panic::catch_unwind::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>, ()>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:542:18
     = note: inside call to `test::run_test_in_process` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:451:39
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:476:13
     = note: inside call to `test::run_test::run_test_inner` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:506:28
     = note: inside call to `test::run_test` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:285:13
     = note: inside call to `test::run_tests::<[closure@DefId(14:230 ~ test[e807]::console[0]::run_tests_console[0]::{{closure}}[2]) 0:&mut test::console::ConsoleTestState, 1:&mut std::boxed::Box<dyn test::formatters::OutputFormatter>]>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/console.rs:280:5
     = note: inside call to `test::run_tests_console` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:121:15
     = note: inside call to `test::test_main` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:140:5
     = note: inside call to `test::test_main_static`
     = note: inside call to `main` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67:34
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:73
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys_common/backtrace.rs:130:5
     = note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1:6033 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:13
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:329:40
     = note: inside call to `std::panicking::r#try::do_call::<[closure@DefId(1:6032 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:285:13
     = note: inside call to `std::panicking::r#try::do_try` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:274:15
     = note: inside call to `std::panicking::r#try::<i32, [closure@DefId(1:6032 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394:14
     = note: inside call to `std::panic::catch_unwind::<[closure@DefId(1:6032 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:51:25
     = note: inside call to `std::rt::lang_start_internal` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67:5
     = note: inside call to `std::rt::lang_start::<()>`
     = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

`drop_on_fail`

error: Miri evaluation error: trying to reborrow for Unique, but parent tag <untagged> does not have an appropriate item in the borrow stack
    --> /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/slice/mod.rs:5709:5
     |
5709 |     &mut *ptr::slice_from_raw_parts_mut(data, len)
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trying to reborrow for Unique, but parent tag <untagged> does not have an appropriate item in the borrow stack
     |
note: inside call to `std::slice::from_raw_parts_mut::<std::mem::MaybeUninit<util::init::tests::DropCount>>` at src/util/init.rs:115:25
    --> src/util/init.rs:115:25
     |
115  |                         slice::from_raw_parts_mut(self.array_base_ptr, self.initialized_count)
     |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: inside call to `<util::init::try_unfold_array::DropGuard<util::init::tests::DropCount> as std::ops::Drop>::drop` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ptr/mod.rs:177:1
note: inside call to `std::intrinsics::drop_in_place::<util::init::try_unfold_array::DropGuard<util::init::tests::DropCount>> - shim(Some(util::init::try_unfold_array::DropGuard<util::init::tests::DropCount>))` at src/util/init.rs:155:9
    --> src/util/init.rs:155:9
     |
155  |         }
     |         ^
note: inside call to `util::init::try_unfold_array::<[util::init::tests::DropCount; 16], usize, [closure@src/util/init.rs:47:30: 51:6 f:&mut [closure@src/util/init.rs:228:64: 234:10 counter:&std::sync::Mutex<usize>]], ()>` at src/util/init.rs:47:5
    --> src/util/init.rs:47:5
     |
47   | /     try_unfold_array(0usize, |state| {
48   | |         let item = f(*state);
49   | |         *state += 1;
50   | |         item
51   | |     })
     | |______^
note: inside call to `util::init::try_array_init_fn::<[util::init::tests::DropCount; 16], (), [closure@src/util/init.rs:228:64: 234:10 counter:&std::sync::Mutex<usize>]>` at src/util/init.rs:228:46
    --> src/util/init.rs:228:46
     |
228  |           let r: Result<[DropCount; 16], ()> = try_array_init_fn(|i| {
     |  ______________________________________________^
229  | |             if i == 10 {
230  | |                 Err(())
231  | |             } else {
232  | |                 Ok(DropCount(&counter))
233  | |             }
234  | |         });
     | |__________^
note: inside call to `util::init::tests::drop_on_fail` at src/util/init.rs:225:5
    --> src/util/init.rs:225:5
     |
225  | /     fn drop_on_fail() {
226  | |         let counter = Mutex::new(0);
227  | |
228  | |         let r: Result<[DropCount; 16], ()> = try_array_init_fn(|i| {
...    |
237  | |         assert_eq!(*counter.lock().unwrap(), 10);
238  | |     }
     | |_____^
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232:5
     = note: inside call to `<[closure@src/util/init.rs:225:5: 238:6] as std::ops::FnOnce<()>>::call_once - shim` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232:5
     = note: inside call to `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:518:5
     = note: inside call to `test::__rust_begin_short_backtrace::<fn()>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:509:30
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/ops/function.rs:232:5
     = note: inside call to `<[closure@DefId(14:631 ~ test[e807]::run_test[0]::{{closure}}[2]) 0:fn()] as std::ops::FnOnce<()>>::call_once - shim(vtable)` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/liballoc/boxed.rs:1017:9
     = note: inside call to `<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send> as std::ops::FnOnce<()>>::call_once` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:318:9
     = note: inside call to `<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>> as std::ops::FnOnce<()>>::call_once` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:329:40
     = note: inside call to `std::panicking::r#try::do_call::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>, ()>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:285:13
     = note: inside call to `std::panicking::r#try::do_try` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:274:15
     = note: inside call to `std::panicking::r#try::<(), std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394:14
     = note: inside call to `std::panic::catch_unwind::<std::panic::AssertUnwindSafe<std::boxed::Box<dyn std::ops::FnOnce() + std::marker::Send>>, ()>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:542:18
     = note: inside call to `test::run_test_in_process` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:451:39
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:476:13
     = note: inside call to `test::run_test::run_test_inner` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:506:28
     = note: inside call to `test::run_test` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:285:13
     = note: inside call to `test::run_tests::<[closure@DefId(14:230 ~ test[e807]::console[0]::run_tests_console[0]::{{closure}}[2]) 0:&mut test::console::ConsoleTestState, 1:&mut std::boxed::Box<dyn test::formatters::OutputFormatter>]>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/console.rs:280:5
     = note: inside call to `test::run_tests_console` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:121:15
     = note: inside call to `test::test_main` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libtest/lib.rs:140:5
     = note: inside call to `test::test_main_static`
     = note: inside call to `main` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67:34
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:73
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/sys_common/backtrace.rs:130:5
     = note: inside call to `std::sys_common::backtrace::__rust_begin_short_backtrace::<[closure@DefId(1:6033 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]::{{closure}}[0]) 0:&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:52:13
     = note: inside call to closure at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:329:40
     = note: inside call to `std::panicking::r#try::do_call::<[closure@DefId(1:6032 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:285:13
     = note: inside call to `std::panicking::r#try::do_try` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panicking.rs:274:15
     = note: inside call to `std::panicking::r#try::<i32, [closure@DefId(1:6032 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe]>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/panic.rs:394:14
     = note: inside call to `std::panic::catch_unwind::<[closure@DefId(1:6032 ~ std[1f88]::rt[0]::lang_start_internal[0]::{{closure}}[0]) 0:&&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe], i32>` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:51:25
     = note: inside call to `std::rt::lang_start_internal` at /home/waffle/.rustup/toolchains/nightly-2020-03-16-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libstd/rt.rs:67:5
     = note: inside call to `std::rt::lang_start::<()>`
     = note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)

In both cases, the error is caused by try_unfold_array::DropGuard::drop.

The error seems to be because of aliasing, but I don't understand where is the first reference to the slice...

It also seems that array-init (where I've stolen the idea of try_unfold_array method from) does not have the same issue (the same drop/fail tests for array-init: gist).

I don't understand what am I doing wrong, so I would appreciate if somebody with more experience in unsafe code will help.

@WaffleLapkin WaffleLapkin added bug Something isn't working help wanted Extra attention is needed unsafe Issue with unsafe code labels Mar 20, 2020
@WaffleLapkin
Copy link
Owner Author

WaffleLapkin commented Mar 20, 2020

MRE: playground
(you can run it directly on the playground, see tools -> miri)

@WaffleLapkin
Copy link
Owner Author

One possible solution is to use array_base_ptr.add(i).write(value); instead of *array.index_mut(i) = MaybeUninit::new(value);:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed unsafe Issue with unsafe code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant