]> git.proxmox.com Git - rustc.git/blame - src/test/ui/array-slice-vec/vec-slice-drop.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / src / test / ui / array-slice-vec / vec-slice-drop.rs
CommitLineData
b7449926
XL
1// run-pass
2
3#![allow(non_camel_case_types)]
4
1a4d82fc
JJ
5use std::cell::Cell;
6
223e47cc 7// Make sure that destructors get run on slice literals
1a4d82fc 8struct foo<'a> {
c34b1796 9 x: &'a Cell<isize>,
223e47cc
LB
10}
11
1a4d82fc
JJ
12impl<'a> Drop for foo<'a> {
13 fn drop(&mut self) {
14 self.x.set(self.x.get() + 1);
223e47cc
LB
15 }
16}
17
c34b1796 18fn foo(x: &Cell<isize>) -> foo {
223e47cc
LB
19 foo {
20 x: x
21 }
22}
23
24pub fn main() {
1a4d82fc 25 let x = &Cell::new(0);
223e47cc
LB
26 {
27 let l = &[foo(x)];
1a4d82fc 28 assert_eq!(l[0].x.get(), 0);
223e47cc 29 }
1a4d82fc 30 assert_eq!(x.get(), 1);
223e47cc 31}