rust/compiler/rustc_middle
León Orell Valerian Liehr 44c7a2dbff
Rollup merge of #125259 - compiler-errors:fn-mut-as-a-treat, r=oli-obk
An async closure may implement `FnMut`/`Fn` if it has no self-borrows

There's no reason that async closures may not implement `FnMut` or `Fn` if they don't actually borrow anything with the closure's env lifetime. Specifically, #123660 made it so that we don't always need to borrow captures from the closure's env.

See the doc comment on `should_reborrow_from_env_of_parent_coroutine_closure`:

c00957a3e2/compiler/rustc_hir_typeck/src/upvar.rs (L1777-L1823)

If there are no such borrows, then we are free to implement `FnMut` and `Fn` as permitted by our closure's inferred `ClosureKind`.

As far as I can tell, this change makes `async || {}` work in precisely the set of places they used to work before #120361.
Fixes #125247.

r? oli-obk
2024-05-22 19:04:45 +02:00
..
src Rollup merge of #125259 - compiler-errors:fn-mut-as-a-treat, r=oli-obk 2024-05-22 19:04:45 +02:00
Cargo.toml Uplift GenericArgKind, CanonicalVarValues, QueryInput 2024-05-18 16:21:43 -04:00
messages.ftl Port DeprecatedMacro to diag structs 2024-05-21 20:16:39 +00:00
README.md

For more information about how rustc works, see the rustc dev guide.