Skip to content
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

The value no longer satisfies the constraint after passing through identity, which seems counterintuitive #124481

Open
A4-Tacks opened this issue Apr 28, 2024 · 1 comment
Labels
A-typesystem Area: The type system C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@A4-Tacks
Copy link

use std::convert::identity;

fn foo<F: for<'a> FnOnce(&'a ()) -> &'a ()>(f: F) {
    f(&());
}

fn main() {
    //foo(identity(|x| x));
    foo(|x| x);
}

I'm not sure if this is a generic or something issue

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 28, 2024
@LunarLambda
Copy link

My guess is that passing the closure as-is causes it to coerce to a fn-pointer which fulfills the HRTB, but passing it through identity causes it to be passed as whatever anonymous closure struct type it is, which the compiler cannot prove fulfills the HRTB since it's not part of the signature (in other words, identity() could feasibly return a different value of the same type, so the compiler is conservative and the inferred type doesn't fulfill the HRTB)

@jieyouxu jieyouxu added A-typesystem Area: The type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-discussion Category: Discussion or questions that doesn't represent real issues. T-types Relevant to the types team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants