Skip to content

Commit 7dab981

Browse files
committed
extended info for E0595 closure cannot mutate immutable local variable
1 parent 5605d58 commit 7dab981

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

Diff for: src/librustc_borrowck/diagnostics.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,24 @@ fn main() {
11321132
```
11331133
"##,
11341134

1135+
E0595: r##"
1136+
Closures cannot mutate immutable captured variables.
1137+
1138+
Erroneous code example:
1139+
1140+
```compile_fail,E0595
1141+
let x = 3; // error: closure cannot assign to immutable local variable `x`
1142+
let mut c = || { x += 1 };
1143+
```
1144+
1145+
Make the variable binding mutable:
1146+
1147+
```
1148+
let mut x = 3; // ok!
1149+
let mut c = || { x += 1 };
1150+
```
1151+
"##,
1152+
11351153
E0596: r##"
11361154
This error occurs because you tried to mutably borrow a non-mutable variable.
11371155
@@ -1189,6 +1207,5 @@ register_diagnostics! {
11891207
// E0385, // {} in an aliasable location
11901208
E0524, // two closures require unique access to `..` at the same time
11911209
E0594, // cannot assign to {}
1192-
E0595, // closure cannot assign to {}
11931210
E0598, // lifetime of {} is too short to guarantee its contents can be...
11941211
}

0 commit comments

Comments
 (0)