rust/src/test/compile-fail/fn-variance-2.rs

23 lines
433 B
Rust
Raw Normal View History

fn reproduce<T:copy>(t: T) -> fn@() -> T {
fn@() -> T { t }
}
fn main() {
// type of x is the variable X,
// with the lower bound @mut int
let x = @mut 3;
// type of r is fn@() -> X
let r = reproduce(x);
// Requires that X be a subtype of
// @mut int.
let f: @mut int = r();
// OK.
let g: @const int = r();
// Bad.
let h: @int = r(); //~ ERROR (values differ in mutability)
}