Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/test-utils/src/minicore.rs')
| -rw-r--r-- | crates/test-utils/src/minicore.rs | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs index 696928b522..0fe17e3075 100644 --- a/crates/test-utils/src/minicore.rs +++ b/crates/test-utils/src/minicore.rs @@ -68,6 +68,7 @@ //! transmute: //! try: infallible //! tuple: +//! unary_ops: //! unpin: sized //! unsize: sized //! write: fmt @@ -591,13 +592,13 @@ pub mod ops { impl<T: PointeeSized> Deref for &T { type Target = T; fn deref(&self) -> &T { - loop {} + *self } } impl<T: PointeeSized> Deref for &mut T { type Target = T; fn deref(&self) -> &T { - loop {} + *self } } // region:deref_mut @@ -1056,6 +1057,9 @@ pub mod ops { type Output = $t; fn add(self, other: $t) -> $t { self + other } } + impl AddAssign for $t { + fn add_assign(&mut self, other: $t) { *self += other; } + } )*) } @@ -1063,6 +1067,24 @@ pub mod ops { // endregion:builtin_impls // endregion:add + // region:unary_ops + #[lang = "not"] + pub const trait Not { + type Output; + + #[must_use] + fn not(self) -> Self::Output; + } + + #[lang = "neg"] + pub const trait Neg { + type Output; + + #[must_use = "this returns the result of the operation, without modifying the original"] + fn neg(self) -> Self::Output; + } + // endregion:unary_ops + // region:coroutine mod coroutine { use crate::pin::Pin; @@ -1118,6 +1140,12 @@ pub mod cmp { pub trait Eq: PartialEq<Self> + PointeeSized {} + // region:builtin_impls + impl PartialEq for () { + fn eq(&self, other: &()) -> bool { true } + } + // endregion:builtin_impls + // region:derive #[rustc_builtin_macro] pub macro PartialEq($item:item) {} @@ -1490,6 +1518,12 @@ pub mod pin { { } // endregion:dispatch_from_dyn + // region:coerce_unsized + impl<Ptr, U> crate::ops::CoerceUnsized<Pin<U>> for Pin<Ptr> where + Ptr: crate::ops::CoerceUnsized<U> + { + } + // endregion:coerce_unsized } // endregion:pin @@ -1954,6 +1988,10 @@ pub mod num { // region:bool_impl #[lang = "bool"] impl bool { + pub fn then_some<T>(self, t: T) -> Option<T> { + if self { Some(t) } else { None } + } + pub fn then<T, F: FnOnce() -> T>(self, f: F) -> Option<T> { if self { Some(f()) } else { None } } |