Skip to content

Commit 7500bcf

Browse files
authored
Rollup merge of #70690 - GuillaumeGomez:cleanup-e0501, r=Dylan-DPC
Clean up E0501 explanation r? @Dylan-DPC
2 parents 5768385 + 84c97ee commit 7500bcf

File tree

1 file changed

+11
-9
lines changed
  • src/librustc_error_codes/error_codes

1 file changed

+11
-9
lines changed

src/librustc_error_codes/error_codes/E0501.md

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
This error indicates that a mutable variable is being used while it is still
2-
captured by a closure. Because the closure has borrowed the variable, it is not
3-
available for use until the closure goes out of scope.
4-
5-
Note that a capture will either move or borrow a variable, but in this
6-
situation, the closure is borrowing the variable. Take a look at the chapter
7-
on [Capturing][capturing] in Rust By Example for more information.
8-
9-
[capturing]: https://doc.rust-lang.org/stable/rust-by-example/fn/closures/capture.html
1+
A mutable variable is used but it is already captured by a closure.
102

113
Erroneous code example:
124

@@ -29,6 +21,16 @@ fn foo(a: &mut i32) {
2921
}
3022
```
3123

24+
This error indicates that a mutable variable is used while it is still captured
25+
by a closure. Because the closure has borrowed the variable, it is not available
26+
until the closure goes out of scope.
27+
28+
Note that a capture will either move or borrow a variable, but in this
29+
situation, the closure is borrowing the variable. Take a look at the chapter
30+
on [Capturing][capturing] in Rust By Example for more information.
31+
32+
[capturing]: https://doc.rust-lang.org/stable/rust-by-example/fn/closures/capture.html
33+
3234
To fix this error, you can finish using the closure before using the captured
3335
variable:
3436

0 commit comments

Comments
 (0)