about summary refs log tree commit diff
path: root/src/test/ui/array-slice-vec/vec-slice-drop.rs
blob: 3a9ea86af34bbf3098edcce4f24c9b219acc4282 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// run-pass

#![allow(non_camel_case_types)]

use std::cell::Cell;

// Make sure that destructors get run on slice literals
struct foo<'a> {
    x: &'a Cell<isize>,
}

impl<'a> Drop for foo<'a> {
    fn drop(&mut self) {
        self.x.set(self.x.get() + 1);
    }
}

fn foo(x: &Cell<isize>) -> foo {
    foo {
        x: x
    }
}

pub fn main() {
    let x = &Cell::new(0);
    {
        let l = &[foo(x)];
        assert_eq!(l[0].x.get(), 0);
    }
    assert_eq!(x.get(), 1);
}