Skip to content

Commit 2de51b4

Browse files
committed
const checks: avoid 'top-level scope' terminology
1 parent e61dd43 commit 2de51b4

28 files changed

+56
-60
lines changed

compiler/rustc_const_eval/messages.ftl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,13 @@ const_eval_incompatible_types =
125125
calling a function with argument of type {$callee_ty} passing data of type {$caller_ty}
126126
127127
const_eval_interior_mutable_borrow_escaping =
128-
interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed
128+
interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
129129
.label = this borrow of an interior mutable value refers to a lifetime-extended temporary
130130
.help = to fix this, the value can be extracted to a separate `static` item and then referenced
131131
.teach_note =
132-
This creates a raw pointer to a temporary that has its lifetime extended to last for the entire program.
133-
Lifetime-extended temporaries in constants and statics must be immutable.
134-
This is to avoid accidentally creating shared mutable state.
135-
136-
132+
Temporaries in constants and statics can have their lifetime extended until the end of the program.
133+
(See <https://doc.rust-lang.org/reference/destructors.html#r-destructors.scope.lifetime-extension.static>.)
134+
To avoid accidentally creating global mutable state, such temporaries must be immutable.
137135
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
138136
139137
const_eval_intern_kind = {$kind ->
@@ -215,13 +213,11 @@ const_eval_modified_global =
215213
modifying a static's initial value from another static's initializer
216214
217215
const_eval_mutable_borrow_escaping =
218-
mutable borrows of lifetime-extended temporaries in the top-level scope of a {const_eval_const_context} are not allowed
216+
mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
219217
.teach_note =
220-
This creates a reference to a temporary that has its lifetime extended to last for the entire program.
221-
Lifetime-extended temporaries in constants and statics must be immutable.
222-
This is to avoid accidentally creating shared mutable state.
223-
224-
218+
Temporaries in constants and statics can have their lifetime extended until the end of the program.
219+
(See <https://doc.rust-lang.org/reference/destructors.html#r-destructors.scope.lifetime-extension.static>.)
220+
To avoid accidentally creating global mutable state, such temporaries must be immutable.
225221
If you really want global mutable state, try using an interior mutable `static` or a `static mut`.
226222
227223
const_eval_mutable_ptr_in_final = encountered mutable pointer in final value of {const_eval_intern_kind}

tests/ui/consts/const-mut-refs/issue-76510.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::mem::{transmute, ManuallyDrop};
22

33
const S: &'static mut str = &mut " hello ";
4-
//~^ ERROR: mutable borrows of lifetime-extended temporaries
4+
//~^ ERROR: mutable borrows of temporaries
55

66
const fn trigger() -> [(); unsafe {
77
let s = transmute::<(*const u8, usize), &ManuallyDrop<str>>((S.as_ptr(), 3));

tests/ui/consts/const-mut-refs/issue-76510.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/issue-76510.rs:3:29
33
|
44
LL | const S: &'static mut str = &mut " hello ";

tests/ui/consts/const-mut-refs/mut_ref_in_final.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ const A: *const i32 = &4;
1212
// It could be made sound to allow it to compile,
1313
// but we do not want to allow this to compile,
1414
// as that would be an enormous footgun in oli-obk's opinion.
15-
const B: *mut i32 = &mut 4; //~ ERROR mutable borrows of lifetime-extended temporaries
15+
const B: *mut i32 = &mut 4; //~ ERROR mutable borrows of temporaries
1616

1717
// Ok, no actual mutable allocation exists
1818
const B2: Option<&mut i32> = None;
1919

2020
// Not ok, can't prove that no mutable allocation ends up in final value
21-
const B3: Option<&mut i32> = Some(&mut 42); //~ ERROR mutable borrows of lifetime-extended temporaries
21+
const B3: Option<&mut i32> = Some(&mut 42); //~ ERROR mutable borrows of temporaries
2222

2323
const fn helper(x: &mut i32) -> Option<&mut i32> { Some(x) }
2424
const B4: Option<&mut i32> = helper(&mut 42); //~ ERROR temporary value dropped while borrowed
@@ -69,13 +69,13 @@ unsafe impl<T> Sync for SyncPtr<T> {}
6969
// (This relies on `SyncPtr` being a curly brace struct.)
7070
// However, we intern the inner memory as read-only, so this must be rejected.
7171
static RAW_MUT_CAST_S: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
72-
//~^ ERROR mutable borrows of lifetime-extended temporaries
72+
//~^ ERROR mutable borrows of temporaries
7373
static RAW_MUT_COERCE_S: SyncPtr<i32> = SyncPtr { x: &mut 0 };
74-
//~^ ERROR mutable borrows of lifetime-extended temporaries
74+
//~^ ERROR mutable borrows of temporaries
7575
const RAW_MUT_CAST_C: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
76-
//~^ ERROR mutable borrows of lifetime-extended temporaries
76+
//~^ ERROR mutable borrows of temporaries
7777
const RAW_MUT_COERCE_C: SyncPtr<i32> = SyncPtr { x: &mut 0 };
78-
//~^ ERROR mutable borrows of lifetime-extended temporaries
78+
//~^ ERROR mutable borrows of temporaries
7979

8080
fn main() {
8181
println!("{}", unsafe { *A });

tests/ui/consts/const-mut-refs/mut_ref_in_final.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/mut_ref_in_final.rs:15:21
33
|
44
LL | const B: *mut i32 = &mut 4;
55
| ^^^^^^
66

7-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
7+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
88
--> $DIR/mut_ref_in_final.rs:21:35
99
|
1010
LL | const B3: Option<&mut i32> = Some(&mut 42);
@@ -72,25 +72,25 @@ LL | static mut FOO3: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
7272
| | creates a temporary value which is freed while still in use
7373
| using this value as a static requires that borrow lasts for `'static`
7474

75-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed
75+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
7676
--> $DIR/mut_ref_in_final.rs:71:53
7777
|
7878
LL | static RAW_MUT_CAST_S: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
7979
| ^^^^^^^
8080

81-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed
81+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
8282
--> $DIR/mut_ref_in_final.rs:73:54
8383
|
8484
LL | static RAW_MUT_COERCE_S: SyncPtr<i32> = SyncPtr { x: &mut 0 };
8585
| ^^^^^^
8686

87-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
87+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
8888
--> $DIR/mut_ref_in_final.rs:75:52
8989
|
9090
LL | const RAW_MUT_CAST_C: SyncPtr<i32> = SyncPtr { x : &mut 42 as *mut _ as *const _ };
9191
| ^^^^^^^
9292

93-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
93+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
9494
--> $DIR/mut_ref_in_final.rs:77:53
9595
|
9696
LL | const RAW_MUT_COERCE_C: SyncPtr<i32> = SyncPtr { x: &mut 0 };

tests/ui/consts/const-promoted-opaque.atomic.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL |
77
LL | };
88
| - value is dropped here
99

10-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
10+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
1111
--> $DIR/const-promoted-opaque.rs:36:19
1212
|
1313
LL | const BAZ: &Foo = &FOO;

tests/ui/consts/const-promoted-opaque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const BAR: () = {
3434
};
3535

3636
const BAZ: &Foo = &FOO;
37-
//[atomic]~^ ERROR: interior mutable shared borrows of lifetime-extended temporaries
37+
//[atomic]~^ ERROR: interior mutable shared borrows of temporaries
3838

3939
fn main() {
4040
let _: &'static _ = &FOO;

tests/ui/consts/issue-17718-const-bad-values.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#![allow(static_mut_refs)]
66

77
const C1: &'static mut [usize] = &mut [];
8-
//~^ ERROR: mutable borrows of lifetime-extended temporaries
8+
//~^ ERROR: mutable borrows of temporaries
99

1010
static mut S: i32 = 3;
1111
const C2: &'static mut i32 = unsafe { &mut S };

tests/ui/consts/issue-17718-const-bad-values.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/issue-17718-const-bad-values.rs:7:34
33
|
44
LL | const C1: &'static mut [usize] = &mut [];

tests/ui/consts/issue-17718-const-borrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use std::cell::UnsafeCell;
22

33
const A: UnsafeCell<usize> = UnsafeCell::new(1);
44
const B: &'static UnsafeCell<usize> = &A;
5-
//~^ ERROR: interior mutable shared borrows of lifetime-extended temporaries
5+
//~^ ERROR: interior mutable shared borrows of temporaries
66

77
struct C { a: UnsafeCell<usize> }
88
const D: C = C { a: UnsafeCell::new(1) };
99
const E: &'static UnsafeCell<usize> = &D.a;
10-
//~^ ERROR: interior mutable shared borrows of lifetime-extended temporaries
10+
//~^ ERROR: interior mutable shared borrows of temporaries
1111
const F: &'static C = &D;
12-
//~^ ERROR: interior mutable shared borrows of lifetime-extended temporaries
12+
//~^ ERROR: interior mutable shared borrows of temporaries
1313

1414
fn main() {}

tests/ui/consts/issue-17718-const-borrow.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/issue-17718-const-borrow.rs:4:39
33
|
44
LL | const B: &'static UnsafeCell<usize> = &A;
55
| ^^ this borrow of an interior mutable value refers to a lifetime-extended temporary
66

7-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
7+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
88
--> $DIR/issue-17718-const-borrow.rs:9:39
99
|
1010
LL | const E: &'static UnsafeCell<usize> = &D.a;
1111
| ^^^^ this borrow of an interior mutable value refers to a lifetime-extended temporary
1212

13-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
13+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
1414
--> $DIR/issue-17718-const-borrow.rs:11:23
1515
|
1616
LL | const F: &'static C = &D;

tests/ui/consts/partial_qualif.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cell::Cell;
33
const FOO: &(Cell<usize>, bool) = {
44
let mut a = (Cell::new(0), false);
55
a.1 = true; // sets `qualif(a)` to `qualif(a) | qualif(true)`
6-
&{a} //~ ERROR interior mutable shared borrows of lifetime-extended temporaries
6+
&{a} //~ ERROR interior mutable shared borrows of temporaries
77
};
88

99
fn main() {}

tests/ui/consts/partial_qualif.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/partial_qualif.rs:6:5
33
|
44
LL | &{a}

tests/ui/consts/qualif_overwrite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::cell::Cell;
77
const FOO: &Option<Cell<usize>> = {
88
let mut a = Some(Cell::new(0));
99
a = None; // sets `qualif(a)` to `qualif(a) | qualif(None)`
10-
&{a} //~ ERROR interior mutable shared borrows of lifetime-extended temporaries
10+
&{a} //~ ERROR interior mutable shared borrows of temporaries
1111
};
1212

1313
fn main() {}

tests/ui/consts/qualif_overwrite.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/qualif_overwrite.rs:10:5
33
|
44
LL | &{a}

tests/ui/consts/qualif_overwrite_2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::cell::Cell;
55
const FOO: &Option<Cell<usize>> = {
66
let mut a = (Some(Cell::new(0)),);
77
a.0 = None; // sets `qualif(a)` to `qualif(a) | qualif(None)`
8-
&{a.0} //~ ERROR interior mutable shared borrows of lifetime-extended temporaries
8+
&{a.0} //~ ERROR interior mutable shared borrows of temporaries
99
};
1010

1111
fn main() {}

tests/ui/consts/qualif_overwrite_2.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/qualif_overwrite_2.rs:8:5
33
|
44
LL | &{a.0}

tests/ui/consts/refs-to-cell-in-final.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ unsafe impl<T> Sync for SyncPtr<T> {}
1111
// The resulting constant would pass all validation checks, so it is crucial that this gets rejected
1212
// by static const checks!
1313
static RAW_SYNC_S: SyncPtr<Cell<i32>> = SyncPtr { x: &Cell::new(42) };
14-
//~^ ERROR: interior mutable shared borrows of lifetime-extended temporaries
14+
//~^ ERROR: interior mutable shared borrows of temporaries
1515
const RAW_SYNC_C: SyncPtr<Cell<i32>> = SyncPtr { x: &Cell::new(42) };
16-
//~^ ERROR: interior mutable shared borrows of lifetime-extended temporaries
16+
//~^ ERROR: interior mutable shared borrows of temporaries
1717

1818
// This one does not get promoted because of `Drop`, and then enters interesting codepaths because
1919
// as a value it has no interior mutability, but as a type it does. See
@@ -39,7 +39,7 @@ const NONE_EXPLICIT_PROMOTED: &'static Option<Cell<i32>> = {
3939

4040
// Not okay, since we are borrowing something with interior mutability.
4141
const INTERIOR_MUT_VARIANT: &Option<UnsafeCell<bool>> = &{
42-
//~^ERROR: interior mutable shared borrows of lifetime-extended temporaries
42+
//~^ERROR: interior mutable shared borrows of temporaries
4343
let mut x = None;
4444
assert!(x.is_none());
4545
x = Some(UnsafeCell::new(false));

tests/ui/consts/refs-to-cell-in-final.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed
1+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/refs-to-cell-in-final.rs:13:54
33
|
44
LL | static RAW_SYNC_S: SyncPtr<Cell<i32>> = SyncPtr { x: &Cell::new(42) };
55
| ^^^^^^^^^^^^^^ this borrow of an interior mutable value refers to a lifetime-extended temporary
66
|
77
= help: to fix this, the value can be extracted to a separate `static` item and then referenced
88

9-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
9+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
1010
--> $DIR/refs-to-cell-in-final.rs:15:53
1111
|
1212
LL | const RAW_SYNC_C: SyncPtr<Cell<i32>> = SyncPtr { x: &Cell::new(42) };
1313
| ^^^^^^^^^^^^^^ this borrow of an interior mutable value refers to a lifetime-extended temporary
1414

15-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
15+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
1616
--> $DIR/refs-to-cell-in-final.rs:41:57
1717
|
1818
LL | const INTERIOR_MUT_VARIANT: &Option<UnsafeCell<bool>> = &{

tests/ui/consts/write_to_static_via_mut_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static OH_NO: &mut i32 = &mut 42; //~ ERROR mutable borrows of lifetime-extended temporaries
1+
static OH_NO: &mut i32 = &mut 42; //~ ERROR mutable borrows of temporaries
22
fn main() {
33
assert_eq!(*OH_NO, 42);
44
*OH_NO = 43; //~ ERROR cannot assign to `*OH_NO`, as `OH_NO` is an immutable static

tests/ui/consts/write_to_static_via_mut_ref.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed
1+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/write_to_static_via_mut_ref.rs:1:26
33
|
44
LL | static OH_NO: &mut i32 = &mut 42;

tests/ui/error-codes/E0017.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ static X: i32 = 1;
55
const C: i32 = 2;
66
static mut M: i32 = 3;
77

8-
const CR: &'static mut i32 = &mut C; //~ ERROR mutable borrows of lifetime-extended temporaries
8+
const CR: &'static mut i32 = &mut C; //~ ERROR mutable borrows of temporaries
99
//~| WARN taking a mutable
1010

1111
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR cannot borrow immutable static item `X` as mutable
1212

13-
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable borrows of lifetime-extended temporaries
13+
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable borrows of temporaries
1414
//~| WARN taking a mutable
1515

1616
fn main() {}

tests/ui/error-codes/E0017.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | const C: i32 = 2;
1313
| ^^^^^^^^^^^^
1414
= note: `#[warn(const_item_mutation)]` on by default
1515

16-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
16+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
1717
--> $DIR/E0017.rs:8:30
1818
|
1919
LL | const CR: &'static mut i32 = &mut C;
@@ -39,7 +39,7 @@ note: `const` item defined here
3939
LL | const C: i32 = 2;
4040
| ^^^^^^^^^^^^
4141

42-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed
42+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
4343
--> $DIR/E0017.rs:13:38
4444
|
4545
LL | static CONST_REF: &'static mut i32 = &mut C;

tests/ui/error-codes/E0492.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a constant are not allowed
1+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/E0492.rs:4:33
33
|
44
LL | const B: &'static AtomicUsize = &A;
55
| ^^ this borrow of an interior mutable value refers to a lifetime-extended temporary
66

7-
error[E0492]: interior mutable shared borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed
7+
error[E0492]: interior mutable shared borrows of temporaries that have their lifetime extended until the end of the program are not allowed
88
--> $DIR/E0492.rs:5:34
99
|
1010
LL | static C: &'static AtomicUsize = &A;

tests/ui/issues/issue-46604.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR mutable borrows of lifetime-extended temporaries
1+
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR mutable borrows of temporaries
22
fn write<T: AsRef<[u8]>>(buffer: T) { }
33

44
fn main() {

tests/ui/issues/issue-46604.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0764]: mutable borrows of lifetime-extended temporaries in the top-level scope of a static are not allowed
1+
error[E0764]: mutable borrows of temporaries that have their lifetime extended until the end of the program are not allowed
22
--> $DIR/issue-46604.rs:1:25
33
|
44
LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Checks that immutable static items can't have mutable slices
22

33
static TEST: &'static mut [isize] = &mut [];
4-
//~^ ERROR mutable borrows of lifetime-extended temporaries
4+
//~^ ERROR mutable borrows of temporaries
55

66
pub fn main() { }

0 commit comments

Comments
 (0)