forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#122267 - compiler-errors:closure-like-goals, …
…r=lcnr Eagerly instantiate closure/coroutine-like bounds with placeholders to deal with binders correctly A follow-up to rust-lang#119849, however it aims to fix a different set of issues. Currently, we have trouble confirming goals where built-in closure/fnptr/coroutine signatures are compared against higher-ranked goals. Currently, we don't support goals like `for<'a> fn(&'a ()): Fn(&'a ())` because we don't expect the self type of goal to reference any bound regions from the goal, because we don't really know how to deal with the double binder of predicate + self type. However, this definitely can be reached (rust-lang#121653) -- and in fact, it results in post-mono errors in the case of rust-lang#112347 where the builtin type (e.g. a coroutine) is hidden behind a TAIT. The proper fix here is to instantiate the goal before trying to extract the signature from the self type. See final two commits. r? lcnr
- Loading branch information
Showing
12 changed files
with
158 additions
and
141 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,58 @@ | ||
//@ edition:2024 | ||
//@ compile-flags: -Zunstable-options | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ check-pass | ||
|
||
// Makes sure that we support closure/coroutine goals where the signature of | ||
// the item references higher-ranked lifetimes from the *predicate* binder, | ||
// not its own internal signature binder. | ||
// | ||
// This was fixed in <https://github.com/rust-lang/rust/pull/122267>. | ||
|
||
#![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(); | ||
} |
Oops, something went wrong.