]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/regions-variance-contravariant-use-contravariant.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / regions-variance-contravariant-use-contravariant.rs
1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Test that a type which is contravariant with respect to its region
12 // parameter compiles successfully when used in a contravariant way.
13 //
14 // Note: see compile-fail/variance-regions-*.rs for the tests that check that the
15 // variance inference works in the first place.
16
17 struct Contravariant<'a> {
18     f: &'a int
19 }
20
21 fn use_<'a>(c: Contravariant<'a>) {
22     let x = 3;
23
24     // 'b winds up being inferred to this call.
25     // Contravariant<'a> <: Contravariant<'call> is true
26     // if 'call <= 'a, which is true, so no error.
27     collapse(&x, c);
28
29     fn collapse<'b>(x: &'b int, c: Contravariant<'b>) { }
30 }
31
32 pub fn main() {}