We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We need to handle the equality and partial equality lang items following this example from libcore 1.49
// taken from https://github.com/rust-lang/rust/blob/e1884a8e3c3e813aada8254edfa120e85bf5ffca/library/core/src/cmp.rs#L98 #[lang = "sized"] pub trait Sized {} #[lang = "eq"] #[stable(feature = "rust1", since = "1.0.0")] #[doc(alias = "==")] #[doc(alias = "!=")] 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) } } enum BookFormat { Paperback, Hardback, Ebook, } impl PartialEq<BookFormat> for BookFormat { fn eq(&self, other: &BookFormat) -> bool { self == other } } struct Book { isbn: i32, format: BookFormat, } // Implement <Book> == <BookFormat> comparisons impl PartialEq<BookFormat> for Book { fn eq(&self, other: &BookFormat) -> bool { self.format == *other } } // Implement <BookFormat> == <Book> comparisons impl PartialEq<Book> for BookFormat { fn eq(&self, other: &Book) -> bool { *self == other.format } } // Implement <Book> == <Book> comparisons impl PartialEq<Book> for Book { fn eq(&self, other: &Book) -> bool { *self == other.format } } pub fn test() { let b1 = Book { isbn: 1, format: BookFormat::Paperback, }; let b2 = Book { isbn: 2, format: BookFormat::Paperback, }; let c1: bool = b1 == BookFormat::Paperback; let c2: bool = BookFormat::Paperback == b2; let c3: bool = b1 == b2; }
The text was updated successfully, but these errors were encountered:
gccrs: add support for lang_item eq and PartialEq trait
7a5ba86
TODO Fixes #3302 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): * backend/rust-compile-expr.h: * hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): * hir/tree/rust-hir-expr.h: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): (TypeCheckExpr::resolve_operator_overload): * typecheck/rust-hir-type-check-expr.h: * util/rust-lang-item.cc (LangItem::ComparisonToLangItem): (LangItem::ComparisonToSegment): * util/rust-lang-item.h: Signed-off-by: Philip Herron <[email protected]>
philberty
No branches or pull requests
We need to handle the equality and partial equality lang items following this example from libcore 1.49
The text was updated successfully, but these errors were encountered: