rust/src/test/compile-fail/issue-2548.rs

48 lines
1.0 KiB
Rust
Raw Normal View History

// Copyright 2012 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.
2013-10-23 04:49:18 -04:00
#[feature(managed_boxes)];
2012-08-03 10:22:16 -07:00
// A test case for #2548.
2013-12-31 15:46:27 -08:00
use std::cell::Cell;
2012-08-03 10:22:16 -07:00
2013-12-31 15:46:27 -08:00
struct foo {
x: @Cell<int>,
}
#[unsafe_destructor]
impl Drop for foo {
2013-09-16 21:18:07 -04:00
fn drop(&mut self) {
unsafe {
println("Goodbye, World!");
2013-12-31 15:46:27 -08:00
self.x.set(self.x.get() + 1);
}
2012-08-03 10:22:16 -07:00
}
}
2013-12-31 15:46:27 -08:00
fn foo(x: @Cell<int>) -> foo {
foo { x: x }
}
2012-08-03 10:22:16 -07:00
fn main() {
2013-12-31 15:46:27 -08:00
let x = @Cell::new(0);
2012-08-03 10:22:16 -07:00
{
let mut res = foo(x);
let mut v = ~[];
2013-07-11 12:05:17 -07:00
v = ~[(res)] + v; //~ failed to find an implementation of trait
assert_eq!(v.len(), 2);
2012-08-03 10:22:16 -07:00
}
2013-12-31 15:46:27 -08:00
assert_eq!(x.get(), 1);
2012-08-03 10:22:16 -07:00
}