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

48 lines
782 B
Rust
Raw Normal View History

2022-08-30 23:46:54 -05:00
// check-pass
#![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
}