2012-12-10 19:32:48 -06:00
|
|
|
// 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.
|
|
|
|
|
2012-07-31 12:27:51 -05:00
|
|
|
trait box_trait<T> {
|
2012-04-06 10:16:20 -05:00
|
|
|
fn get() -> T;
|
|
|
|
fn set(t: T);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum box_impl<T> = {
|
|
|
|
mut f: T
|
|
|
|
};
|
|
|
|
|
2012-09-07 16:52:28 -05:00
|
|
|
impl<T:Copy> box_impl<T>: box_trait<T> {
|
2012-08-01 19:30:05 -05:00
|
|
|
fn get() -> T { return self.f; }
|
2012-04-06 10:16:20 -05:00
|
|
|
fn set(t: T) { self.f = t; }
|
|
|
|
}
|
|
|
|
|
2012-07-31 12:27:51 -05:00
|
|
|
fn set_box_trait<T>(b: box_trait<@const T>, v: @const T) {
|
2012-04-06 10:16:20 -05:00
|
|
|
b.set(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_box_impl<T>(b: box_impl<@const T>, v: @const T) {
|
|
|
|
b.set(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let b = box_impl::<@int>({mut f: @3});
|
2012-07-31 12:27:51 -05:00
|
|
|
set_box_trait(b as box_trait::<@int>, @mut 5);
|
2012-06-30 06:23:59 -05:00
|
|
|
//~^ ERROR values differ in mutability
|
2012-04-06 10:16:20 -05:00
|
|
|
set_box_impl(b, @mut 5);
|
2012-06-30 06:23:59 -05:00
|
|
|
//~^ ERROR values differ in mutability
|
2012-04-06 10:16:20 -05:00
|
|
|
}
|