update diagnostics for &mut in constants
This commit is contained in:
parent
014e605870
commit
1f48465a01
30 changed files with 111 additions and 180 deletions
|
@ -216,17 +216,23 @@ impl NonConstOp for MutBorrow {
|
|||
}
|
||||
|
||||
fn emit_error(&self, ccx: &ConstCx<'_, '_>, span: Span) {
|
||||
let mut err = feature_err(
|
||||
let mut err = if ccx.const_kind() == hir::ConstContext::ConstFn {
|
||||
feature_err(
|
||||
&ccx.tcx.sess.parse_sess,
|
||||
sym::const_mut_refs,
|
||||
span,
|
||||
&format!(
|
||||
"references in {}s may only refer \
|
||||
to immutable values",
|
||||
ccx.const_kind()
|
||||
),
|
||||
);
|
||||
err.span_label(span, format!("{}s require immutable values", ccx.const_kind()));
|
||||
&format!("mutable references are not allowed in {}s", ccx.const_kind()),
|
||||
)
|
||||
} else {
|
||||
struct_span_err!(
|
||||
ccx.tcx.sess,
|
||||
span,
|
||||
E0019,
|
||||
"mutable references are not allowed in {}s",
|
||||
ccx.const_kind(),
|
||||
)
|
||||
};
|
||||
err.span_label(span, "`&mut` is only allowed in `const fn`".to_string());
|
||||
if ccx.tcx.sess.teach(&err.get_code().unwrap()) {
|
||||
err.note(
|
||||
"References in statics and constants may only refer \
|
||||
|
|
|
@ -9,7 +9,7 @@ fn main() {
|
|||
[(); { for _ in 0usize.. {}; 0}];
|
||||
//~^ ERROR `for` is not allowed in a `const`
|
||||
//~| ERROR calls in constants are limited to constant functions
|
||||
//~| ERROR references in constants may only refer to immutable values
|
||||
//~| ERROR mutable references are not allowed in constants
|
||||
//~| ERROR calls in constants are limited to constant functions
|
||||
//~| ERROR evaluation of constant value failed
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Checks that immutable static items can't have mutable slices
|
||||
|
||||
static TEST: &'static mut [isize] = &mut [];
|
||||
//~^ ERROR references in statics may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in statics
|
||||
|
||||
pub fn main() { }
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/check-static-immutable-mut-slices.rs:3:37
|
||||
|
|
||||
LL | static TEST: &'static mut [isize] = &mut [];
|
||||
| ^^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
const _: Vec<i32> = {
|
||||
let mut x = Vec::<i32>::new(); //~ ERROR destructors cannot be evaluated at compile-time
|
||||
let r = &mut x; //~ ERROR references in constants may only refer to immutable values
|
||||
let r = &mut x; //~ ERROR mutable references are not allowed in constants
|
||||
let y = x;
|
||||
y
|
||||
};
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/issue-65394.rs:8:13
|
||||
|
|
||||
LL | let r = &mut x;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0493]: destructors cannot be evaluated at compile-time
|
||||
--> $DIR/issue-65394.rs:7:9
|
||||
|
@ -15,5 +12,5 @@ LL | let mut x = Vec::<i32>::new();
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0493, E0658.
|
||||
For more information about an error, try `rustc --explain E0493`.
|
||||
Some errors have detailed explanations: E0019, E0493.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
const _: i32 = {
|
||||
let mut a = 5;
|
||||
let p = &mut a; //~ ERROR references in constants may only refer to immutable values
|
||||
let p = &mut a; //~ ERROR mutable references are not allowed in constants
|
||||
|
||||
let reborrow = {p};
|
||||
let pp = &reborrow;
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const-multi-ref.rs:6:13
|
||||
|
|
||||
LL | let p = &mut a;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
|
||||
--> $DIR/const-multi-ref.rs:16:13
|
||||
|
@ -15,5 +12,5 @@ LL | let p = &a;
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0492, E0658.
|
||||
For more information about an error, try `rustc --explain E0492`.
|
||||
Some errors have detailed explanations: E0019, E0492.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -22,9 +22,9 @@ const fn baz(foo: &mut Foo)-> *mut usize {
|
|||
|
||||
const _: () = {
|
||||
foo().bar();
|
||||
//~^ ERROR references in constants may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
baz(&mut foo());
|
||||
//~^ ERROR references in constants may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
};
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_address_of.rs:24:5
|
||||
|
|
||||
LL | foo().bar();
|
||||
| ^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_address_of.rs:26:9
|
||||
|
|
||||
LL | baz(&mut foo());
|
||||
| ^^^^^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -29,9 +29,9 @@ const fn bazz(foo: &mut Foo) -> usize {
|
|||
|
||||
fn main() {
|
||||
let _: [(); foo().bar()] = [(); 1];
|
||||
//~^ ERROR references in constants may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
let _: [(); baz(&mut foo())] = [(); 2];
|
||||
//~^ ERROR references in constants may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
let _: [(); bazz(&mut foo())] = [(); 3];
|
||||
//~^ ERROR references in constants may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
}
|
||||
|
|
|
@ -1,30 +1,21 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_refs.rs:31:17
|
||||
|
|
||||
LL | let _: [(); foo().bar()] = [(); 1];
|
||||
| ^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_refs.rs:33:21
|
||||
|
|
||||
LL | let _: [(); baz(&mut foo())] = [(); 2];
|
||||
| ^^^^^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const_mut_refs.rs:35:22
|
||||
|
|
||||
LL | let _: [(); bazz(&mut foo())] = [(); 3];
|
||||
| ^^^^^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -13,14 +13,14 @@ impl S {
|
|||
|
||||
const FOO: S = {
|
||||
let mut s = S { state: 42 };
|
||||
s.foo(3); //~ ERROR references in constants may only refer to immutable values
|
||||
s.foo(3); //~ ERROR mutable references are not allowed in constants
|
||||
s
|
||||
};
|
||||
|
||||
type Array = [u32; {
|
||||
let mut x = 2;
|
||||
let y = &mut x;
|
||||
//~^ ERROR references in constants may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in constants
|
||||
*y = 42;
|
||||
//~^ ERROR constant contains unimplemented expression type
|
||||
*y
|
||||
|
|
|
@ -6,23 +6,17 @@ LL | self.state = x;
|
|||
|
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const_let_assign3.rs:16:5
|
||||
|
|
||||
LL | s.foo(3);
|
||||
| ^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/const_let_assign3.rs:22:13
|
||||
|
|
||||
LL | let y = &mut x;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0019]: constant contains unimplemented expression type
|
||||
--> $DIR/const_let_assign3.rs:24:5
|
||||
|
@ -34,5 +28,4 @@ LL | *y = 42;
|
|||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0019, E0658.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/projection_qualif.rs:10:27
|
||||
|
|
||||
LL | let b: *mut u32 = &mut a;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/projection_qualif.rs:11:18
|
||||
|
@ -18,4 +15,5 @@ LL | unsafe { *b = 5; }
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
Some errors have detailed explanations: E0019, E0658.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::cell::Cell;
|
|||
const FOO: &u32 = {
|
||||
let mut a = 42;
|
||||
{
|
||||
let b: *mut u32 = &mut a; //~ ERROR may only refer to immutable values
|
||||
let b: *mut u32 = &mut a; //~ ERROR mutable references are not allowed in constants
|
||||
unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants
|
||||
//[stock]~^ contains unimplemented expression
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/projection_qualif.rs:10:27
|
||||
|
|
||||
LL | let b: *mut u32 = &mut a;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||
--> $DIR/projection_qualif.rs:11:18
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
// 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 references in statics may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in statics
|
||||
fn main() {
|
||||
assert_eq!(*OH_NO, 42);
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
error[E0658]: references in statics may only refer to immutable values
|
||||
--> $DIR/read_from_static_mut_ref.rs:4:26
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/read_from_static_mut_ref.rs:5:26
|
||||
|
|
||||
LL | static OH_NO: &mut i32 = &mut 42;
|
||||
| ^^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: 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; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
||||
|
||||
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||
//~^ ERROR references in statics may only refer to immutable values
|
||||
//~^ ERROR mutable references are not allowed in statics
|
||||
//[stock]~| ERROR static contains unimplemented expression type
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: 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; };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0019]: static contains unimplemented expression type
|
||||
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
|
||||
|
@ -17,5 +14,4 @@ LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 4
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0019, E0658.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
For more information about this error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -2,10 +2,10 @@ static X: i32 = 1;
|
|||
const C: i32 = 2;
|
||||
static mut M: i32 = 3;
|
||||
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0658
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0658
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0019
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0019
|
||||
//~| ERROR E0019
|
||||
//~| ERROR cannot borrow
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0658
|
||||
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0658
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0019
|
||||
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0019
|
||||
fn main() {}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/E0017.rs:5:30
|
||||
|
|
||||
LL | const CR: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0019]: static contains unimplemented expression type
|
||||
--> $DIR/E0017.rs:6:39
|
||||
|
@ -15,14 +12,11 @@ LL | static STATIC_REF: &'static mut i32 = &mut X;
|
|||
|
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/E0017.rs:6:39
|
||||
|
|
||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0596]: cannot borrow immutable static item `X` as mutable
|
||||
--> $DIR/E0017.rs:6:39
|
||||
|
@ -30,25 +24,19 @@ error[E0596]: cannot borrow immutable static item `X` as mutable
|
|||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^ cannot borrow as mutable
|
||||
|
||||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/E0017.rs:9:38
|
||||
|
|
||||
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/E0017.rs:10:52
|
||||
|
|
||||
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
||||
| ^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0019, E0596, E0658.
|
||||
Some errors have detailed explanations: E0019, E0596.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
static X: i32 = 1;
|
||||
const C: i32 = 2;
|
||||
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0658
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0658
|
||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0019
|
||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0019
|
||||
//~| ERROR cannot borrow
|
||||
//~| ERROR E0019
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0658
|
||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0019
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/E0388.rs:4:30
|
||||
|
|
||||
LL | const CR: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0019]: static contains unimplemented expression type
|
||||
--> $DIR/E0388.rs:5:39
|
||||
|
@ -15,14 +12,11 @@ LL | static STATIC_REF: &'static mut i32 = &mut X;
|
|||
|
|
||||
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||
|
||||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/E0388.rs:5:39
|
||||
|
|
||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0596]: cannot borrow immutable static item `X` as mutable
|
||||
--> $DIR/E0388.rs:5:39
|
||||
|
@ -30,16 +24,13 @@ error[E0596]: cannot borrow immutable static item `X` as mutable
|
|||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||
| ^^^^^^ cannot borrow as mutable
|
||||
|
||||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/E0388.rs:8:38
|
||||
|
|
||||
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||
| ^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0019, E0596, E0658.
|
||||
Some errors have detailed explanations: E0019, E0596.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
const C1: &'static mut [usize] = &mut [];
|
||||
//~^ ERROR: references in constants may only refer to immutable values
|
||||
//~^ ERROR: mutable references are not allowed in constants
|
||||
|
||||
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: references in constants may only refer to immutable values
|
||||
//~| ERROR: mutable references are not allowed in constants
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in constants
|
||||
--> $DIR/issue-17718-const-bad-values.rs:1:34
|
||||
|
|
||||
LL | const C1: &'static mut [usize] = &mut [];
|
||||
| ^^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error[E0013]: constants cannot refer to statics
|
||||
--> $DIR/issue-17718-const-bad-values.rs:5:46
|
||||
|
@ -23,16 +20,13 @@ 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[E0658]: references in constants may only refer to immutable values
|
||||
error[E0019]: 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 };
|
||||
| ^^^^^^ constants require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^ `&mut` is only allowed in `const fn`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0013, E0658.
|
||||
Some errors have detailed explanations: E0013, E0019.
|
||||
For more information about an error, try `rustc --explain E0013`.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR E0658
|
||||
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR E0019
|
||||
fn write<T: AsRef<[u8]>>(buffer: T) { }
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
error[E0658]: references in statics may only refer to immutable values
|
||||
error[E0019]: mutable references are not allowed in statics
|
||||
--> $DIR/issue-46604.rs:1:25
|
||||
|
|
||||
LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
|
||||
| ^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
||||
|
|
||||
= 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
|
||||
| ^^^^^^^^^^^^^^^^^^^^ `&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
|
||||
|
@ -15,5 +12,5 @@ LL | buf[0]=2;
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0594, E0658.
|
||||
For more information about an error, try `rustc --explain E0594`.
|
||||
Some errors have detailed explanations: E0019, E0594.
|
||||
For more information about an error, try `rustc --explain E0019`.
|
||||
|
|
Loading…
Reference in a new issue