Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extended information for E0594 #60193

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion src/librustc_mir/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,36 @@ fn get_owned_iterator() -> IntoIter<i32> {
```
"##,

E0594: r##"
Cannot assign to immutable static item.

Example of erroneous code:

```compile_fail,E0594
static NUM: i32 = 18;
NUM = 20; // error: cannot assign
```

Statics are shared everywhere, and if they are mutable one might violate memory
safety since holding multiple mutable references to shared data is not allowed.

If you really want global mutable state, try using `static mut`. You will also
need to wrap the assignment in an `unsafe` block, see E0133.

```
static mut NUM: i32 = 18;
unsafe {
NUM = 20;
}
```

See also:

https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html
https://doc.rust-lang.org/stable/reference/items/static-items.html
https://doc.rust-lang.org/stable/rust-by-example/custom_types/constants.html
"##,

E0595: r##"
#### Note: this error code is no longer emitted by the compiler.

Expand Down Expand Up @@ -2435,7 +2465,6 @@ register_diagnostics! {
E0521, // borrowed data escapes outside of closure
E0524, // two closures require unique access to `..` at the same time
E0526, // shuffle indices are not constant
E0594, // cannot assign to {}
E0598, // lifetime of {} is too short to guarantee its contents can be...
E0625, // thread-local statics cannot be accessed at compile-time
}
1 change: 1 addition & 0 deletions src/test/ui/E0594.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | NUM = 20;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/borrowck/borrow-immutable-upvar-mutation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,5 @@ LL | let _h = to_fn_mut(move || { set(&mut z); to_fn(move || z = 42); })

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ LL | *s.pointer += 1;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/borrowck/borrowck-assign-to-constants.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | foo = 6;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ LL | let x: &mut isize = &mut **t0;

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0502, E0596.
Some errors have detailed explanations: E0502, E0594, E0596.
For more information about an error, try `rustc --explain E0502`.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ LL | *x.y_mut() = 3;

error: aborting due to 14 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/borrowck/borrowck-borrow-overloaded-deref.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ LL | **x = 3;

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/borrowck/borrowck-closures-unique.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ LL | let c1 = |y: &'static mut isize| x = y;

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0500`.
Some errors have detailed explanations: E0500, E0594.
For more information about an error, try `rustc --explain E0500`.
3 changes: 2 additions & 1 deletion src/test/ui/borrowck/borrowck-issue-14498.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,5 @@ LL | drop(p);

error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0506`.
Some errors have detailed explanations: E0506, E0594.
For more information about an error, try `rustc --explain E0506`.
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ LL | s[2] = 20;

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0502`.
Some errors have detailed explanations: E0502, E0594.
For more information about an error, try `rustc --explain E0502`.
3 changes: 2 additions & 1 deletion src/test/ui/borrowck/index-mut-help.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ LL | let _ = &mut map["peter"];

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/borrowck/issue-45983.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | give_any(|y| x = Some(y));

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,5 @@ LL | v.y = 2;

error: aborting due to 9 previous errors

For more information about this error, try `rustc --explain E0382`.
Some errors have detailed explanations: E0382, E0594.
For more information about an error, try `rustc --explain E0382`.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ LL | || { &mut x.0; };

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ LL | || { &mut x.0; };

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/borrowck/mutability-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,5 @@ LL | &mut X.0;

error: aborting due to 38 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ LL | x.b = 22;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0381`.
Some errors have detailed explanations: E0381, E0594.
For more information about an error, try `rustc --explain E0381`.
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ LL | x.0 = 1;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0381`.
Some errors have detailed explanations: E0381, E0594.
For more information about an error, try `rustc --explain E0381`.
3 changes: 2 additions & 1 deletion src/test/ui/cannot-mutate-captured-non-mut-var.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ LL | to_fn_once(move|| { s.read_to_end(&mut Vec::new()); });

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | foo(Box::new(move || y = false) as Box<_>);

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/did_you_mean/issue-35937.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ LL | s.x += 1;

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/did_you_mean/issue-39544.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,5 @@ LL | *x.0 = 1;

error: aborting due to 12 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/error-codes/E0389.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | fancy_ref.num = 6;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/fn/fn-closure-mutable-capture.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ LL | bar(move || x = 1);

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/immut-function-arguments.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ LL | let _frob = |q: Box<isize>| { *q = 2; };

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-46023.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ LL | x = 1;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/issues/issue-46604.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ LL | buf[0]=2;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0017`.
Some errors have detailed explanations: E0017, E0594.
For more information about an error, try `rustc --explain E0017`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-51244.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | *my_ref = 0;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-51515.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | *bar = 64;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/mut/mutable-class-fields-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | self.how_hungry -= 5;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/mut/mutable-class-fields.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | nyan.how_hungry = 0;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/nll/closure-captures.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,5 @@ LL | | *x = 1;});

error: aborting due to 12 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/nll/constant-thread-locals-issue-47053.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | FOO = 6;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/nll/generator-upvar-mutability.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ LL | x = 1;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/nll/issue-47388.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | fancy_ref.num = 6;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/nll/issue-51244.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ LL | *my_ref = 0;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
3 changes: 2 additions & 1 deletion src/test/ui/nll/issue-57989.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ LL | g;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0506`.
Some errors have detailed explanations: E0506, E0594.
For more information about an error, try `rustc --explain E0506`.
1 change: 1 addition & 0 deletions src/test/ui/rfc-2005-default-binding-mode/enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | *x += 1;

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | *n += 1;

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/suggestions/suggest-ref-mut.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ LL | ref quo => { *quo = 32; },

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0594`.
1 change: 1 addition & 0 deletions src/test/ui/thread-local-mutation.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ LL | S = "after";

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ LL | || set(&mut x);

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0596`.
Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ LL | | });

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0594`.
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ LL | | });

error: aborting due to previous error

For more information about this error, try `rustc --explain E0594`.