2014-04-27 22:27:20 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
struct DroppableStruct;
|
2014-06-14 08:55:55 -05:00
|
|
|
enum DroppableEnum {
|
|
|
|
DroppableVariant1, DroppableVariant2
|
|
|
|
}
|
2014-04-27 22:27:20 -05:00
|
|
|
|
|
|
|
static mut DROPPED: bool = false;
|
|
|
|
|
|
|
|
impl Drop for DroppableStruct {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { DROPPED = true; }
|
|
|
|
}
|
|
|
|
}
|
2014-06-14 08:55:55 -05:00
|
|
|
impl Drop for DroppableEnum {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
unsafe { DROPPED = true; }
|
|
|
|
}
|
|
|
|
}
|
2014-04-27 22:27:20 -05:00
|
|
|
|
|
|
|
trait MyTrait { }
|
2014-05-05 20:56:44 -05:00
|
|
|
impl MyTrait for Box<DroppableStruct> {}
|
2014-06-14 08:55:55 -05:00
|
|
|
impl MyTrait for Box<DroppableEnum> {}
|
2014-04-27 22:27:20 -05:00
|
|
|
|
2014-08-27 20:46:52 -05:00
|
|
|
struct Whatever { w: Box<MyTrait+'static> }
|
2014-04-27 22:27:20 -05:00
|
|
|
impl Whatever {
|
2014-08-27 20:46:52 -05:00
|
|
|
fn new(w: Box<MyTrait+'static>) -> Whatever {
|
2014-04-27 22:27:20 -05:00
|
|
|
Whatever { w: w }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
{
|
2014-05-05 20:56:44 -05:00
|
|
|
let f = box DroppableStruct;
|
|
|
|
let _a = Whatever::new(box f as Box<MyTrait>);
|
2014-04-27 22:27:20 -05:00
|
|
|
}
|
|
|
|
assert!(unsafe { DROPPED });
|
2014-06-14 08:55:55 -05:00
|
|
|
unsafe { DROPPED = false; }
|
|
|
|
{
|
2014-11-06 02:05:53 -06:00
|
|
|
let f = box DroppableEnum::DroppableVariant1;
|
2014-06-14 08:55:55 -05:00
|
|
|
let _a = Whatever::new(box f as Box<MyTrait>);
|
|
|
|
}
|
|
|
|
assert!(unsafe { DROPPED });
|
2014-04-27 22:27:20 -05:00
|
|
|
}
|