Permit mutable references in all const contexts
This commit is contained in:
parent
1986b58c64
commit
d118021f8b
35 changed files with 298 additions and 171 deletions
|
|
@ -1,6 +1,6 @@
|
|||
// Checks that immutable static items can't have mutable slices
|
||||
|
||||
static TEST: &'static mut [isize] = &mut [];
|
||||
//~^ ERROR mutable references are not allowed in statics
|
||||
//~^ ERROR mutable references are not allowed
|
||||
|
||||
pub fn main() { }
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error[E0764]: mutable references are not allowed in statics
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/check-static-immutable-mut-slices.rs:3:37
|
||||
|
|
||||
LL | static TEST: &'static mut [isize] = &mut [];
|
||||
| ^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -1,20 +1,29 @@
|
|||
error[E0764]: raw mutable references are not allowed in constants
|
||||
error[E0658]: raw mutable references are not allowed in constants
|
||||
--> $DIR/const-address-of-mut.rs:3:32
|
||||
|
|
||||
LL | const A: () = { let mut x = 2; &raw mut x; };
|
||||
| ^^^^^^^^^^ `&raw mut` is only allowed in `const fn`
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0764]: raw mutable references are not allowed in statics
|
||||
error[E0658]: raw mutable references are not allowed in statics
|
||||
--> $DIR/const-address-of-mut.rs:5:33
|
||||
|
|
||||
LL | static B: () = { let mut x = 2; &raw mut x; };
|
||||
| ^^^^^^^^^^ `&raw mut` is only allowed in `const fn`
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0764]: raw mutable references are not allowed in statics
|
||||
error[E0658]: raw mutable references are not allowed in statics
|
||||
--> $DIR/const-address-of-mut.rs:7:37
|
||||
|
|
||||
LL | static mut C: () = { let mut x = 2; &raw mut x; };
|
||||
| ^^^^^^^^^^ `&raw mut` is only allowed in `const fn`
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: raw mutable references are not allowed in constant functions
|
||||
--> $DIR/const-address-of-mut.rs:11:13
|
||||
|
|
@ -27,5 +36,4 @@ LL | let y = &raw mut x;
|
|||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0658, E0764.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
--> $DIR/issue-65394.rs:8:13
|
||||
|
|
||||
LL | let r = &mut x;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0493]: destructors cannot be evaluated at compile-time
|
||||
--> $DIR/issue-65394.rs:7:9
|
||||
|
|
@ -15,5 +18,5 @@ LL | };
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0493, E0764.
|
||||
Some errors have detailed explanations: E0493, E0658.
|
||||
For more information about an error, try `rustc --explain E0493`.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
--> $DIR/const-multi-ref.rs:6:13
|
||||
|
|
||||
LL | let p = &mut a;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: cannot borrow here, since the borrowed element may contain interior mutability
|
||||
--> $DIR/const-multi-ref.rs:16:13
|
||||
|
|
@ -15,5 +18,4 @@ LL | let p = &a;
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0658, E0764.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
// check-pass
|
||||
#![feature(const_mut_refs)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(raw_ref_op)]
|
||||
|
|
@ -22,9 +23,7 @@ const fn baz(foo: &mut Foo)-> *mut usize {
|
|||
|
||||
const _: () = {
|
||||
foo().bar();
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
baz(&mut foo());
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
error[E0764]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_address_of.rs:24:5
|
||||
|
|
||||
LL | foo().bar();
|
||||
| ^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_address_of.rs:26:9
|
||||
|
|
||||
LL | baz(&mut foo());
|
||||
| ^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0764`.
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
// check-pass
|
||||
#![feature(const_mut_refs)]
|
||||
|
||||
struct Foo {
|
||||
|
|
@ -29,9 +30,6 @@ const fn bazz(foo: &mut Foo) -> usize {
|
|||
|
||||
fn main() {
|
||||
let _: [(); foo().bar()] = [(); 1];
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
let _: [(); baz(&mut foo())] = [(); 2];
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
let _: [(); bazz(&mut foo())] = [(); 3];
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
error[E0764]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_refs.rs:31:17
|
||||
|
|
||||
LL | let _: [(); foo().bar()] = [(); 1];
|
||||
| ^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_refs.rs:33:21
|
||||
|
|
||||
LL | let _: [(); baz(&mut foo())] = [(); 2];
|
||||
| ^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_refs.rs:35:22
|
||||
|
|
||||
LL | let _: [(); bazz(&mut foo())] = [(); 3];
|
||||
| ^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0764`.
|
||||
24
src/test/ui/consts/const-mut-refs/mut_ref_in_final.rs
Normal file
24
src/test/ui/consts/const-mut-refs/mut_ref_in_final.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#![feature(const_mut_refs)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(raw_ref_op)]
|
||||
const NULL: *mut i32 = std::ptr::null_mut();
|
||||
const A: *const i32 = &4;
|
||||
|
||||
// It could be made sound to allow it to compile,
|
||||
// but we do not want to allow this to compile,
|
||||
// as that would be an enormous footgun in oli-obk's opinion.
|
||||
const B: *mut i32 = &mut 4; //~ ERROR mutable references are not allowed
|
||||
|
||||
// Could be ok, but the same analysis that prevents the mutable one above will also bail out here
|
||||
// Using a block with some complex content, because just `&45` would get promoted,
|
||||
// which is not what we want to test here.
|
||||
const C: *const i32 = &{
|
||||
let mut x = 42;
|
||||
x += 3;
|
||||
x
|
||||
};
|
||||
|
||||
fn main() {
|
||||
println!("{}", unsafe { *A });
|
||||
unsafe { *B = 4 } // Bad news
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
error[E0764]: mutable references are not allowed in final value of constants
|
||||
--> $DIR/mut_ref_in_final.rs:10:21
|
||||
|
|
||||
LL | const B: *mut i32 = &mut 4;
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0764`.
|
||||
22
src/test/ui/consts/const-mut-refs/mut_ref_in_final_ok.rs
Normal file
22
src/test/ui/consts/const-mut-refs/mut_ref_in_final_ok.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#![feature(const_mut_refs)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(raw_ref_op)]
|
||||
|
||||
use std::cell::UnsafeCell;
|
||||
struct NotAMutex<T>(UnsafeCell<T>);
|
||||
|
||||
unsafe impl<T> Sync for NotAMutex<T> {}
|
||||
|
||||
const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
|
||||
//~^ ERROR temporary value dropped while borrowed
|
||||
|
||||
// `BAR` works, because `&42` promotes immediately instead of relying on
|
||||
// "final value lifetime extension".
|
||||
const BAR: NotAMutex<&i32> = NotAMutex(UnsafeCell::new(&42));
|
||||
|
||||
fn main() {
|
||||
unsafe {
|
||||
**FOO.0.get() = 99;
|
||||
assert_eq!(**FOO.0.get(), 99);
|
||||
}
|
||||
}
|
||||
13
src/test/ui/consts/const-mut-refs/mut_ref_in_final_ok.stderr
Normal file
13
src/test/ui/consts/const-mut-refs/mut_ref_in_final_ok.stderr
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
error[E0716]: temporary value dropped while borrowed
|
||||
--> $DIR/mut_ref_in_final_ok.rs:10:65
|
||||
|
|
||||
LL | const FOO: NotAMutex<&mut i32> = NotAMutex(UnsafeCell::new(&mut 42));
|
||||
| -------------------------------^^--
|
||||
| | | |
|
||||
| | | temporary value is freed at the end of this statement
|
||||
| | creates a temporary which is freed while still in use
|
||||
| using this value as a constant requires that borrow lasts for `'static`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0716`.
|
||||
|
|
@ -7,19 +7,24 @@ LL | const fn foo(&mut self, x: u32) {
|
|||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
--> $DIR/const_let_assign3.rs:16:5
|
||||
|
|
||||
LL | s.foo(3);
|
||||
| ^ `&mut` is only allowed in `const fn`
|
||||
| ^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
--> $DIR/const_let_assign3.rs:22:13
|
||||
|
|
||||
LL | let y = &mut x;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0658, E0764.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
const C1: &'static mut [usize] = &mut [];
|
||||
//~^ ERROR: mutable references are not allowed in constants
|
||||
//~^ ERROR: mutable references are not allowed
|
||||
|
||||
static mut S: usize = 3;
|
||||
const C2: &'static mut usize = unsafe { &mut S };
|
||||
//~^ ERROR: constants cannot refer to statics
|
||||
//~| ERROR: constants cannot refer to statics
|
||||
//~| ERROR: mutable references are not allowed in constants
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0764]: mutable references are not allowed in final value of constants
|
||||
--> $DIR/issue-17718-const-bad-values.rs:1:34
|
||||
|
|
||||
LL | const C1: &'static mut [usize] = &mut [];
|
||||
| ^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^^
|
||||
|
||||
error[E0013]: constants cannot refer to statics
|
||||
--> $DIR/issue-17718-const-bad-values.rs:5:46
|
||||
|
|
@ -20,13 +20,7 @@ LL | const C2: &'static mut usize = unsafe { &mut S };
|
|||
|
|
||||
= help: consider extracting the value of the `static` to a `const`, and referring to that
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
--> $DIR/issue-17718-const-bad-values.rs:5:41
|
||||
|
|
||||
LL | const C2: &'static mut usize = unsafe { &mut S };
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0013, E0764.
|
||||
For more information about an error, try `rustc --explain E0013`.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
error[E0764]: mutable references are not allowed in constants
|
||||
--> $DIR/projection_qualif.rs:10:27
|
||||
|
|
||||
LL | let b: *mut u32 = &mut a;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/projection_qualif.rs:11:18
|
||||
|
|
||||
|
|
@ -13,7 +7,6 @@ LL | unsafe { *b = 5; }
|
|||
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
|
||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0658, E0764.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use std::cell::Cell;
|
|||
const FOO: &u32 = {
|
||||
let mut a = 42;
|
||||
{
|
||||
let b: *mut u32 = &mut a; //~ ERROR mutable references are not allowed in constants
|
||||
let b: *mut u32 = &mut a; //[stock]~ ERROR mutable references are not allowed in constants
|
||||
unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants
|
||||
}
|
||||
&{a}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
--> $DIR/projection_qualif.rs:10:27
|
||||
|
|
||||
LL | let b: *mut u32 = &mut a;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/projection_qualif.rs:11:18
|
||||
|
|
@ -15,5 +18,4 @@ LL | unsafe { *b = 5; }
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0658, E0764.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
// We are keeping this test in case we decide to allow mutable references in statics again
|
||||
#![feature(const_mut_refs)]
|
||||
#![allow(const_err)]
|
||||
|
||||
static OH_NO: &mut i32 = &mut 42;
|
||||
//~^ ERROR mutable references are not allowed in statics
|
||||
static OH_NO: &mut i32 = &mut 42; //~ ERROR mutable references are not allowed
|
||||
fn main() {
|
||||
assert_eq!(*OH_NO, 42);
|
||||
*OH_NO = 43; //~ ERROR cannot assign to `*OH_NO`, as `OH_NO` is an immutable static
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,16 @@
|
|||
error[E0764]: mutable references are not allowed in statics
|
||||
--> $DIR/read_from_static_mut_ref.rs:5:26
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/read_from_static_mut_ref.rs:4:26
|
||||
|
|
||||
LL | static OH_NO: &mut i32 = &mut 42;
|
||||
| ^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0594]: cannot assign to `*OH_NO`, as `OH_NO` is an immutable static item
|
||||
--> $DIR/read_from_static_mut_ref.rs:7:5
|
||||
|
|
||||
LL | *OH_NO = 43;
|
||||
| ^^^^^^^^^^^ cannot assign
|
||||
|
||||
For more information about this error, try `rustc --explain E0764`.
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0594, E0764.
|
||||
For more information about an error, try `rustc --explain E0594`.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
error[E0764]: mutable references are not allowed in statics
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:7:46
|
||||
error[E0080]: could not evaluate static initializer
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
|
||||
|
|
||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ modifying a static's initial value from another static's initializer
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0764`.
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
||||
|
||||
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
//~^ ERROR mutable references are not allowed in statics
|
||||
//[mut_refs]~^ ERROR could not evaluate static initializer
|
||||
//[stock]~^^ ERROR mutable references are not allowed in statics
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,12 @@
|
|||
error[E0764]: mutable references are not allowed in statics
|
||||
error[E0658]: mutable references are not allowed in statics
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:7:46
|
||||
|
|
||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0764`.
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -2,12 +2,13 @@ static X: i32 = 1;
|
|||
const C: i32 = 2;
|
||||
static mut M: i32 = 3;
|
||||
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0764
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed
|
||||
//~| WARN taking a mutable
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0764
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0658
|
||||
//~| ERROR cannot borrow
|
||||
//~| ERROR mutable references are not allowed
|
||||
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0764
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed
|
||||
//~| WARN taking a mutable
|
||||
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0764
|
||||
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR mutable references are not
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -13,17 +13,26 @@ note: `const` item defined here
|
|||
LL | const C: i32 = 2;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0764]: mutable references are not allowed in final value of constants
|
||||
--> $DIR/E0017.rs:5:30
|
||||
|
|
||||
LL | const CR: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in statics
|
||||
error[E0658]: mutation through a reference is not allowed in statics
|
||||
--> $DIR/E0017.rs:7:39
|
||||
|
|
||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/E0017.rs:7:39
|
||||
|
|
||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0596]: cannot borrow immutable static item `X` as mutable
|
||||
--> $DIR/E0017.rs:7:39
|
||||
|
|
@ -32,7 +41,7 @@ LL | static STATIC_REF: &'static mut i32 = &mut X;
|
|||
| ^^^^^^ cannot borrow as mutable
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/E0017.rs:10:38
|
||||
--> $DIR/E0017.rs:11:38
|
||||
|
|
||||
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||
| ^^^^^^
|
||||
|
|
@ -45,19 +54,19 @@ note: `const` item defined here
|
|||
LL | const C: i32 = 2;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in statics
|
||||
--> $DIR/E0017.rs:10:38
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/E0017.rs:11:38
|
||||
|
|
||||
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in statics
|
||||
--> $DIR/E0017.rs:12:52
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/E0017.rs:13:52
|
||||
|
|
||||
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors; 2 warnings emitted
|
||||
error: aborting due to 6 previous errors; 2 warnings emitted
|
||||
|
||||
Some errors have detailed explanations: E0596, E0764.
|
||||
Some errors have detailed explanations: E0596, E0658, E0764.
|
||||
For more information about an error, try `rustc --explain E0596`.
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
static X: i32 = 1;
|
||||
const C: i32 = 2;
|
||||
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0764
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed
|
||||
//~| WARN taking a mutable
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR cannot borrow
|
||||
//~| ERROR E0764
|
||||
//~| ERROR E0658
|
||||
//~| ERROR mutable references are not allowed
|
||||
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0764
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR mutable references are not allowed
|
||||
//~| WARN taking a mutable
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -13,17 +13,26 @@ note: `const` item defined here
|
|||
LL | const C: i32 = 2;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0764]: mutable references are not allowed in final value of constants
|
||||
--> $DIR/E0388.rs:4:30
|
||||
|
|
||||
LL | const CR: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in statics
|
||||
error[E0658]: mutation through a reference is not allowed in statics
|
||||
--> $DIR/E0388.rs:6:39
|
||||
|
|
||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/E0388.rs:6:39
|
||||
|
|
||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^
|
||||
|
||||
error[E0596]: cannot borrow immutable static item `X` as mutable
|
||||
--> $DIR/E0388.rs:6:39
|
||||
|
|
@ -32,7 +41,7 @@ LL | static STATIC_REF: &'static mut i32 = &mut X;
|
|||
| ^^^^^^ cannot borrow as mutable
|
||||
|
||||
warning: taking a mutable reference to a `const` item
|
||||
--> $DIR/E0388.rs:9:38
|
||||
--> $DIR/E0388.rs:10:38
|
||||
|
|
||||
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||
| ^^^^^^
|
||||
|
|
@ -45,13 +54,13 @@ note: `const` item defined here
|
|||
LL | const C: i32 = 2;
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in statics
|
||||
--> $DIR/E0388.rs:9:38
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/E0388.rs:10:38
|
||||
|
|
||||
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to 4 previous errors; 2 warnings emitted
|
||||
error: aborting due to 5 previous errors; 2 warnings emitted
|
||||
|
||||
Some errors have detailed explanations: E0596, E0764.
|
||||
Some errors have detailed explanations: E0596, E0658, E0764.
|
||||
For more information about an error, try `rustc --explain E0596`.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR E0764
|
||||
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR mutable references are not allowed
|
||||
fn write<T: AsRef<[u8]>>(buffer: T) { }
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
error[E0764]: mutable references are not allowed in statics
|
||||
error[E0764]: mutable references are not allowed in final value of statics
|
||||
--> $DIR/issue-46604.rs:1:25
|
||||
|
|
||||
LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0594]: cannot assign to `buf[_]`, as `buf` is an immutable static item
|
||||
--> $DIR/issue-46604.rs:6:5
|
||||
|
|
|
|||
|
|
@ -39,11 +39,14 @@ error[E0015]: calls in constants are limited to constant functions, tuple struct
|
|||
LL | [(); { for _ in 0usize.. {}; 0}];
|
||||
| ^^^^^^^^
|
||||
|
||||
error[E0764]: mutable references are not allowed in constants
|
||||
error[E0658]: mutable references are not allowed in constants
|
||||
--> $DIR/issue-52443.rs:9:21
|
||||
|
|
||||
LL | [(); { for _ in 0usize.. {}; 0}];
|
||||
| ^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
--> $DIR/issue-52443.rs:9:21
|
||||
|
|
@ -53,5 +56,5 @@ LL | [(); { for _ in 0usize.. {}; 0}];
|
|||
|
||||
error: aborting due to 6 previous errors; 1 warning emitted
|
||||
|
||||
Some errors have detailed explanations: E0015, E0308, E0744, E0764.
|
||||
Some errors have detailed explanations: E0015, E0308, E0658, E0744.
|
||||
For more information about an error, try `rustc --explain E0015`.
|
||||
|
|
|
|||
|
|
@ -18,3 +18,9 @@ const fn bar() -> NonZero<u32> {
|
|||
let y = unsafe { &mut x.0 }; //~ ERROR mutable references
|
||||
unsafe { NonZero(1) }
|
||||
}
|
||||
|
||||
const fn boo() -> NonZero<u32> {
|
||||
let mut x = unsafe { NonZero(1) };
|
||||
unsafe { let y = &mut x.0; } //~ ERROR mutable references
|
||||
unsafe { NonZero(1) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,15 @@ LL | let y = unsafe { &mut x.0 };
|
|||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: mutable references are not allowed in constant functions
|
||||
--> $DIR/ranged_ints2_const.rs:24:22
|
||||
|
|
||||
LL | unsafe { let y = &mut x.0; }
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0133]: mutation of layout constrained field is unsafe and requires unsafe function or block
|
||||
--> $DIR/ranged_ints2_const.rs:11:13
|
||||
|
|
||||
|
|
@ -24,7 +33,7 @@ LL | let y = &mut x.0;
|
|||
|
|
||||
= note: mutating layout constrained fields cannot statically be checked for valid values
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0133, E0658.
|
||||
For more information about an error, try `rustc --explain E0133`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue