Skip to content

Unable to infer the type of a ~fn inside an Option #9409

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

Closed
MicahChalmer opened this issue Sep 22, 2013 · 1 comment
Closed

Unable to infer the type of a ~fn inside an Option #9409

MicahChalmer opened this issue Sep 22, 2013 · 1 comment

Comments

@MicahChalmer
Copy link
Contributor

There seems to be no way to use a ~fn inside an Option without rewriting the type every time you use it. This line:

let _:Option<~fn()> = Some(|| { });

gives this error message:

error: mismatched types: expected `std::option::Option<~fn:Send()>` but found `std::option::Option<&fn<no-bounds>()>` (expected ~ closure, found & closure)

The problem is that the function inside the Some is interpreted to be a &fn rather than a ~fn, and then the compiler complains about a type mismatch. The only way to make it work is this to make it Some::<~fn()>(|| { }) instead. But when the function isn't just ~fn() and has parameters and a return type, that becomes extremely annoying.

@MicahChalmer
Copy link
Contributor Author

This does not appear to be an issue anymore, ever since the change to proc instead of fn. The syntax is different than a &fn, so the compiler can no longer get confused. The equivalent code after the change: let _:Option<proc()> = Some(proc() {}) compiles just fine. Closing this.

djkoloski pushed a commit to djkoloski/rust that referenced this issue Sep 21, 2022
…dnet

Add `iter_kv_map` lint

fixes rust-lang#9376

| before | after |
| -------------- | ------------------------- |
| `hmap.iter().map(\|(key, _)\| key)` | `hmap.keys()` |
| `hmap.iter().map(\|(_, v)\| v + 2)` | `hmap.values().map(\|v\| v + 2)` |
| `hmap.into_iter().map(\|(key, _)\| key)` | `hmap.into_keys()` |

Is `MachineApplicable`

changelog: [`iter_kv_map`]: added lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant