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:
commit
7c2aeb9d97
8 changed files with 186 additions and 30 deletions
|
|
@ -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() {}
|
||||
|
|
@ -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() {}
|
||||
34
src/test/ui/impl-trait/associated-existential-type.rs
Normal file
34
src/test/ui/impl-trait/associated-existential-type.rs
Normal 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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue