]> git.lizzy.rs Git - rust.git/commit
Auto merge of #21805 - nikomatsakis:closure-inference-refactor-1, r=eddyb
authorbors <bors@rust-lang.org>
Sun, 1 Feb 2015 13:01:57 +0000 (13:01 +0000)
committerbors <bors@rust-lang.org>
Sun, 1 Feb 2015 13:01:57 +0000 (13:01 +0000)
commit0ab8d5dadd72b8d44cc79a1756c0a00fec619efa
tree5ac2cc900562623bec214091e1f4c82682d5a4c5
parentf1f9cb705df95171fce4e575374c959509e58dea
parent870aea216bb6f6d6a238c03e186a01bff8820ac0
Auto merge of #21805 - nikomatsakis:closure-inference-refactor-1, r=eddyb

Currently, we only infer the kind of a closure based on the expected type or explicit annotation. If neither applies, we currently report an error. This pull request changes that case to defer the decision until we are able to analyze the actions of the closure: closures which mutate their environment require `FnMut`, closures which move out of their environment require `FnOnce`.

This PR is not the end of the story:

- It does not remove the explicit annotations nor disregard them. The latter is the logical next step to removing them (we'll need a snapshot before we can do anything anyhow). Disregarding explicit annotations might expose more bugs since right now all closures in libstd/rustc use explicit annotations or the expected type, so this inference never kicks in.
- The interaction with instantiating type parameter fallbacks leaves something to be desired. This is mostly just saying that the algorithm from https://github.com/rust-lang/rfcs/pull/213 needs to be implemented, which is a separate bug. There are some semi-subtle interactions though because not knowing whether a closure is `Fn` vs `FnMut` prevents us from resolving obligations like `F : FnMut(...)`, which can in turn prevent unification of some type parameters, which might (in turn) lead to undesired fallback. We can improve this situation however -- even if we don't know whether (or just how) `F : FnMut(..)` holds or not for some closure type `F`, we can still perform unification since we *do* know the argument and return types. Once kind inference is done, we can complete the `F : FnMut(..)` analysis -- which might yield an error if (e.g.) the `F` moves out of its environment.

r? @nick29581