diff options
Diffstat (limited to 'gcc/testsuite/rust/compile/derive-partialeq1.rs')
-rw-r--r-- | gcc/testsuite/rust/compile/derive-partialeq1.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/gcc/testsuite/rust/compile/derive-partialeq1.rs b/gcc/testsuite/rust/compile/derive-partialeq1.rs new file mode 100644 index 0000000..35e33fb --- /dev/null +++ b/gcc/testsuite/rust/compile/derive-partialeq1.rs @@ -0,0 +1,62 @@ +#![feature(intrinsics)] + +#[lang = "sized"] +trait Sized {} + +#[lang = "copy"] +trait Copy {} + +#[lang = "structural_peq"] +trait StructuralPartialEq {} + +#[lang = "eq"] +pub trait PartialEq<Rhs: ?Sized = Self> { + /// This method tests for `self` and `other` values to be equal, and is used + /// by `==`. + #[must_use] + #[stable(feature = "rust1", since = "1.0.0")] + fn eq(&self, other: &Rhs) -> bool; + + /// This method tests for `!=`. + #[inline] + #[must_use] + #[stable(feature = "rust1", since = "1.0.0")] + fn ne(&self, other: &Rhs) -> bool { + !self.eq(other) + } +} + +#[derive(PartialEq, Copy)] // { dg-warning "unused name" } +struct Foo; + +#[derive(PartialEq)] +struct Bar(Foo); + +#[derive(PartialEq)] +struct Baz { _inner: Foo } + +extern "C" { + fn puts(s: *const i8); +} + +fn print(b: bool) { + if b { + unsafe { puts("true" as *const str as *const i8) } + } else { + unsafe { puts("false" as *const str as *const i8) } + } +} + +fn main() -> i32 { + let x = Foo; + + let b1 = x == Foo; + let b2 = Bar(x) != Bar(Foo); + let b3 = Baz { _inner: Foo } != Baz { _inner: x }; + + print(b1); + print(b2); + print(b3); + + 0 +} |