2019-07-03 15:20:16 -05:00
|
|
|
// check-pass
|
|
|
|
// edition:2018
|
2020-10-25 04:33:13 -05:00
|
|
|
// revisions: default sa
|
2019-07-03 15:20:16 -05:00
|
|
|
|
2021-07-26 15:01:16 -05:00
|
|
|
#![feature(type_alias_impl_trait)]
|
2019-07-03 15:20:16 -05:00
|
|
|
|
|
|
|
// See issue 60414
|
|
|
|
|
|
|
|
// Reduction to `impl Trait`
|
|
|
|
|
|
|
|
struct Foo<T>(T);
|
|
|
|
|
2021-07-14 10:31:58 -05:00
|
|
|
trait FooLike {
|
|
|
|
type Output;
|
|
|
|
}
|
2019-07-03 15:20:16 -05:00
|
|
|
|
|
|
|
impl<T> FooLike for Foo<T> {
|
|
|
|
type Output = T;
|
|
|
|
}
|
|
|
|
|
|
|
|
mod impl_trait {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
trait Trait {
|
|
|
|
type Assoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// `T::Assoc` should be normalized to `()` here.
|
2021-07-14 10:31:58 -05:00
|
|
|
fn foo_pass<T: Trait<Assoc = ()>>() -> impl FooLike<Output = T::Assoc> {
|
2019-07-03 15:20:16 -05:00
|
|
|
Foo(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same with lifetimes in the trait
|
|
|
|
|
|
|
|
mod lifetimes {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
trait Trait<'a> {
|
|
|
|
type Assoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Like above.
|
2019-07-09 05:57:52 -05:00
|
|
|
///
|
|
|
|
/// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
|
2021-07-14 10:31:58 -05:00
|
|
|
fn foo2_pass<'a, T: Trait<'a, Assoc = ()> + 'a>()
|
|
|
|
-> impl FooLike<Output = <T as Trait<'a>>::Assoc> + 'a {
|
2019-07-03 15:20:16 -05:00
|
|
|
Foo(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Normalization to type containing bound region.
|
2019-07-09 05:57:52 -05:00
|
|
|
///
|
|
|
|
/// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
|
2021-07-14 10:31:58 -05:00
|
|
|
fn foo2_pass2<'a, T: Trait<'a, Assoc = &'a ()> + 'a>()
|
|
|
|
-> impl FooLike<Output = <T as Trait<'a>>::Assoc> + 'a {
|
2019-07-03 15:20:16 -05:00
|
|
|
Foo(&())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-31 18:40:42 -05:00
|
|
|
// The same applied to `type Foo = impl Bar`s
|
2019-07-03 15:20:16 -05:00
|
|
|
|
2019-07-31 18:40:42 -05:00
|
|
|
mod opaque_types {
|
2019-07-03 15:20:16 -05:00
|
|
|
trait Implemented {
|
|
|
|
type Assoc;
|
|
|
|
}
|
|
|
|
impl<T> Implemented for T {
|
|
|
|
type Assoc = u8;
|
|
|
|
}
|
|
|
|
|
|
|
|
trait Trait {
|
|
|
|
type Out;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Trait for () {
|
|
|
|
type Out = u8;
|
|
|
|
}
|
|
|
|
|
2019-07-29 18:11:58 -05:00
|
|
|
type Ex = impl Trait<Out = <() as Implemented>::Assoc>;
|
2019-07-03 15:20:16 -05:00
|
|
|
|
|
|
|
fn define() -> Ex {
|
|
|
|
()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|