Skip to content

Closure type expectations do not guide type inference? #15

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
compiler-errors opened this issue Mar 29, 2023 · 0 comments · Fixed by rust-lang/rust#109739
Closed

Closure type expectations do not guide type inference? #15

compiler-errors opened this issue Mar 29, 2023 · 0 comments · Fixed by rust-lang/rust#109739
Labels
has-fix A fix is up

Comments

@compiler-errors
Copy link
Owner

compiler-errors commented Mar 29, 2023

fn foo(i: isize) -> isize { i + 1 }

fn apply<A, F>(f: F, v: A) -> A where F: FnOnce(A) -> A { f(v) }

pub fn main() {
    let f = |i| foo(i);
    assert_eq!(apply(f, 2), 3);
}

apply(f, 2) is not constraining the type of 2 or 3 to be isize, which causes the obligations registered by apply to fail after fallback!

@compiler-errors compiler-errors added the needs-further-investigation Needs to be root-caused label Mar 29, 2023
@compiler-errors compiler-errors added needs-fix An easy fix needs to be put up and applied has-fix A fix is up and removed needs-further-investigation Needs to be root-caused needs-fix An easy fix needs to be put up and applied labels Mar 29, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Mar 30, 2023
…-fnonce, r=lcnr

Closures always implement `FnOnce` in new solver

We should process `[closure]: FnOnce(Tys...) -> Ty` obligations *before* fallback and closure analysis. We can do this by taking advantage of the fact that `FnOnce` is always implemented by closures, even before we definitely know the closure kind.

Fixes compiler-errors/next-solver-hir-issues#15

r? `@oli-obk` (trying to spread the reviewer load for new trait solver prs, and this one is pretty self-contained, though feel free to reassign 😸)
compiler-errors added a commit to compiler-errors/rust that referenced this issue Mar 30, 2023
…-fnonce, r=lcnr

Closures always implement `FnOnce` in new solver

We should process `[closure]: FnOnce(Tys...) -> Ty` obligations *before* fallback and closure analysis. We can do this by taking advantage of the fact that `FnOnce` is always implemented by closures, even before we definitely know the closure kind.

Fixes compiler-errors/next-solver-hir-issues#15

r? ``@oli-obk`` (trying to spread the reviewer load for new trait solver prs, and this one is pretty self-contained, though feel free to reassign 😸)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
has-fix A fix is up
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant