diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-02-10 13:12:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-10 13:12:28 +0100 |
| commit | 0b7f0ff230b125032d1ac29a9d34195bc5d8d42a (patch) | |
| tree | 8642721e601f1aded01a2f4a0d580e51a57a1510 /tests/ui/array-slice-vec | |
| parent | 232919c33a5ba8ce8b4171b03cc898c77da136cc (diff) | |
| parent | 9a819ab8f7f69b5461d0a9a7f8b57f976de1ae2e (diff) | |
| download | rust-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')
| -rw-r--r-- | tests/ui/array-slice-vec/check-static-mut-slices.rs | 15 |
1 files changed, 0 insertions, 15 deletions
diff --git a/tests/ui/array-slice-vec/check-static-mut-slices.rs b/tests/ui/array-slice-vec/check-static-mut-slices.rs deleted file mode 100644 index b89c634036e..00000000000 --- a/tests/ui/array-slice-vec/check-static-mut-slices.rs +++ /dev/null @@ -1,15 +0,0 @@ -// run-pass -#![allow(dead_code)] - -// Checks that mutable static items can have mutable slices - - -static mut TEST: &'static mut [isize] = &mut [1]; -static mut EMPTY: &'static mut [isize] = &mut []; - -pub fn main() { - unsafe { - TEST[0] += 1; - assert_eq!(TEST[0], 2); - } -} |
