Skip to content

Commit a09f8b0

Browse files
committed
Auto merge of #1663 - RalfJung:rustup, r=RalfJung
test Weak into_raw/from_raw on dangling ptrs
2 parents 0a723fa + 82c6c77 commit a09f8b0

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
507bff92fadf1f25a830da5065a5a87113345163
1+
8b002d5c3489a21db2c16e5af63cf5d234f6972c

tests/run-pass/intrinsics.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#![feature(core_intrinsics, const_raw_ptr_comparison)]
2+
#![feature(layout_for_ptr)]
23

34
use std::intrinsics;
4-
use std::mem::{size_of, size_of_val};
5+
use std::mem::{size_of, size_of_val, size_of_val_raw};
56

67
struct Bomb;
78

@@ -19,6 +20,9 @@ fn main() {
1920
assert_eq!(size_of_val(&[1, 2, 3] as &[i32]), 12);
2021
assert_eq!(size_of_val("foobar"), 6);
2122

23+
unsafe { assert_eq!(size_of_val_raw(&[1] as &[i32] as *const [i32]), 4); }
24+
unsafe { assert_eq!(size_of_val_raw(0x100 as *const i32), 4); }
25+
2226
assert_eq!(intrinsics::type_name::<Option<i32>>(), "core::option::Option<i32>");
2327

2428
assert_eq!(intrinsics::likely(false), false);

tests/run-pass/rc.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use std::cell::{Cell, RefCell};
66
use std::rc::{Rc, Weak};
7-
use std::sync::Arc;
7+
use std::sync::{Arc, Weak as ArcWeak};
88
use std::fmt::Debug;
99

1010
fn rc_refcell() {
@@ -48,6 +48,9 @@ fn arc() {
4848
a
4949
}
5050
assert_eq!(*test(), 42);
51+
52+
let raw = ArcWeak::into_raw(ArcWeak::<usize>::new());
53+
drop(unsafe { ArcWeak::from_raw(raw) });
5154
}
5255

5356
// Make sure this Rc doesn't fall apart when touched
@@ -84,6 +87,9 @@ fn weak_into_raw() {
8487

8588
drop(unsafe { Weak::from_raw(raw) });
8689
assert_eq!(0, Rc::weak_count(&strong));
90+
91+
let raw = Weak::into_raw(Weak::<usize>::new());
92+
drop(unsafe { Weak::from_raw(raw) });
8793
}
8894

8995
/// Taken from the `Weak::from_raw` doctest.

0 commit comments

Comments
 (0)