rust/compiler/rustc_errors/src
Stuart Cook 907076c3dd
Rollup merge of #144558 - estebank:issue-68119, r=lcnr
Point at the `Fn()` or `FnMut()` bound that coerced a closure, which caused a move error

When encountering a move error involving a closure because the captured value isn't `Copy`, and the obligation comes from a bound on a type parameter that requires `Fn` or `FnMut`, we point at it and explain that an `FnOnce` wouldn't cause the move error.

```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
  --> f111.rs:15:25
   |
14 | fn do_stuff(foo: Option<Foo>) {
   |             ---  ----------- move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
   |             |
   |             captured outer variable
15 |     require_fn_trait(|| async {
   |                      -- ^^^^^ `foo` is moved here
   |                      |
   |                      captured by this `Fn` closure
16 |         if foo.map_or(false, |f| f.foo()) {
   |            --- variable moved due to use in coroutine
   |
help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once
  --> f111.rs:12:53
   |
12 | fn require_fn_trait<F: Future<Output = ()>>(_: impl Fn() -> F) {}
   |                                                     ^^^^^^^^^
help: consider cloning the value if the performance cost is acceptable
   |
16 |         if foo.clone().map_or(false, |f| f.foo()) {
   |               ++++++++
```

Fix rust-lang/rust#68119, by pointing at `Fn` and `FnMut` bounds involved in move errors.
2025-08-11 12:21:08 +10:00
..
json Extract Translator struct 2025-06-19 13:02:04 -05:00
markdown Use LocalKey<Cell> methods more 2025-07-24 13:21:25 -05:00
annotate_snippet_emitter_writer.rs Extract Translator struct 2025-06-19 13:02:04 -05:00
codes.rs Stop using String for error codes. 2024-01-29 07:41:41 +11:00
diagnostic.rs Point at the Fn() or FnMut() bound that coerced a closure, which caused a move error 2025-08-10 19:22:49 +00:00
diagnostic_impls.rs remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
emitter.rs Rollup merge of #145152 - xizheyin:detect-confusion-type, r=lqd 2025-08-10 15:43:55 -04:00
error.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
json.rs refactor: Make -Ztrack-diagnostics emit like a note 2025-07-03 07:19:25 -06:00
lib.rs Extend is_case_difference to handle digit-letter confusables 2025-07-31 13:55:59 +08:00
lock.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
registry.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
snippet.rs Use abs_diff where applicable 2025-03-27 18:29:06 +00:00
styled_buffer.rs use let chains in ast, borrowck, codegen, const_eval 2025-07-28 06:08:48 +05:00
tests.rs Extract Translator struct 2025-06-19 13:02:04 -05:00
timings.rs Add codegen timing section 2025-06-23 08:50:17 +02:00
translation.rs Extract Translator struct 2025-06-19 13:02:04 -05:00