Skip to content

Commit

Permalink
Add more tests for type alias impl Trait
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Jun 11, 2020
1 parent f97070d commit 0954669
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/test/rustdoc/auxiliary/issue-73061.rs
@@ -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 src/test/rustdoc/issue-73061-cross-crate-opaque-assoc-type.rs
@@ -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()
}
}
@@ -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() {}
@@ -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() {}
@@ -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() {}
@@ -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`.
@@ -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 src/test/ui/type-alias-impl-trait/type-alias-nested-impl-trait.rs
@@ -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<_>>());
}

0 comments on commit 0954669

Please sign in to comment.