Add more tests for type alias impl Trait
This commit is contained in:
parent
f97070db90
commit
09546692ff
|
@ -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 {}
|
||||
}
|
||||
}
|
|
@ -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() {}
|
|
@ -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<_>>());
|
||||
}
|
Loading…
Reference in New Issue