Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions library/core/tests/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,30 @@ fn cell_into_inner() {
assert_eq!("Hello world".to_owned(), cell.into_inner());
}

#[test]
fn cell_exterior() {
#[derive(Copy, Clone)]
#[allow(dead_code)]
struct Point {
x: isize,
y: isize,
z: isize,
}

fn f(p: &Cell<Point>) {
assert_eq!(p.get().z, 12);
p.set(Point { x: 10, y: 11, z: 13 });
assert_eq!(p.get().z, 13);
}

let a = Point { x: 10, y: 11, z: 12 };
let b = &Cell::new(a);
assert_eq!(b.get().z, 12);
f(b);
assert_eq!(a.z, 12);
assert_eq!(b.get().z, 13);
}

#[test]
fn refcell_default() {
let cell: RefCell<u64> = Default::default();
Expand Down
31 changes: 31 additions & 0 deletions library/core/tests/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,34 @@ fn option_const() {
const IS_NONE: bool = OPTION.is_none();
assert!(!IS_NONE);
}

#[test]
fn test_unwrap_drop() {
use std::cell::Cell;

struct Dtor<'a> {
x: &'a Cell<isize>,
}

impl<'a> std::ops::Drop for Dtor<'a> {
fn drop(&mut self) {
self.x.set(self.x.get() - 1);
}
}

fn unwrap<T>(o: Option<T>) -> T {
match o {
Some(v) => v,
None => panic!(),
}
}

let x = &Cell::new(1);

{
let b = Some(Dtor { x });
let _c = unwrap(b);
}

assert_eq!(x.get(), 0);
}
24 changes: 0 additions & 24 deletions src/test/ui/exterior.rs

This file was deleted.

32 changes: 0 additions & 32 deletions src/test/ui/option-unwrap.rs

This file was deleted.