Skip to content

Commit

Permalink
Expand the macro in variance-btree-invariant-types.rs to make compile…
Browse files Browse the repository at this point in the history
…test recognize that it should error
  • Loading branch information
gereeter committed Jan 17, 2016
1 parent fae75c9 commit 7a9c4a4
Showing 1 changed file with 43 additions and 36 deletions.
79 changes: 43 additions & 36 deletions src/test/compile-fail/variance-btree-invariant-types.rs
Expand Up @@ -12,45 +12,52 @@

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 iter_cov_key<'a, 'new>(v: IterMut<'a, &'static (), ()>) -> IterMut<'a, &'new (), ()> {
v //~ ERROR mismatched types
}
fn iter_cov_val<'a, 'new>(v: IterMut<'a, (), &'static ()>) -> IterMut<'a, (), &'new ()> {
v //~ ERROR mismatched types
}
fn iter_contra_key<'a, 'new>(v: IterMut<'a, &'new (), ()>) -> IterMut<'a, &'static (), ()> {
v //~ ERROR mismatched types
}
fn iter_contra_val<'a, 'new>(v: IterMut<'a, (), &'new ()>) -> IterMut<'a, (), &'static ()> {
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
}
}
}
fn occ_cov_key<'a, 'new>(v: OccupiedEntry<'a, &'static (), ()>)
-> OccupiedEntry<'a, &'new (), ()> {
v //~ ERROR mismatched types
}
fn occ_cov_val<'a, 'new>(v: OccupiedEntry<'a, (), &'static ()>)
-> OccupiedEntry<'a, (), &'new ()> {
v //~ ERROR mismatched types
}
fn occ_contra_key<'a, 'new>(v: OccupiedEntry<'a, &'new (), ()>)
-> OccupiedEntry<'a, &'static (), ()> {
v //~ ERROR mismatched types
}
fn occ_contra_val<'a, 'new>(v: OccupiedEntry<'a, (), &'new ()>)
-> OccupiedEntry<'a, (), &'static ()> {
v //~ ERROR mismatched types
}

test_invariant! { foo IterMut }
test_invariant! { bar OccupiedEntry }
test_invariant! { baz VacantEntry }
fn vac_cov_key<'a, 'new>(v: VacantEntry<'a, &'static (), ()>)
-> VacantEntry<'a, &'new (), ()> {
v //~ ERROR mismatched types
}
fn vac_cov_val<'a, 'new>(v: VacantEntry<'a, (), &'static ()>)
-> VacantEntry<'a, (), &'new ()> {
v //~ ERROR mismatched types
}
fn vac_contra_key<'a, 'new>(v: VacantEntry<'a, &'new (), ()>)
-> VacantEntry<'a, &'static (), ()> {
v //~ ERROR mismatched types
}
fn vac_contra_val<'a, 'new>(v: VacantEntry<'a, (), &'new ()>)
-> VacantEntry<'a, (), &'static ()> {
v //~ ERROR mismatched types
}

#[rustc_error]
fn main() { }

0 comments on commit 7a9c4a4

Please sign in to comment.