mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
37 lines
587 B
Rust
37 lines
587 B
Rust
//@ check-pass
|
|
|
|
use std::marker::PhantomData;
|
|
|
|
#[derive(Default)]
|
|
struct MyType<'a> {
|
|
field: usize,
|
|
_phantom: PhantomData<&'a ()>,
|
|
}
|
|
|
|
#[derive(Default)]
|
|
struct MyTypeVariant<'a> {
|
|
field: usize,
|
|
_phantom: PhantomData<&'a ()>,
|
|
}
|
|
|
|
trait AsVariantTrait {
|
|
type Type;
|
|
}
|
|
|
|
impl<'a> AsVariantTrait for MyType<'a> {
|
|
type Type = MyTypeVariant<'a>;
|
|
}
|
|
|
|
type Variant<G> = <G as AsVariantTrait>::Type;
|
|
|
|
fn foo<T: Default, F: FnOnce(T)>(f: F) {
|
|
let input = T::default();
|
|
f(input);
|
|
}
|
|
|
|
fn main() {
|
|
foo(|a: <MyType as AsVariantTrait>::Type| {
|
|
a.field;
|
|
});
|
|
}
|