From fae75c93b3df9c99f10aee03acf5e5570d6fc3af Mon Sep 17 00:00:00 2001 From: Jonathan S Date: Sun, 17 Jan 2016 09:47:21 -0600 Subject: Fix and test variance of BTreeMap and its companion structs. --- .../compile-fail/variance-btree-invariant-types.rs | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/test/compile-fail/variance-btree-invariant-types.rs (limited to 'src/test') diff --git a/src/test/compile-fail/variance-btree-invariant-types.rs b/src/test/compile-fail/variance-btree-invariant-types.rs new file mode 100644 index 00000000000..ad94a3865ac --- /dev/null +++ b/src/test/compile-fail/variance-btree-invariant-types.rs @@ -0,0 +1,56 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(rustc_attrs)] + +use std::collections::btree_map::{IterMut, OccupiedEntry, VacantEntry}; + +macro_rules! test_invariant { + { $m:ident $t:ident } => { + mod $m { + use std::collections::btree_map::{IterMut, OccupiedEntry, VacantEntry}; + + fn not_covariant_key<'a, 'min,'max>(v: $t<'a, &'max (), ()>) + -> $t<'a, &'min (), ()> + where 'max : 'min + { + v //~ ERROR mismatched types + } + + fn not_contravariant_key<'a, 'min,'max>(v: $t<'a, &'min (), ()>) + -> $t<'a, &'max (), ()> + where 'max : 'min + { + v //~ ERROR mismatched types + } + + fn not_covariant_val<'a, 'min,'max>(v: $t<'a, (), &'max ()>) + -> $t<'a, (), &'min ()> + where 'max : 'min + { + v //~ ERROR mismatched types + } + + fn not_contravariant_val<'a, 'min,'max>(v: $t<'a, (), &'min ()>) + -> $t<'a, (), &'max ()> + where 'max : 'min + { + v //~ ERROR mismatched types + } + } + } +} + +test_invariant! { foo IterMut } +test_invariant! { bar OccupiedEntry } +test_invariant! { baz VacantEntry } + +#[rustc_error] +fn main() { } -- cgit 1.4.1-3-g733a5