-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't deduce a signature that makes a closure cyclic #105409
Conversation
This also doesn't fix #97680, but it makes it possible to compile with the standard "closure wasn't smart enough at inferring higher-ranked lifetime" trick: use std::future::Future;
fn hrc<
R,
F: for<'a> AsyncClosure<'a, (), R>
+ for<'a> Fn(&'a ()) -> <F as AsyncClosure<'a, (), R>>::Fut,
>(
f: F,
) -> F {
f
}
fn main() {
- hrc(|x| async { });
+ hrc(|x: &_| async { });
}
trait AsyncClosure<'a, I, R>: Fn(&'a I) -> Self::Fut
where
I: 'a,
{
type Fut: Future<Output = R> + Send + 'a;
}
impl<'a, I, R, Fut, F> AsyncClosure<'a, I, R> for F
where
I: 'a,
F: Fn(&'a I) -> Fut,
Fut: Future<Output = R> + Send + 'a,
{
type Fut = Fut;
} Without this PR, no amount of fiddling with the closure makes this compile as far as I can tell. |
r? types |
☔ The latest upstream changes (presumably #104986) made this pull request unmergeable. Please resolve the merge conflicts. |
c4dc122
to
8068c6a
Compare
☔ The latest upstream changes (presumably #105657) made this pull request unmergeable. Please resolve the merge conflicts. |
8068c6a
to
fa2f31b
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (03b9e1d): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. |
Sometimes when elaborating supertrait bounds for closure signature inference, we end up deducing a closure signature that is cyclical because either a parameter or the return type references a projection mentioning
Self
that also has escaping bound vars, which means that it's not eagerly replaced with an inference variable.Interestingly, this is not just related to my PR that elaborates supertrait bounds for closure signature deduction. The committed test
supertrait-hint-cycle-3.rs
shows stable code that is fixed by this PR:Fixes #105401
Fixes #105396
r? types