about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/messages.ftl
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-27 22:13:06 +0200
committerGitHub <noreply@github.com>2025-06-27 22:13:06 +0200
commit088f6ab1c5127b5272056c0b27ee1fe06a943a57 (patch)
tree694929bc3e645c7cfdbd95240f20ae1d890a6191 /compiler/rustc_const_eval/messages.ftl
parent2d59c4e0fe7c012e59a985f7313ce1c5ec6e0e47 (diff)
parentd0fa0260ca410b5691a03237e7336bb09c135230 (diff)
downloadrust-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 'compiler/rustc_const_eval/messages.ftl')
-rw-r--r--compiler/rustc_const_eval/messages.ftl28
1 files changed, 10 insertions, 18 deletions
diff --git a/compiler/rustc_const_eval/messages.ftl b/compiler/rustc_const_eval/messages.ftl
index 671ae5975a7..2a2c3e6aee2 100644
--- a/compiler/rustc_const_eval/messages.ftl
+++ b/compiler/rustc_const_eval/messages.ftl
@@ -125,16 +125,11 @@ const_eval_incompatible_types =
     calling a function with argument of type {$callee_ty} passing data of type {$caller_ty}
 
 const_eval_interior_mutable_borrow_escaping =
-    interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed
-    .label = this borrow of an interior mutable value refers to a lifetime-extended temporary
-    .help = to fix this, the value can be extracted to a separate `static` item and then referenced
-    .teach_note =
-        This creates a raw pointer to a temporary that has its lifetime extended to last for the entire program.
-        Lifetime-extended temporaries in constants and statics must be immutable.
-        This is to avoid accidentally creating shared mutable state.
-
-
-        If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
+    interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
+    .label = this borrow of an interior mutable value refers to such a temporary
+    .note = Temporaries in constants and statics can have their lifetime extended until the end of the program
+    .note2 = 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`
 
 const_eval_intern_kind = {$kind ->
     [static] static
@@ -215,14 +210,11 @@ const_eval_modified_global =
     modifying a static's initial value from another static's initializer
 
 const_eval_mutable_borrow_escaping =
-    mutable borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed
-    .teach_note =
-        This creates a reference to a temporary that has its lifetime extended to last for the entire program.
-        Lifetime-extended temporaries in constants and statics must be immutable.
-        This is to avoid accidentally creating shared mutable state.
-
-
-        If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
+    mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
+    .label = 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
+    .note2 = 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`
 
 const_eval_mutable_ptr_in_final = encountered mutable pointer in final value of {const_eval_intern_kind}