about summary refs log tree commit diff
path: root/tests/ui/array-slice-vec/array_const_index-0.rs
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-02-10 13:12:28 +0100
committerGitHub <noreply@github.com>2024-02-10 13:12:28 +0100
commit0b7f0ff230b125032d1ac29a9d34195bc5d8d42a (patch)
tree8642721e601f1aded01a2f4a0d580e51a57a1510 /tests/ui/array-slice-vec/array_const_index-0.rs
parent232919c33a5ba8ce8b4171b03cc898c77da136cc (diff)
parent9a819ab8f7f69b5461d0a9a7f8b57f976de1ae2e (diff)
downloadrust-0b7f0ff230b125032d1ac29a9d34195bc5d8d42a.tar.gz
rust-0b7f0ff230b125032d1ac29a9d34195bc5d8d42a.zip
Rollup merge of #117614 - RalfJung:static-mut-refs, r=davidtwco,oli-obk
static mut: allow mutable reference to arbitrary types, not just slices and arrays

For historical reasons, we allow this:
```rust
static mut ARRAY: &'static mut [isize] = &mut [1];
```
However, we do not allow this:
```rust
static mut INT: &'static mut isize = &mut 1;
```

I think that's terribly inconsistent. I don't care much for `static mut`, but we have to keep it around for backwards compatibility and so we have to keep supporting it properly in the compiler. In recent refactors of how we deal with mutability of data in `static` and `const`, I almost made a fatal mistake since I tested `static mut INT: &'static mut isize = &mut 1` and concluded that we don't allow such `'static` mutable references even inside `static mut`. After all, nobody would expect this to be allowed only for arrays and slices, right?!?? So for the sake of our own sanity, and of whoever else reverse engineers these rules in the future to understand what the Rust compiler accepts or does not accept, I propose that we accept this for all types, not just arrays and slices.
Diffstat (limited to 'tests/ui/array-slice-vec/array_const_index-0.rs')
0 files changed, 0 insertions, 0 deletions