]> git.proxmox.com Git - rustc.git/blob - src/test/ui/regions/regions-variance-contravariant-use-contravariant.rs
New upstream version 1.51.0+dfsg1
[rustc.git] / src / test / ui / regions / regions-variance-contravariant-use-contravariant.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_variables)]
4 // Test that a type which is contravariant with respect to its region
5 // parameter compiles successfully when used in a contravariant way.
6 //
7 // Note: see ui/variance/variance-regions-*.rs for the tests that check that the
8 // variance inference works in the first place.
9
10 // pretty-expanded FIXME #23616
11
12 struct Contravariant<'a> {
13 f: &'a isize
14 }
15
16 fn use_<'a>(c: Contravariant<'a>) {
17 let x = 3;
18
19 // 'b winds up being inferred to this call.
20 // Contravariant<'a> <: Contravariant<'call> is true
21 // if 'call <= 'a, which is true, so no error.
22 collapse(&x, c);
23
24 fn collapse<'b>(x: &'b isize, c: Contravariant<'b>) { }
25 }
26
27 pub fn main() {}