wafflelapkin / arraylib Goto Github PK
View Code? Open in Web Editor NEWTools for working with arrays in rust
Home Page: https://docs.rs/arraylib
License: MIT License
Tools for working with arrays in rust
Home Page: https://docs.rs/arraylib
License: MIT License
Currently, there are 5 methods in Array
to create an array:
unfold
/try_unfold
from_fn
/try_from_fn
from_iter
All of them are implemented either by util::init
module or by specialization for sizes 0..=32
(see local_macros.rs
and array.rs
). This was done to achieve the best performance.
However, all of these methods can be implemented in terms of try_unfold
. And this would probably be zero cost if compiler is smart enough.
Currently, miri doesn't run doctests (see rust-lang/miri#584) however, a lot of functionality of this lib is tested only in doctests.
It makes sense either to copy-paste doctests to unit tests (under #[cfg(miri)]
?) or, at least, run them locally.
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:
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)
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.