mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
More associated type tests
This commit is contained in:
parent
b81f5811f9
commit
f0a3de6aa2
37
src/test/ui/associated-types/issue-24159.rs
Normal file
37
src/test/ui/associated-types/issue-24159.rs
Normal 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() {}
|
19
src/test/ui/associated-types/issue-37808.rs
Normal file
19
src/test/ui/associated-types/issue-37808.rs
Normal 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() {}
|
25
src/test/ui/associated-types/issue-37883.rs
Normal file
25
src/test/ui/associated-types/issue-37883.rs
Normal 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
|
||||
}
|
||||
}
|
14
src/test/ui/associated-types/issue-39532.rs
Normal file
14
src/test/ui/associated-types/issue-39532.rs
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user