summary refs log tree commit diff
path: root/src/test/compile-fail/fn-variance-3.rs
blob: ff8511aeae5e8f86698673ec1adefacf6d5f38a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn mk_identity<T:copy>() -> fn@(T) -> T {
    fn@(t: T) -> T { t }
}

fn main() {
    // type of r is fn@(X) -> X
    // for some fresh X
    let r = mk_identity();

    // @mut int <: X
    r(@mut 3);

    // @int <: X
    //
    // This constraint forces X to be
    // @const int.
    r(@3);

    // Here the type check succeeds but the
    // mutability check will fail, because the
    // type of r has been inferred to be
    // fn(@const int) -> @const int
    *r(@mut 3) = 4; //! ERROR assigning to immutable box
}