Skip to content
New issue

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

Extend push_auto_trait_impl to built-in types #612

Merged
merged 14 commits into from
Sep 19, 2020
109 changes: 109 additions & 0 deletions tests/test/auto_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,112 @@ fn enum_auto_trait() {
}
}
}

#[test]
fn builtin_auto_trait() {
test! {
program {
#[auto] trait AutoTrait {}
struct Struct {}
enum Enum { Var1, Var2 }
fn func();

struct Marker {}
impl !AutoTrait for Marker {}

closure good_closure(self, arg: Marker) -> Marker { i32 }
closure bad_closure(self, arg: i32) -> i32 { Marker }

extern type Ext;
enum ExtEnum { GoodVariant, BadVariant(Ext) }
}

goal {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments on these would be nice.

Can we also get a test of a tuple that does impl the auto trait.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, Haha, that's below.

Clever, but I would feel better about splitting it up a bit.

(Struct, Marker): AutoTrait
}
yields {
"No possible solution"
}

goal {
forall<'a> { (fn(), [(); 1], [()], u32, *const (), str, !, Struct, Enum, func, good_closure, &'a ()): AutoTrait }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mutable ref and raw please

}
yields {
"Unique; substitution [], lifetime constraints []"
}

goal {
good_closure: AutoTrait
}
yields {
"Unique; substitution [], lifetime constraints []"
}

goal {
bad_closure: AutoTrait
}
yields {
"No possible solution"
}

goal {
ExtEnum: AutoTrait
}
yields {
"No possible solution"
}
}
}

#[test]
fn adt_auto_trait() {
test! {
program {
#[auto] trait AutoTrait {}
struct Yes {}
struct No {}
impl !AutoTrait for No {}

struct WrapperNo<T> { t: T }
struct WrapperYes<T> { t: T }

struct X {}
impl !AutoTrait for WrapperNo<X> {}
}

goal {
Yes: AutoTrait
}
yields {
"Unique; substitution [], lifetime constraints []"
}

goal {
No: AutoTrait
}
yields {
"No possible solution"
}

goal {
X: AutoTrait
}
yields {
"Unique; substitution [], lifetime constraints []"
}

goal {
WrapperNo<Yes>: AutoTrait
}
yields {
"No possible solution"
}

goal {
WrapperYes<No>: AutoTrait
}
yields {
"No possible solution"
}
}
}