Auto merge of #52650 - oli-obk:associated_existential_types, r=nikomatsakis

Implement associated existential types

r? @nikomatsakis

no idea if these work with generic traits. I'm going home for the day 🤣
This commit is contained in:
bors 2018-07-27 07:16:12 +00:00
commit 7c2aeb9d97
8 changed files with 186 additions and 30 deletions

View file

@ -0,0 +1,40 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(existential_type)]
// compile-pass
trait Bar {}
struct Dummy<U>(U);
impl<V> Bar for Dummy<V> {}
trait Foo<T> {
type Assoc: Bar;
fn foo(t: T) -> Self::Assoc;
}
impl<W> Foo<W> for i32 {
existential type Assoc: Bar;
fn foo(w: W) -> Self::Assoc {
Dummy(w)
}
}
struct NonGeneric;
impl Bar for NonGeneric {}
impl<W> Foo<W> for u32 {
existential type Assoc: Bar;
fn foo(_: W) -> Self::Assoc {
NonGeneric
}
}
fn main() {}

View file

@ -0,0 +1,30 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(existential_type)]
// compile-pass
trait Bar {}
struct Dummy;
impl Bar for Dummy {}
trait Foo {
type Assoc: Bar;
fn foo() -> Self::Assoc;
}
impl Foo for i32 {
existential type Assoc: Bar;
fn foo() -> Self::Assoc {
Dummy
}
}
fn main() {}

View file

@ -0,0 +1,34 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(existential_type)]
// compile-pass
trait Bar {}
struct Dummy;
impl Bar for Dummy {}
trait Foo {
type Assoc: Bar;
fn foo() -> Self::Assoc;
fn bar() -> Self::Assoc;
}
impl Foo for i32 {
existential type Assoc: Bar;
fn foo() -> Self::Assoc {
Dummy
}
fn bar() -> Self::Assoc {
Dummy
}
}
fn main() {}