From ebb591a5704f767d783d57af7022272f665318ac Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jun 2021 00:30:22 +0300 Subject: internal: add derive and ord support to minicore --- crates/test_utils/src/minicore.rs | 62 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'crates/test_utils') diff --git a/crates/test_utils/src/minicore.rs b/crates/test_utils/src/minicore.rs index a5a7c2f7d..9ec541c57 100644 --- a/crates/test_utils/src/minicore.rs +++ b/crates/test_utils/src/minicore.rs @@ -24,6 +24,9 @@ //! iterators: iterator //! default: sized //! from: sized +//! eq: sized +//! ord: eq, option +//! derive: pub mod marker { // region:sized @@ -173,6 +176,49 @@ pub mod ops { // endregion:fn } +// region:eq +pub mod cmp { + #[lang = "eq"] + pub trait PartialEq { + fn eq(&self, other: &Rhs) -> bool; + } + + pub trait Eq: PartialEq {} + + // region:derive + #[rustc_builtin_macro] + pub macro PartialEq($item:item) {} + #[rustc_builtin_macro] + pub macro Eq($item:item) {} + // endregion:derive + + // region:ord + #[lang = "partial_ord"] + pub trait PartialOrd: PartialEq { + fn partial_cmp(&self, other: &Rhs) -> Option; + } + + pub trait Ord: Eq + PartialOrd { + fn cmp(&self, other: &Self) -> Ordering; + } + + pub enum Ordering { + Less = -1, + Equal = 0, + Greater = 1, + } + + // region:derive + #[rustc_builtin_macro] + pub macro PartialOrd($item:item) {} + #[rustc_builtin_macro] + pub macro Ord($item:item) {} + // endregion:derive + + // endregion:ord +} +// endregion:eq + // region:slice pub mod slice { #[lang = "slice"] @@ -342,16 +388,30 @@ pub mod iter { } // endregion:iterator +// region:derive +mod macros { + pub(crate) mod builtin { + #[rustc_builtin_macro] + pub macro derive($item:item) { + /* compiler built-in */ + } + } +} +// endregion:derive + pub mod prelude { pub mod v1 { pub use crate::{ + cmp::{Eq, PartialEq}, // :eq + cmp::{Ord, PartialOrd}, // :ord + convert::{From, Into}, // :from default::Default, // :default iter::{IntoIterator, Iterator}, // :iterator + macros::builtin::derive, // :derive marker::Sized, // :sized ops::{Fn, FnMut, FnOnce}, // :fn option::Option::{self, None, Some}, // :option result::Result::{self, Err, Ok}, // :result - convert::{From, Into}, // :from }; } -- cgit v1.2.3