diff options
| author | Jonathan S <gereeter+code@gmail.com> | 2016-01-17 09:47:21 -0600 |
|---|---|---|
| committer | Jonathan S <gereeter+code@gmail.com> | 2016-01-17 10:08:22 -0600 |
| commit | fae75c93b3df9c99f10aee03acf5e5570d6fc3af (patch) | |
| tree | 75a0abdaf605acb24483b0f1d3fd6ce35441467c /src/test | |
| parent | bff52927f582e2ca8dea799bd58f06e654295e21 (diff) | |
| download | rust-fae75c93b3df9c99f10aee03acf5e5570d6fc3af.tar.gz rust-fae75c93b3df9c99f10aee03acf5e5570d6fc3af.zip | |
Fix and test variance of BTreeMap and its companion structs.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/variance-btree-invariant-types.rs | 56 |
1 files changed, 56 insertions, 0 deletions
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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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() { } |
