Skip to content

Overloaded call inferred to be through Fn when only FnOnce works #38305

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

Open
causal-agent opened this issue Dec 11, 2016 · 6 comments
Open

Overloaded call inferred to be through Fn when only FnOnce works #38305

causal-agent opened this issue Dec 11, 2016 · 6 comments
Labels
A-closures Area: Closures (`|…| { … }`) C-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@causal-agent
Copy link
Contributor

Repro: https://is.gd/AbO8K4

A wrapper around a closure F implements FnOnce, FnMut and Fn where F does. However, when the wrapper is created with a closure which implements only FnOnce, and then the wrapper is called, the compiler expects the closure to implement FnMut or Fn.

rustc 1.15.0-nightly (daf8c1dfc 2016-12-05)
binary: rustc
commit-hash: daf8c1dfce3b448fc581cc319f64632ec22bd0e1
commit-date: 2016-12-05
host: x86_64-apple-darwin
release: 1.15.0-nightly
LLVM version: 3.9

cc @eddyb (discussed on IRC)

@eddyb eddyb added A-closures Area: Closures (`|…| { … }`) I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 11, 2016
@eddyb
Copy link
Member

eddyb commented Dec 11, 2016

cc @nikomatsakis @nagisa Is this one of the closure inference cases where the current algorithm is suboptimal? AFAICT the wrong trait is inferred at the callsite and it's not changed later, or even if it's changed to FnOnce there might be some obligation left around.

Error for posterity:

error[E0525]: expected a closure that implements the `Fn` trait, but this closure only implements `FnOnce`
  --> <anon>:31:26
   |
31 |     let f = Wrapper { f: || foo };
   |                          ^^^^^^
   |
note: the requirement to implement `Fn` derives from here
  --> <anon>:32:5
   |
32 |     f();
   |     ^^^

@causal-agent
Copy link
Contributor Author

Looks like this also applies to closures only implementing FnMut and the compiler wants it to be Fn: https://is.gd/7U8lK6

@nikomatsakis
Copy link
Contributor

triage: P-medium

@rust-highfive rust-highfive added P-medium Medium priority and removed I-nominated labels Dec 22, 2016
@nikomatsakis
Copy link
Contributor

I'll try to investigate.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@shepmaster
Copy link
Member

Perhaps related to #26186 ?

@Enselic
Copy link
Member

Enselic commented Sep 28, 2023

Triage: Doesn't seem like it, because this still reproduces even though #26186 is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) C-bug Category: This is a bug. P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants