1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#[macro_use]
extern crate derive_destructure2;
#[derive(remove_trait_impls)]
pub enum Simple {
A,
B,
C,
}
impl Drop for Simple {
fn drop(&mut self) {
panic!("We shouldn't drop this!");
}
}
#[test]
fn test_simple() {
let simple = Simple::A;
let simple = simple.remove_trait_impls();
if let SimpleWithoutTraitImpls::A = simple {
} else {
panic!();
}
}
pub trait SomeTrait {}
impl SomeTrait for i32 {}
#[derive(remove_trait_impls)]
pub enum GenericEnum<T: SomeTrait> {
A(T),
B(T, f64),
C { x: String, y: T },
D,
}
impl<T: SomeTrait> Drop for GenericEnum<T> {
fn drop(&mut self) {
panic!("We shouldn't drop this!");
}
}
#[test]
fn test_generic_a() {
let e = GenericEnum::A(5);
let e = e.remove_trait_impls();
if let GenericEnumWithoutTraitImpls::A(x) = e {
assert_eq!(x, 5);
} else {
panic!();
}
}
#[test]
fn test_generic_b() {
let e = GenericEnum::B(7, 8.9);
let e = e.remove_trait_impls();
if let GenericEnumWithoutTraitImpls::B(x, y) = e {
assert_eq!(x, 7);
assert_eq!(y, 8.9);
} else {
panic!();
}
}
#[test]
fn test_generic_c() {
let e = GenericEnum::C {
x: "foo".to_owned(),
y: 7,
};
let e = e.remove_trait_impls();
if let GenericEnumWithoutTraitImpls::C { x, y } = e {
assert_eq!(x, "foo");
assert_eq!(y, 7);
} else {
panic!();
}
}
#[test]
fn test_generic_d() {
let e = GenericEnum::<i32>::D;
let e = e.remove_trait_impls();
if let GenericEnumWithoutTraitImpls::D = e {
} else {
panic!();
}
}
|