Skip to content

Commit

Permalink
Auto merge of rust-lang#1663 - RalfJung:rustup, r=RalfJung
Browse files Browse the repository at this point in the history
test Weak into_raw/from_raw on dangling ptrs
  • Loading branch information
bors committed Dec 31, 2020
2 parents 0a723fa + 82c6c77 commit a09f8b0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion rust-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
507bff92fadf1f25a830da5065a5a87113345163
8b002d5c3489a21db2c16e5af63cf5d234f6972c
6 changes: 5 additions & 1 deletion tests/run-pass/intrinsics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#![feature(core_intrinsics, const_raw_ptr_comparison)]
#![feature(layout_for_ptr)]

use std::intrinsics;
use std::mem::{size_of, size_of_val};
use std::mem::{size_of, size_of_val, size_of_val_raw};

struct Bomb;

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

unsafe { assert_eq!(size_of_val_raw(&[1] as &[i32] as *const [i32]), 4); }
unsafe { assert_eq!(size_of_val_raw(0x100 as *const i32), 4); }

assert_eq!(intrinsics::type_name::<Option<i32>>(), "core::option::Option<i32>");

assert_eq!(intrinsics::likely(false), false);
Expand Down
8 changes: 7 additions & 1 deletion tests/run-pass/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use std::cell::{Cell, RefCell};
use std::rc::{Rc, Weak};
use std::sync::Arc;
use std::sync::{Arc, Weak as ArcWeak};
use std::fmt::Debug;

fn rc_refcell() {
Expand Down Expand Up @@ -48,6 +48,9 @@ fn arc() {
a
}
assert_eq!(*test(), 42);

let raw = ArcWeak::into_raw(ArcWeak::<usize>::new());
drop(unsafe { ArcWeak::from_raw(raw) });
}

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

drop(unsafe { Weak::from_raw(raw) });
assert_eq!(0, Rc::weak_count(&strong));

let raw = Weak::into_raw(Weak::<usize>::new());
drop(unsafe { Weak::from_raw(raw) });
}

/// Taken from the `Weak::from_raw` doctest.
Expand Down

0 comments on commit a09f8b0

Please sign in to comment.