Skip to content

Commit f69c5aa

Browse files
committed
Move more tests using Cell to unit tests
1 parent 8aae1ee commit f69c5aa

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

Diff for: library/core/tests/option.rs

+31
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,34 @@ fn option_const() {
372372
const IS_NONE: bool = OPTION.is_none();
373373
assert!(!IS_NONE);
374374
}
375+
376+
#[test]
377+
fn test_unwrap_drop() {
378+
use std::cell::Cell;
379+
380+
struct Dtor<'a> {
381+
x: &'a Cell<isize>,
382+
}
383+
384+
impl<'a> std::ops::Drop for Dtor<'a> {
385+
fn drop(&mut self) {
386+
self.x.set(self.x.get() - 1);
387+
}
388+
}
389+
390+
fn unwrap<T>(o: Option<T>) -> T {
391+
match o {
392+
Some(v) => v,
393+
None => panic!(),
394+
}
395+
}
396+
397+
let x = &Cell::new(1);
398+
399+
{
400+
let b = Some(Dtor { x });
401+
let _c = unwrap(b);
402+
}
403+
404+
assert_eq!(x.get(), 0);
405+
}

Diff for: src/test/ui/option-unwrap.rs

-32
This file was deleted.

0 commit comments

Comments
 (0)