More associated type tests

This commit is contained in:
Jack Huey 2021-02-02 12:54:32 -05:00
parent b81f5811f9
commit f0a3de6aa2
4 changed files with 95 additions and 0 deletions

View File

@ -0,0 +1,37 @@
// check-pass
#![allow(unused)]
trait Bar<T> {
fn dummy(&self);
}
trait Foo {
type A;
type B: Bar<Self::A>;
fn get_b(&self) -> &Self::B;
}
fn test_bar<A, B: Bar<A>>(_: &B) {}
fn test<A, F: Foo<A = A>>(f: &F) {
test_bar(f.get_b());
}
trait Bar1<T> {}
trait Caz1 {
type A;
type B: Bar1<Self::A>;
}
fn test1<T, U>() where T: Caz1, U: Caz1<A = T::A> {}
trait Bar2<T> {}
trait Caz2 {
type A;
type B: Bar2<Self::A>;
}
fn test2<T: Caz2<A = ()>>() {}
fn main() {}

View File

@ -0,0 +1,19 @@
// check-pass
trait Parent {
type Ty;
type Assoc: Child<Self::Ty>;
}
trait Child<T> {}
struct ChildWrapper<T>(T);
impl<A, T> Child<A> for ChildWrapper<T> where T: Child<A> {}
struct ParentWrapper<T>(T);
impl<A, T: Parent<Ty = A>> Parent for ParentWrapper<T> {
type Ty = A;
type Assoc = ChildWrapper<T::Assoc>;
}
fn main() {}

View File

@ -0,0 +1,25 @@
// check-pass
use std::ops::Mul;
fn main() {}
trait Ring {}
trait Real: Ring {}
trait Module: Sized + Mul<<Self as Module>::Ring, Output = Self> {
type Ring: Ring;
}
trait EuclideanSpace {
type Coordinates: Module<Ring = Self::Real>;
type Real: Real;
}
trait Translation<E: EuclideanSpace> {
fn to_vector(&self) -> E::Coordinates;
fn powf(&self, n: <E::Coordinates as Module>::Ring) -> E::Coordinates {
self.to_vector() * n
}
}

View File

@ -0,0 +1,14 @@
// check-pass
#![allow(unused)]
trait Foo {
type Bar;
type Baz: Bar<Self::Bar>;
}
trait Bar<T> {}
fn x<T: Foo<Bar = U>, U>(t: &T) {}
fn main() {}