Skip to content

Commit 0954669

Browse files
committed
Add more tests for type alias impl Trait
1 parent f97070d commit 0954669

8 files changed

+163
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//edition:2018
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
pub trait Foo {
6+
type X: std::future::Future<Output = ()>;
7+
fn x(&self) -> Self::X;
8+
}
9+
10+
pub struct F;
11+
12+
impl Foo for F {
13+
type X = impl std::future::Future<Output = ()>;
14+
fn x(&self) -> Self::X {
15+
async {}
16+
}
17+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for ICE #73061
2+
3+
// aux-build:issue-73061.rs
4+
5+
extern crate issue_73061;
6+
7+
pub struct Z;
8+
9+
impl issue_73061::Foo for Z {
10+
type X = <issue_73061::F as issue_73061::Foo>::X;
11+
fn x(&self) -> Self::X {
12+
issue_73061::F.x()
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Regression test for #57188
2+
3+
// check-pass
4+
5+
#![feature(type_alias_impl_trait)]
6+
7+
struct Baz<'a> {
8+
source: &'a str,
9+
}
10+
11+
trait Foo<'a> {
12+
type T: Iterator<Item = Baz<'a>> + 'a;
13+
fn foo(source: &'a str) -> Self::T;
14+
}
15+
16+
struct Bar;
17+
impl<'a> Foo<'a> for Bar {
18+
type T = impl Iterator<Item = Baz<'a>> + 'a;
19+
fn foo(source: &'a str) -> Self::T {
20+
std::iter::once(Baz { source })
21+
}
22+
}
23+
24+
fn main() {}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Regression test for #62988
2+
3+
// check-pass
4+
5+
#![feature(type_alias_impl_trait)]
6+
7+
trait MyTrait {
8+
type AssocType: Send;
9+
fn ret(&self) -> Self::AssocType;
10+
}
11+
12+
impl MyTrait for () {
13+
type AssocType = impl Send;
14+
fn ret(&self) -> Self::AssocType {
15+
()
16+
}
17+
}
18+
19+
impl<'a> MyTrait for &'a () {
20+
type AssocType = impl Send;
21+
fn ret(&self) -> Self::AssocType {
22+
()
23+
}
24+
}
25+
26+
trait MyLifetimeTrait<'a> {
27+
type AssocType: Send + 'a;
28+
fn ret(&self) -> Self::AssocType;
29+
}
30+
31+
impl<'a> MyLifetimeTrait<'a> for &'a () {
32+
type AssocType = impl Send + 'a;
33+
fn ret(&self) -> Self::AssocType {
34+
*self
35+
}
36+
}
37+
38+
fn main() {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Regression test for #69136
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
trait SomeTrait {}
6+
7+
impl SomeTrait for () {}
8+
9+
trait WithAssoc<A> {
10+
type AssocType;
11+
}
12+
13+
impl<T> WithAssoc<T> for () {
14+
type AssocType = ();
15+
}
16+
17+
type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
18+
//~^ ERROR use of undeclared lifetime name `'a`
19+
20+
fn my_fun() -> Return<()> {}
21+
22+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0261]: use of undeclared lifetime name `'a`
2+
--> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:65
3+
|
4+
LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
5+
| - ^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'a` here: `'a,`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0261`.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Test-pass variant of #69136
2+
3+
// check-pass
4+
5+
#![feature(type_alias_impl_trait)]
6+
7+
trait SomeTrait {}
8+
9+
impl SomeTrait for () {}
10+
11+
trait WithAssoc {
12+
type AssocType;
13+
}
14+
15+
impl WithAssoc for () {
16+
type AssocType = ();
17+
}
18+
19+
type Return<'a> = impl WithAssoc<AssocType = impl Sized + 'a>;
20+
21+
fn my_fun<'a>() -> Return<'a> {}
22+
23+
fn main() {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
use std::iter::{once, Chain};
6+
7+
type I<A> = Chain<A, impl Iterator<Item = &'static str>>;
8+
fn test2<A: Iterator<Item = &'static str>>(x: A) -> I<A> {
9+
x.chain(once("5"))
10+
}
11+
12+
fn main() {
13+
assert_eq!(vec!["1", "3", "5"], test2(["1", "3"].iter().cloned()).collect::<Vec<_>>());
14+
}

0 commit comments

Comments
 (0)