forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more tests for type alias impl Trait
- Loading branch information
1 parent
f97070d
commit 0954669
Showing
8 changed files
with
163 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//edition:2018 | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
pub trait Foo { | ||
type X: std::future::Future<Output = ()>; | ||
fn x(&self) -> Self::X; | ||
} | ||
|
||
pub struct F; | ||
|
||
impl Foo for F { | ||
type X = impl std::future::Future<Output = ()>; | ||
fn x(&self) -> Self::X { | ||
async {} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/test/rustdoc/issue-73061-cross-crate-opaque-assoc-type.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,14 @@ | ||
// Regression test for ICE #73061 | ||
|
||
// aux-build:issue-73061.rs | ||
|
||
extern crate issue_73061; | ||
|
||
pub struct Z; | ||
|
||
impl issue_73061::Foo for Z { | ||
type X = <issue_73061::F as issue_73061::Foo>::X; | ||
fn x(&self) -> Self::X { | ||
issue_73061::F.x() | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/type-alias-impl-trait/issue-57188-associate-impl-capture.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,24 @@ | ||
// Regression test for #57188 | ||
|
||
// check-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
struct Baz<'a> { | ||
source: &'a str, | ||
} | ||
|
||
trait Foo<'a> { | ||
type T: Iterator<Item = Baz<'a>> + 'a; | ||
fn foo(source: &'a str) -> Self::T; | ||
} | ||
|
||
struct Bar; | ||
impl<'a> Foo<'a> for Bar { | ||
type T = impl Iterator<Item = Baz<'a>> + 'a; | ||
fn foo(source: &'a str) -> Self::T { | ||
std::iter::once(Baz { source }) | ||
} | ||
} | ||
|
||
fn main() {} |
38 changes: 38 additions & 0 deletions
38
src/test/ui/type-alias-impl-trait/issue-62000-associate-impl-trait-lifetimes.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,38 @@ | ||
// Regression test for #62988 | ||
|
||
// check-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
trait MyTrait { | ||
type AssocType: Send; | ||
fn ret(&self) -> Self::AssocType; | ||
} | ||
|
||
impl MyTrait for () { | ||
type AssocType = impl Send; | ||
fn ret(&self) -> Self::AssocType { | ||
() | ||
} | ||
} | ||
|
||
impl<'a> MyTrait for &'a () { | ||
type AssocType = impl Send; | ||
fn ret(&self) -> Self::AssocType { | ||
() | ||
} | ||
} | ||
|
||
trait MyLifetimeTrait<'a> { | ||
type AssocType: Send + 'a; | ||
fn ret(&self) -> Self::AssocType; | ||
} | ||
|
||
impl<'a> MyLifetimeTrait<'a> for &'a () { | ||
type AssocType = impl Send + 'a; | ||
fn ret(&self) -> Self::AssocType { | ||
*self | ||
} | ||
} | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.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,22 @@ | ||
// Regression test for #69136 | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
trait SomeTrait {} | ||
|
||
impl SomeTrait for () {} | ||
|
||
trait WithAssoc<A> { | ||
type AssocType; | ||
} | ||
|
||
impl<T> WithAssoc<T> for () { | ||
type AssocType = (); | ||
} | ||
|
||
type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>; | ||
//~^ ERROR use of undeclared lifetime name `'a` | ||
|
||
fn my_fun() -> Return<()> {} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr
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,11 @@ | ||
error[E0261]: use of undeclared lifetime name `'a` | ||
--> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:65 | ||
| | ||
LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>; | ||
| - ^^ undeclared lifetime | ||
| | | ||
| help: consider introducing lifetime `'a` here: `'a,` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0261`. |
23 changes: 23 additions & 0 deletions
23
src/test/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-ok.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,23 @@ | ||
// Test-pass variant of #69136 | ||
|
||
// check-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
trait SomeTrait {} | ||
|
||
impl SomeTrait for () {} | ||
|
||
trait WithAssoc { | ||
type AssocType; | ||
} | ||
|
||
impl WithAssoc for () { | ||
type AssocType = (); | ||
} | ||
|
||
type Return<'a> = impl WithAssoc<AssocType = impl Sized + 'a>; | ||
|
||
fn my_fun<'a>() -> Return<'a> {} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/type-alias-impl-trait/type-alias-nested-impl-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,14 @@ | ||
// run-pass | ||
|
||
#![feature(type_alias_impl_trait)] | ||
|
||
use std::iter::{once, Chain}; | ||
|
||
type I<A> = Chain<A, impl Iterator<Item = &'static str>>; | ||
fn test2<A: Iterator<Item = &'static str>>(x: A) -> I<A> { | ||
x.chain(once("5")) | ||
} | ||
|
||
fn main() { | ||
assert_eq!(vec!["1", "3", "5"], test2(["1", "3"].iter().cloned()).collect::<Vec<_>>()); | ||
} |