Skip to content

Commit

Permalink
More associated type tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed Feb 2, 2021
1 parent b81f581 commit f0a3de6
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/test/ui/associated-types/issue-24159.rs
Original file line number Diff line number Diff line change
@@ -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() {}
19 changes: 19 additions & 0 deletions src/test/ui/associated-types/issue-37808.rs
Original file line number Diff line number Diff line change
@@ -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() {}
25 changes: 25 additions & 0 deletions src/test/ui/associated-types/issue-37883.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
14 changes: 14 additions & 0 deletions src/test/ui/associated-types/issue-39532.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit f0a3de6

Please sign in to comment.