forked from rust-lang/glacier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tracks rust-lang/rust#101696
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
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: Variant<MyType>| { | ||
a.field; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
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>; | ||
} | ||
|
||
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; | ||
}); | ||
} |