diff options
| author | Michael Goulet <michael@errs.io> | 2024-03-09 22:12:33 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2024-04-01 22:48:23 -0400 |
| commit | 5f59b7f7634ac4b05923b47de00f2a13b213af1f (patch) | |
| tree | eff28d21a19ed4202f947a3079079e6a76091f5f /tests | |
| parent | dd5e502d4b095be205c07da1481846f0a07c43b4 (diff) | |
| download | rust-5f59b7f7634ac4b05923b47de00f2a13b213af1f.tar.gz rust-5f59b7f7634ac4b05923b47de00f2a13b213af1f.zip | |
Instantiate closure-like bounds with placeholders to deal with binders correctly
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/higher-ranked/builtin-closure-like-bounds.rs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/ui/higher-ranked/builtin-closure-like-bounds.rs b/tests/ui/higher-ranked/builtin-closure-like-bounds.rs new file mode 100644 index 00000000000..c7dfaefbc74 --- /dev/null +++ b/tests/ui/higher-ranked/builtin-closure-like-bounds.rs @@ -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(); +} \ No newline at end of file |
