Demonstrating bugfix to trait constraints
I wasn't able to reproduce the error shown in #3325---I believe it to be
resolved in the form shown in This PR adds the code from that
issue to the test suite.
Closes
script;
+use core::ops::*;
+
use std::{
assert::assert,
logging::log,
@@ -139,6 +141,27 @@ fn do_math3<T>(a: MyPoint<T>, b: MyPoint<T>) -> MyPoint<T> where T: MyMath {
}
}
+enum MyOption<T> {
+ Some: T,
+ None: ()
+}
+
+impl<T> MyOption<T> {
+ pub fn ok_or<E>(self, err: E) -> Result<T, E> {
+ match self {
+ MyOption::Some(v) => Result::Ok(v),
+ MyOption::None => Result::Err(err),
+ }
+ }
+}
+
+fn test_ok_or<T, E>(val: T, default: E) where T: Eq, E: Eq {
+ match MyOption::Some(val).ok_or(default) {
+ Result::Ok(inner) => assert(val == inner),
+ Result::Err(_) => revert(0),
+ }
+}
+
fn main() -> u64 {
let a = MyPoint {
x: 1u64,
@@ -198,5 +221,7 @@ fn main() -> u64 {
assert(m.x == 12u64);
assert(m.y == 20u64);
+ test_ok_or(true, 0);
+
42
}
