Amanieu / intrusive-rs

Intrusive collections for Rust
Apache License 2.0
423 stars 50 forks source link

tests fail when run with miri #28

Closed jrmuizel closed 5 years ago

jrmuizel commented 5 years ago

I disabled the tests that require rand, ran cargo miri test and got the following error:

error[E0080]: constant evaluation error: Pointer must be in-bounds and live at offset 40, but is outside bounds of allocation 40420 which has size 24
    --> /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/libcore/ptr.rs:3009:9
     |
3009 |         &*self.as_ptr()
     |         ^^^^^^^^^^^^^^^ Pointer must be in-bounds and live at offset 40, but is outside bounds of allocation 40420 which has size 24
     |
     = note: inside call to `core::ptr::NonNull::<alloc::sync::ArcInner<i32>>::as_ref` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/liballoc/sync.rs:545:18
     = note: inside call to `alloc::sync::Arc::<i32>::inner` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/liballoc/sync.rs:777:10
     = note: inside call to `<alloc::sync::Arc<i32> as core::ops::Deref>::deref` at /Users/jrmuizel/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/src/liballoc/sync.rs:2140:10
note: inside call to `<alloc::sync::Arc<i32> as core::convert::AsRef<i32>>::as_ref` at src/intrusive_pointer.rs:125:30
    --> src/intrusive_pointer.rs:125:30
     |
125  |         let fake_rc_target = fake_rc.as_ref() as *const _;
     |                              ^^^^^^^^^^^^^^^^
note: inside call to `<alloc::sync::Arc<i32> as intrusive_pointer::IntrusivePointer<i32>>::from_raw` at src/intrusive_pointer.rs:186:32
    --> src/intrusive_pointer.rs:186:32
     |
186  |             let p2: Arc<i32> = IntrusivePointer::from_raw(r);
     |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to `intrusive_pointer::tests::test_arc` at src/intrusive_pointer.rs:180:5
    --> src/intrusive_pointer.rs:180:5
     |
180  | /     fn test_arc() {
181  | |         unsafe {
182  | |             let p = Arc::new(1);
183  | |             let a: *const i32 = &*p;
...    |
189  | |         }
190  | |     }
     | |_____^
Amanieu commented 5 years ago

This code needs to be changed to use Rc::from_raw and Arc::from_raw instead of the current hack (which was written before from_raw was stabilized).