rust/tests/ui/impl-trait/in-trait/opaque-in-impl.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
923 B
Rust
Raw Normal View History

2022-08-30 23:46:54 -05:00
// check-pass
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next
2022-08-30 23:46:54 -05:00
#![feature(return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]
2022-09-06 10:37:00 -05:00
use std::fmt::Debug;
2022-08-30 23:46:54 -05:00
trait Foo {
2022-09-06 10:37:00 -05:00
fn foo(&self) -> impl Debug;
2022-08-30 23:46:54 -05:00
}
impl Foo for () {
2022-09-06 10:37:00 -05:00
fn foo(&self) -> impl Debug {
2022-08-30 23:46:54 -05:00
"Hello, world"
}
}
2022-09-06 10:37:00 -05:00
impl<T: Default + Debug> Foo for std::marker::PhantomData<T> {
fn foo(&self) -> impl Debug {
T::default()
}
}
trait Bar {
fn bar<T>(&self) -> impl Debug;
}
impl Bar for () {
fn bar<T>(&self) -> impl Debug {
format!("Hello with generic {}", std::any::type_name::<T>())
}
}
trait Baz {
fn baz(&self) -> impl Debug + '_;
}
impl Baz for String {
fn baz(&self) -> impl Debug + '_ {
(self,)
}
}
2022-08-30 23:46:54 -05:00
fn main() {
2022-09-06 10:37:00 -05:00
println!("{:?}", ().foo());
println!("{:?}", ().bar::<u64>());
println!("{:?}", "hi".to_string().baz());
2022-08-30 23:46:54 -05:00
}