Remove defaults table and attach defaults directly to tyvars

This commit is contained in:
Jared Roesch 2015-07-09 12:15:48 -07:00 committed by Jared Roesch
parent bbdca2c8ad
commit 49eb2c6763
6 changed files with 143 additions and 41 deletions

View file

@ -0,0 +1,23 @@
use std::marker::PhantomData;
trait Id {
type This;
}
impl<A> Id for A {
type This = A;
}
struct Foo<X: Default = usize, Y = <X as Id>::This> {
data: PhantomData<(X, Y)>
}
impl<X: Default, Y> Foo<X, Y> {
fn new() -> Foo<X, Y> {
Foo { data: PhantomData }
}
}
fn main() {
let foo = Foo::new();
}

View file

@ -0,0 +1,7 @@
use std::marker::PhantomData;
struct Foo<T,U=T> { data: PhantomData<(T, U)> }
fn main() {
let foo = Foo { data: PhantomData };
}

View file

@ -0,0 +1,30 @@
use std::marker::PhantomData;
trait TypeEq<A> {}
impl<A> TypeEq<A> for A {}
struct DeterministicHasher;
struct RandomHasher;
struct MyHashMap<K, V, H=DeterministicHasher> {
data: PhantomData<(K, V, H)>
}
impl<K, V, H> MyHashMap<K, V, H> {
fn new() -> MyHashMap<K, V, H> {
MyHashMap { data: PhantomData }
}
}
mod mystd {
use super::{MyHashMap, RandomHasher};
pub type HashMap<K, V, H=RandomHasher> = MyHashMap<K, V, H>;
}
fn try_me<H>(hash_map: mystd::HashMap<i32, i32, H>) {}
fn main() {
let hash_map = mystd::HashMap::new();
try_me(hash_map);
}