]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/variance-types.rs
Rollup merge of #35710 - matthew-piziak:explicit-drop, r=steveklabnik
[rust.git] / src / test / compile-fail / variance-types.rs
1 // Copyright 2014 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 #![allow(dead_code)]
12 #![feature(rustc_attrs)]
13
14 use std::cell::Cell;
15
16 // Check that a type parameter which is only used in a trait bound is
17 // not considered bivariant.
18
19 #[rustc_variance]
20 struct InvariantMut<'a,A:'a,B:'a> { //~ ERROR types=[o, o], regions=[-]
21     t: &'a mut (A,B)
22 }
23
24 #[rustc_variance]
25 struct InvariantCell<A> { //~ ERROR types=[o]
26     t: Cell<A>
27 }
28
29 #[rustc_variance]
30 struct InvariantIndirect<A> { //~ ERROR types=[o]
31     t: InvariantCell<A>
32 }
33
34 #[rustc_variance]
35 struct Covariant<A> { //~ ERROR types=[+]
36     t: A, u: fn() -> A
37 }
38
39 #[rustc_variance]
40 struct Contravariant<A> { //~ ERROR types=[-]
41     t: fn(A)
42 }
43
44 #[rustc_variance]
45 enum Enum<A,B,C> { //~ ERROR types=[+, -, o]
46     Foo(Covariant<A>),
47     Bar(Contravariant<B>),
48     Zed(Covariant<C>,Contravariant<C>)
49 }
50
51 pub fn main() { }