Skip to content

Commit 574fbbf

Browse files
Add E0388 error explanation
1 parent 9d8d47d commit 574fbbf

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/librustc_borrowck/diagnostics.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,30 @@ You can read more about cell types in the API documentation:
286286
https://doc.rust-lang.org/std/cell/
287287
"##,
288288

289+
E0388: r##"
290+
A mutable borrow was attempted in a static location.
291+
292+
Erroneous code example:
293+
294+
```compile_fail,E0388
295+
static X: i32 = 1;
296+
297+
static STATIC_REF: &'static mut i32 = &mut X;
298+
// error: cannot borrow data mutably in a static location
299+
300+
const CONST_REF: &'static mut i32 = &mut X;
301+
// error: cannot borrow data mutably in a static location
302+
```
303+
304+
To fix this error, you have to use constant borrow:
305+
306+
```
307+
static X: i32 = 1;
308+
309+
static STATIC_REF: &'static i32 = &X;
310+
```
311+
"##,
312+
289313
E0389: r##"
290314
An attempt was made to mutate data using a non-mutable reference. This
291315
commonly occurs when attempting to assign to a non-mutable reference of a
@@ -1113,6 +1137,5 @@ fn main() {
11131137

11141138
register_diagnostics! {
11151139
E0385, // {} in an aliasable location
1116-
E0388, // {} in a static location
11171140
E0524, // two closures require unique access to `..` at the same time
11181141
}

0 commit comments

Comments
 (0)