-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instantiate closure-like bounds with placeholders to deal with binder…
…s correctly
- Loading branch information
1 parent
519d892
commit 24482c8
Showing
3 changed files
with
139 additions
and
82 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
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
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,51 @@ | ||
//@ edition:2024 | ||
//@ compile-flags: -Zunstable-options | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
#![feature(unboxed_closures, gen_blocks)] | ||
|
||
trait Dispatch { | ||
fn dispatch(self); | ||
} | ||
|
||
struct Fut<T>(T); | ||
impl<T: for<'a> Fn<(&'a (),)>> Dispatch for Fut<T> | ||
where | ||
for<'a> <T as FnOnce<(&'a (),)>>::Output: Future, | ||
{ | ||
fn dispatch(self) { | ||
(self.0)(&()); | ||
} | ||
} | ||
|
||
struct Gen<T>(T); | ||
impl<T: for<'a> Fn<(&'a (),)>> Dispatch for Gen<T> | ||
where | ||
for<'a> <T as FnOnce<(&'a (),)>>::Output: Iterator, | ||
{ | ||
fn dispatch(self) { | ||
(self.0)(&()); | ||
} | ||
} | ||
|
||
struct Closure<T>(T); | ||
impl<T: for<'a> Fn<(&'a (),)>> Dispatch for Closure<T> | ||
where | ||
for<'a> <T as FnOnce<(&'a (),)>>::Output: Fn<(&'a (),)>, | ||
{ | ||
fn dispatch(self) { | ||
(self.0)(&())(&()); | ||
} | ||
} | ||
|
||
fn main() { | ||
async fn foo(_: &()) {} | ||
Fut(foo).dispatch(); | ||
|
||
gen fn bar(_: &()) {} | ||
Gen(bar).dispatch(); | ||
|
||
fn uwu<'a>(x: &'a ()) -> impl Fn(&'a ()) { |_| {} } | ||
Closure(uwu).dispatch(); | ||
} |