summaryrefslogtreecommitdiffstats
path: root/src/test/ui/structs-enums/newtype-struct-drop-run.rs
blob: 0754f3187018e8c753ec201ff6352af2d8d9c544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// run-pass
// Make sure the destructor is run for newtype structs.

use std::cell::Cell;

struct Foo<'a>(&'a Cell<isize>);

impl<'a> Drop for Foo<'a> {
    fn drop(&mut self) {
        let Foo(i) = *self;
        i.set(23);
    }
}

pub fn main() {
    let y = &Cell::new(32);
    {
        let _x = Foo(y);
    }
    assert_eq!(y.get(), 23);
}