We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8aae1ee commit f69c5aaCopy full SHA for f69c5aa
library/core/tests/option.rs
@@ -372,3 +372,34 @@ fn option_const() {
372
const IS_NONE: bool = OPTION.is_none();
373
assert!(!IS_NONE);
374
}
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
+}
src/test/ui/option-unwrap.rs
0 commit comments