-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #52650 - oli-obk:associated_existential_types, r=nikoma…
…tsakis Implement associated existential types r? @nikomatsakis no idea if these work with generic traits. I'm going home for the day 🤣
- Loading branch information
Showing
8 changed files
with
186 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/ui/impl-trait/associated-existential-type-generic-trait.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
30 changes: 30 additions & 0 deletions
30
src/test/ui/impl-trait/associated-existential-type-trivial.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() {} |