diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-06-27 22:13:06 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-27 22:13:06 +0200 |
| commit | 088f6ab1c5127b5272056c0b27ee1fe06a943a57 (patch) | |
| tree | 694929bc3e645c7cfdbd95240f20ae1d890a6191 /tests/ui/statics | |
| parent | 2d59c4e0fe7c012e59a985f7313ce1c5ec6e0e47 (diff) | |
| parent | d0fa0260ca410b5691a03237e7336bb09c135230 (diff) | |
| download | rust-088f6ab1c5127b5272056c0b27ee1fe06a943a57.tar.gz rust-088f6ab1c5127b5272056c0b27ee1fe06a943a57.zip | |
Rollup merge of #143092 - RalfJung:const-check-lifetime-ext, r=oli-obk
const checks for lifetime-extended temporaries: avoid 'top-level scope' terminology This error recently got changed in https://github.com/rust-lang/rust/pull/140942 to use the terminology of "top-level scope", but after further discussion in https://github.com/rust-lang/reference/pull/1865 it seems the reference will not be using that terminology after all. So let's also remove it from the compiler again, and let's focus on what actually happens with these temporaries: their lifetime is extended until the end of the program. r? ``@oli-obk`` ``@traviscross``
Diffstat (limited to 'tests/ui/statics')
| -rw-r--r-- | tests/ui/statics/check-immutable-mut-slices.rs | 2 | ||||
| -rw-r--r-- | tests/ui/statics/check-immutable-mut-slices.stderr | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/tests/ui/statics/check-immutable-mut-slices.rs b/tests/ui/statics/check-immutable-mut-slices.rs index 9e5ca5059d6..19545a1c925 100644 --- a/tests/ui/statics/check-immutable-mut-slices.rs +++ b/tests/ui/statics/check-immutable-mut-slices.rs @@ -1,6 +1,6 @@ // Checks that immutable static items can't have mutable slices static TEST: &'static mut [isize] = &mut []; -//~^ ERROR mutable borrows of lifetime-extended temporaries +//~^ ERROR mutable borrows of temporaries pub fn main() { } diff --git a/tests/ui/statics/check-immutable-mut-slices.stderr b/tests/ui/statics/check-immutable-mut-slices.stderr index 35521755650..a9486fc9d78 100644 --- a/tests/ui/statics/check-immutable-mut-slices.stderr +++ b/tests/ui/statics/check-immutable-mut-slices.stderr @@ -1,8 +1,12 @@ -error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed +error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed --> $DIR/check-immutable-mut-slices.rs:3:37 | LL | static TEST: &'static mut [isize] = &mut []; - | ^^^^^^^ + | ^^^^^^^ this mutable borrow refers to such a temporary + | + = note: Temporaries in constants and statics can have their lifetime extended until the end of the program + = note: To avoid accidentally creating global mutable state, such temporaries must be immutable + = help: If you really want global mutable state, try replacing the temporary by an interior mutable `static` or a `static mut` error: aborting due to 1 previous error |
