diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/variance/variance-types.rs | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/variance/variance-types.rs')
-rw-r--r-- | tests/ui/variance/variance-types.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/ui/variance/variance-types.rs b/tests/ui/variance/variance-types.rs new file mode 100644 index 000000000..b9b6d9c9b --- /dev/null +++ b/tests/ui/variance/variance-types.rs @@ -0,0 +1,41 @@ +#![allow(dead_code)] +#![feature(rustc_attrs)] + +use std::cell::Cell; + +// Check that a type parameter which is only used in a trait bound is +// not considered bivariant. + +#[rustc_variance] +struct InvariantMut<'a,A:'a,B:'a> { //~ ERROR [-, o, o] + t: &'a mut (A,B) +} + +#[rustc_variance] +struct InvariantCell<A> { //~ ERROR [o] + t: Cell<A> +} + +#[rustc_variance] +struct InvariantIndirect<A> { //~ ERROR [o] + t: InvariantCell<A> +} + +#[rustc_variance] +struct Covariant<A> { //~ ERROR [+] + t: A, u: fn() -> A +} + +#[rustc_variance] +struct Contravariant<A> { //~ ERROR [-] + t: fn(A) +} + +#[rustc_variance] +enum Enum<A,B,C> { //~ ERROR [+, -, o] + Foo(Covariant<A>), + Bar(Contravariant<B>), + Zed(Covariant<C>,Contravariant<C>) +} + +pub fn main() { } |