From f69c5aa428efdbc01685c3d06e63fedd3120e8e5 Mon Sep 17 00:00:00 2001 From: Alexis Bourget Date: Tue, 8 Sep 2020 00:10:35 +0200 Subject: [PATCH] Move more tests using Cell to unit tests --- library/core/tests/option.rs | 31 +++++++++++++++++++++++++++++++ src/test/ui/option-unwrap.rs | 32 -------------------------------- 2 files changed, 31 insertions(+), 32 deletions(-) delete mode 100644 src/test/ui/option-unwrap.rs diff --git a/library/core/tests/option.rs b/library/core/tests/option.rs index 9e86e07dd91..bd9a5a6a2cd 100644 --- a/library/core/tests/option.rs +++ b/library/core/tests/option.rs @@ -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, + } + + impl<'a> std::ops::Drop for Dtor<'a> { + fn drop(&mut self) { + self.x.set(self.x.get() - 1); + } + } + + fn unwrap(o: Option) -> 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); +} diff --git a/src/test/ui/option-unwrap.rs b/src/test/ui/option-unwrap.rs deleted file mode 100644 index 173f803ee24..00000000000 --- a/src/test/ui/option-unwrap.rs +++ /dev/null @@ -1,32 +0,0 @@ -// run-pass - -#![allow(non_camel_case_types)] -use std::cell::Cell; - -struct dtor<'a> { - x: &'a Cell, -} - -impl<'a> Drop for dtor<'a> { - fn drop(&mut self) { - self.x.set(self.x.get() - 1); - } -} - -fn unwrap(o: Option) -> T { - match o { - Some(v) => v, - None => panic!() - } -} - -pub fn main() { - let x = &Cell::new(1); - - { - let b = Some(dtor { x:x }); - let _c = unwrap(b); - } - - assert_eq!(x.get(), 0); -}