]> git.lizzy.rs Git - rust.git/blob - src/test/ui/variance/variance-contravariant-arg-trait-match.rs
Rollup merge of #57107 - mjbshaw:thread_local_test, r=nikomatsakis
[rust.git] / src / test / ui / variance / variance-contravariant-arg-trait-match.rs
1 #![allow(dead_code)]
2
3 // Test that even when `T` is only used in contravariant position, it
4 // is treated as invariant.
5
6 trait Get<T> {
7     fn get(&self, t: T);
8 }
9
10 fn get_min_from_max<'min, 'max, G>()
11     where 'max : 'min, G : Get<&'max i32>
12 {
13     impls_get::<G,&'min i32>() //~ ERROR mismatched types
14 }
15
16 fn get_max_from_min<'min, 'max, G>()
17     where 'max : 'min, G : Get<&'min i32>
18 {
19     // Previously OK, but now an error because traits are invariant:
20
21     impls_get::<G,&'max i32>() //~ ERROR mismatched types
22 }
23
24 fn impls_get<G,T>() where G : Get<T> { }
25
26 fn main() { }