Rollup merge of #66606 - christianpoveda:mut-refs-in-const-fn, r=oli-obk
Add feature gate for mut refs in const fn r? @oli-obk
This commit is contained in:
commit
2bd35c065c
33 changed files with 311 additions and 142 deletions
|
@ -18,7 +18,6 @@ E0010: include_str!("./error_codes/E0010.md"),
|
||||||
E0013: include_str!("./error_codes/E0013.md"),
|
E0013: include_str!("./error_codes/E0013.md"),
|
||||||
E0014: include_str!("./error_codes/E0014.md"),
|
E0014: include_str!("./error_codes/E0014.md"),
|
||||||
E0015: include_str!("./error_codes/E0015.md"),
|
E0015: include_str!("./error_codes/E0015.md"),
|
||||||
E0017: include_str!("./error_codes/E0017.md"),
|
|
||||||
E0019: include_str!("./error_codes/E0019.md"),
|
E0019: include_str!("./error_codes/E0019.md"),
|
||||||
E0023: include_str!("./error_codes/E0023.md"),
|
E0023: include_str!("./error_codes/E0023.md"),
|
||||||
E0025: include_str!("./error_codes/E0025.md"),
|
E0025: include_str!("./error_codes/E0025.md"),
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
References in statics and constants may only refer to immutable values.
|
|
||||||
|
|
||||||
Erroneous code example:
|
|
||||||
|
|
||||||
```compile_fail,E0017
|
|
||||||
static X: i32 = 1;
|
|
||||||
const C: i32 = 2;
|
|
||||||
|
|
||||||
// these three are not allowed:
|
|
||||||
const CR: &mut i32 = &mut C;
|
|
||||||
static STATIC_REF: &'static mut i32 = &mut X;
|
|
||||||
static CONST_REF: &'static mut i32 = &mut C;
|
|
||||||
```
|
|
||||||
|
|
||||||
Statics are shared everywhere, and if they refer to mutable data one might
|
|
||||||
violate memory safety since holding multiple mutable references to shared data
|
|
||||||
is not allowed.
|
|
||||||
|
|
||||||
If you really want global mutable state, try using `static mut` or a global
|
|
||||||
`UnsafeCell`.
|
|
|
@ -523,6 +523,9 @@ declare_features! (
|
||||||
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
|
/// Allows the use of `#[cfg(sanitize = "option")]`; set when -Zsanitizer is used.
|
||||||
(active, cfg_sanitize, "1.41.0", Some(39699), None),
|
(active, cfg_sanitize, "1.41.0", Some(39699), None),
|
||||||
|
|
||||||
|
/// Allows using `&mut` in constant functions.
|
||||||
|
(active, const_mut_refs, "1.41.0", Some(57349), None),
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
// feature-group-end: actual feature gates
|
// feature-group-end: actual feature gates
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! Concrete error types for all operations which may be invalid in a certain const context.
|
//! Concrete error types for all operations which may be invalid in a certain const context.
|
||||||
|
|
||||||
use rustc::hir::def_id::DefId;
|
use rustc::hir::def_id::DefId;
|
||||||
use rustc::mir::BorrowKind;
|
|
||||||
use rustc::session::config::nightly_options;
|
use rustc::session::config::nightly_options;
|
||||||
use rustc::ty::TyCtxt;
|
use rustc::ty::TyCtxt;
|
||||||
use syntax::feature_gate::feature_err;
|
use syntax::feature_gate::feature_err;
|
||||||
|
@ -181,38 +180,53 @@ impl NonConstOp for Loop {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MutBorrow(pub BorrowKind);
|
pub struct CellBorrow;
|
||||||
impl NonConstOp for MutBorrow {
|
impl NonConstOp for CellBorrow {
|
||||||
fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
|
fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
|
||||||
let kind = self.0;
|
span_err!(item.tcx.sess, span, E0492,
|
||||||
if let BorrowKind::Mut { .. } = kind {
|
"cannot borrow a constant which may contain \
|
||||||
let mut err = struct_span_err!(item.tcx.sess, span, E0017,
|
interior mutability, create a static instead");
|
||||||
"references in {}s may only refer \
|
}
|
||||||
to immutable values", item.const_kind());
|
}
|
||||||
err.span_label(span, format!("{}s require immutable values",
|
|
||||||
item.const_kind()));
|
#[derive(Debug)]
|
||||||
if item.tcx.sess.teach(&err.get_code().unwrap()) {
|
pub struct MutBorrow;
|
||||||
err.note("References in statics and constants may only refer \
|
impl NonConstOp for MutBorrow {
|
||||||
to immutable values.\n\n\
|
fn feature_gate(tcx: TyCtxt<'_>) -> Option<bool> {
|
||||||
Statics are shared everywhere, and if they refer to \
|
Some(tcx.features().const_mut_refs)
|
||||||
mutable data one might violate memory safety since \
|
}
|
||||||
holding multiple mutable references to shared data \
|
|
||||||
is not allowed.\n\n\
|
fn emit_error(&self, item: &Item<'_, '_>, span: Span) {
|
||||||
If you really want global mutable state, try using \
|
let mut err = feature_err(
|
||||||
static mut or a global UnsafeCell.");
|
&item.tcx.sess.parse_sess,
|
||||||
}
|
sym::const_mut_refs,
|
||||||
err.emit();
|
span,
|
||||||
} else {
|
&format!("references in {}s may only refer \
|
||||||
span_err!(item.tcx.sess, span, E0492,
|
to immutable values", item.const_kind())
|
||||||
"cannot borrow a constant which may contain \
|
);
|
||||||
interior mutability, create a static instead");
|
err.span_label(span, format!("{}s require immutable values",
|
||||||
|
item.const_kind()));
|
||||||
|
if item.tcx.sess.teach(&err.get_code().unwrap()) {
|
||||||
|
err.note("References in statics and constants may only refer \
|
||||||
|
to immutable values.\n\n\
|
||||||
|
Statics are shared everywhere, and if they refer to \
|
||||||
|
mutable data one might violate memory safety since \
|
||||||
|
holding multiple mutable references to shared data \
|
||||||
|
is not allowed.\n\n\
|
||||||
|
If you really want global mutable state, try using \
|
||||||
|
static mut or a global UnsafeCell.");
|
||||||
}
|
}
|
||||||
|
err.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct MutDeref;
|
pub struct MutDeref;
|
||||||
impl NonConstOp for MutDeref {}
|
impl NonConstOp for MutDeref {
|
||||||
|
fn feature_gate(tcx: TyCtxt<'_>) -> Option<bool> {
|
||||||
|
Some(tcx.features().const_mut_refs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Panic;
|
pub struct Panic;
|
||||||
|
|
|
@ -359,7 +359,11 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
if !is_allowed {
|
if !is_allowed {
|
||||||
self.check_op(ops::MutBorrow(kind));
|
if let BorrowKind::Mut{ .. } = kind {
|
||||||
|
self.check_op(ops::MutBorrow);
|
||||||
|
} else {
|
||||||
|
self.check_op(ops::CellBorrow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,7 +388,11 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
|
||||||
);
|
);
|
||||||
|
|
||||||
if borrowed_place_has_mut_interior {
|
if borrowed_place_has_mut_interior {
|
||||||
self.check_op(ops::MutBorrow(kind));
|
if let BorrowKind::Mut{ .. } = kind {
|
||||||
|
self.check_op(ops::MutBorrow);
|
||||||
|
} else {
|
||||||
|
self.check_op(ops::CellBorrow);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,7 +459,6 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_projection_elem(
|
fn visit_projection_elem(
|
||||||
&mut self,
|
&mut self,
|
||||||
place_base: &PlaceBase<'tcx>,
|
place_base: &PlaceBase<'tcx>,
|
||||||
|
|
|
@ -79,10 +79,14 @@ pub fn is_min_const_fn(tcx: TyCtxt<'tcx>, def_id: DefId, body: &'a Body<'tcx>) -
|
||||||
fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult {
|
fn check_ty(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span, fn_def_id: DefId) -> McfResult {
|
||||||
for ty in ty.walk() {
|
for ty in ty.walk() {
|
||||||
match ty.kind {
|
match ty.kind {
|
||||||
ty::Ref(_, _, hir::Mutability::Mutable) => return Err((
|
ty::Ref(_, _, hir::Mutability::Mutable) => {
|
||||||
span,
|
if !tcx.features().const_mut_refs {
|
||||||
"mutable references in const fn are unstable".into(),
|
return Err((
|
||||||
)),
|
span,
|
||||||
|
"mutable references in const fn are unstable".into(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())),
|
ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())),
|
||||||
ty::FnPtr(..) => {
|
ty::FnPtr(..) => {
|
||||||
if !tcx.const_fn_is_allowed_fn_ptr(fn_def_id) {
|
if !tcx.const_fn_is_allowed_fn_ptr(fn_def_id) {
|
||||||
|
|
|
@ -213,6 +213,7 @@ symbols! {
|
||||||
const_indexing,
|
const_indexing,
|
||||||
const_in_array_repeat_expressions,
|
const_in_array_repeat_expressions,
|
||||||
const_let,
|
const_let,
|
||||||
|
const_mut_refs,
|
||||||
const_panic,
|
const_panic,
|
||||||
const_raw_ptr_deref,
|
const_raw_ptr_deref,
|
||||||
const_raw_ptr_to_usize_cast,
|
const_raw_ptr_to_usize_cast,
|
||||||
|
|
|
@ -6,7 +6,7 @@ const fn f(x: usize) -> usize {
|
||||||
let mut sum = 0;
|
let mut sum = 0;
|
||||||
for i in 0..x {
|
for i in 0..x {
|
||||||
//~^ ERROR E0015
|
//~^ ERROR E0015
|
||||||
//~| ERROR E0017
|
//~| ERROR E0658
|
||||||
//~| ERROR E0080
|
//~| ERROR E0080
|
||||||
//~| ERROR E0744
|
//~| ERROR E0744
|
||||||
//~| ERROR E0019
|
//~| ERROR E0019
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
error[E0017]: references in statics may only refer to immutable values
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
--> $DIR/check-static-immutable-mut-slices.rs:3:37
|
--> $DIR/check-static-immutable-mut-slices.rs:3:37
|
||||||
|
|
|
|
||||||
LL | static TEST: &'static mut [isize] = &mut [];
|
LL | static TEST: &'static mut [isize] = &mut [];
|
||||||
| ^^^^^^^ statics require immutable values
|
| ^^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0017`.
|
For more information about this error, try `rustc --explain E0658`.
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/issue-65394.rs:8:13
|
--> $DIR/issue-65394.rs:8:13
|
||||||
|
|
|
|
||||||
LL | let r = &mut x;
|
LL | let r = &mut x;
|
||||||
| ^^^^^^ constants require immutable values
|
| ^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0493]: destructors cannot be evaluated at compile-time
|
error[E0493]: destructors cannot be evaluated at compile-time
|
||||||
--> $DIR/issue-65394.rs:7:9
|
--> $DIR/issue-65394.rs:7:9
|
||||||
|
@ -12,5 +15,5 @@ LL | let mut x = Vec::<i32>::new();
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0017, E0493.
|
Some errors have detailed explanations: E0493, E0658.
|
||||||
For more information about an error, try `rustc --explain E0017`.
|
For more information about an error, try `rustc --explain E0493`.
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/const-multi-ref.rs:6:13
|
--> $DIR/const-multi-ref.rs:6:13
|
||||||
|
|
|
|
||||||
LL | let p = &mut a;
|
LL | let p = &mut a;
|
||||||
| ^^^^^^ constants require immutable values
|
| ^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
|
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead
|
||||||
--> $DIR/const-multi-ref.rs:16:13
|
--> $DIR/const-multi-ref.rs:16:13
|
||||||
|
@ -12,5 +15,5 @@ LL | let p = &a;
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0017, E0492.
|
Some errors have detailed explanations: E0492, E0658.
|
||||||
For more information about an error, try `rustc --explain E0017`.
|
For more information about an error, try `rustc --explain E0492`.
|
||||||
|
|
36
src/test/ui/consts/const-mut-refs/const_mut_refs.rs
Normal file
36
src/test/ui/consts/const-mut-refs/const_mut_refs.rs
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// run-pass
|
||||||
|
|
||||||
|
#![feature(const_mut_refs)]
|
||||||
|
|
||||||
|
struct Foo {
|
||||||
|
x: usize
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn foo() -> Foo {
|
||||||
|
Foo { x: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Foo {
|
||||||
|
const fn bar(&mut self) -> usize {
|
||||||
|
self.x = 1;
|
||||||
|
self.x
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn baz(foo: &mut Foo) -> usize {
|
||||||
|
let x = &mut foo.x;
|
||||||
|
*x = 2;
|
||||||
|
*x
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn bazz(foo: &mut Foo) -> usize {
|
||||||
|
foo.x = 3;
|
||||||
|
foo.x
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _: [(); foo().bar()] = [(); 1];
|
||||||
|
let _: [(); baz(&mut foo())] = [(); 2];
|
||||||
|
let _: [(); bazz(&mut foo())] = [(); 3];
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
fn main() {
|
||||||
|
foo(&mut 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fn foo(x: &mut i32) -> i32 { //~ ERROR mutable references in const fn are unstable
|
||||||
|
*x + 1
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0723]: mutable references in const fn are unstable
|
||||||
|
--> $DIR/feature-gate-const_mut_refs.rs:5:14
|
||||||
|
|
|
||||||
|
LL | const fn foo(x: &mut i32) -> i32 {
|
||||||
|
| ^
|
||||||
|
|
|
||||||
|
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563
|
||||||
|
= help: add `#![feature(const_fn)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0723`.
|
|
@ -4,17 +4,23 @@ error[E0019]: constant function contains unimplemented expression type
|
||||||
LL | self.state = x;
|
LL | self.state = x;
|
||||||
| ^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/const_let_assign3.rs:16:5
|
--> $DIR/const_let_assign3.rs:16:5
|
||||||
|
|
|
|
||||||
LL | s.foo(3);
|
LL | s.foo(3);
|
||||||
| ^ constants require immutable values
|
| ^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/const_let_assign3.rs:22:13
|
--> $DIR/const_let_assign3.rs:22:13
|
||||||
|
|
|
|
||||||
LL | let y = &mut x;
|
LL | let y = &mut x;
|
||||||
| ^^^^^^ constants require immutable values
|
| ^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0019]: constant contains unimplemented expression type
|
error[E0019]: constant contains unimplemented expression type
|
||||||
--> $DIR/const_let_assign3.rs:24:5
|
--> $DIR/const_let_assign3.rs:24:5
|
||||||
|
@ -24,5 +30,5 @@ LL | *y = 42;
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0017, E0019.
|
Some errors have detailed explanations: E0019, E0658.
|
||||||
For more information about an error, try `rustc --explain E0017`.
|
For more information about an error, try `rustc --explain E0019`.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||||
|
|
||||||
#![feature(const_raw_ptr_deref)]
|
#![feature(const_raw_ptr_deref)]
|
||||||
|
#![feature(const_mut_refs)]
|
||||||
#![deny(const_err)]
|
#![deny(const_err)]
|
||||||
|
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
|
@ -12,9 +13,7 @@ const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
const MUTATING_BEHIND_RAW: () = {
|
const MUTATING_BEHIND_RAW: () = {
|
||||||
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
|
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
|
||||||
unsafe {
|
unsafe {
|
||||||
*MUTABLE_BEHIND_RAW = 99 //~ WARN skipping const checks
|
*MUTABLE_BEHIND_RAW = 99 //~ ERROR any use of this value will cause an error
|
||||||
//~^ ERROR any use of this value will cause an error
|
|
||||||
//~^^ tried to modify constant memory
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,23 @@
|
||||||
warning: skipping const checks
|
warning: skipping const checks
|
||||||
--> $DIR/mutable_const.rs:9:38
|
--> $DIR/mutable_const.rs:10:38
|
||||||
|
|
|
|
||||||
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
warning: skipping const checks
|
|
||||||
--> $DIR/mutable_const.rs:15:9
|
|
||||||
|
|
|
||||||
LL | *MUTABLE_BEHIND_RAW = 99
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: any use of this value will cause an error
|
error: any use of this value will cause an error
|
||||||
--> $DIR/mutable_const.rs:15:9
|
--> $DIR/mutable_const.rs:16:9
|
||||||
|
|
|
|
||||||
LL | / const MUTATING_BEHIND_RAW: () = {
|
LL | / const MUTATING_BEHIND_RAW: () = {
|
||||||
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
|
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
|
||||||
LL | | unsafe {
|
LL | | unsafe {
|
||||||
LL | | *MUTABLE_BEHIND_RAW = 99
|
LL | | *MUTABLE_BEHIND_RAW = 99
|
||||||
| | ^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify constant memory
|
| | ^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify constant memory
|
||||||
... |
|
|
||||||
LL | | }
|
LL | | }
|
||||||
LL | | };
|
LL | | };
|
||||||
| |__-
|
| |__-
|
||||||
|
|
|
|
||||||
note: lint level defined here
|
note: lint level defined here
|
||||||
--> $DIR/mutable_const.rs:4:9
|
--> $DIR/mutable_const.rs:5:9
|
||||||
|
|
|
|
||||||
LL | #![deny(const_err)]
|
LL | #![deny(const_err)]
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
// compile-flags: -Zunleash-the-miri-inside-of-you
|
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||||
|
#![feature(const_mut_refs)]
|
||||||
#![allow(const_err)]
|
#![allow(const_err)]
|
||||||
|
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
|
|
||||||
// a test demonstrating what things we could allow with a smarter const qualification
|
// a test demonstrating what things we could allow with a smarter const qualification
|
||||||
|
|
||||||
|
// this is fine because is not possible to mutate through an immutable reference.
|
||||||
static FOO: &&mut u32 = &&mut 42;
|
static FOO: &&mut u32 = &&mut 42;
|
||||||
//~^ WARN: skipping const checks
|
|
||||||
|
|
||||||
|
// this is fine because accessing an immutable static `BAR` is equivalent to accessing `*&BAR`
|
||||||
|
// which puts the mutable reference behind an immutable one.
|
||||||
static BAR: &mut () = &mut ();
|
static BAR: &mut () = &mut ();
|
||||||
//~^ WARN: skipping const checks
|
|
||||||
|
|
||||||
struct Foo<T>(T);
|
struct Foo<T>(T);
|
||||||
|
|
||||||
|
// this is fine for the same reason as `BAR`.
|
||||||
static BOO: &mut Foo<()> = &mut Foo(());
|
static BOO: &mut Foo<()> = &mut Foo(());
|
||||||
//~^ WARN: skipping const checks
|
|
||||||
|
|
||||||
struct Meh {
|
struct Meh {
|
||||||
x: &'static UnsafeCell<i32>,
|
x: &'static UnsafeCell<i32>,
|
||||||
|
@ -27,8 +29,8 @@ static MEH: Meh = Meh {
|
||||||
//~^ WARN: skipping const checks
|
//~^ WARN: skipping const checks
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// this is fine for the same reason as `BAR`.
|
||||||
static OH_YES: &mut i32 = &mut 42;
|
static OH_YES: &mut i32 = &mut 42;
|
||||||
//~^ WARN: skipping const checks
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -1,35 +1,11 @@
|
||||||
warning: skipping const checks
|
warning: skipping const checks
|
||||||
--> $DIR/mutable_references.rs:8:26
|
--> $DIR/mutable_references.rs:28:8
|
||||||
|
|
|
||||||
LL | static FOO: &&mut u32 = &&mut 42;
|
|
||||||
| ^^^^^^^
|
|
||||||
|
|
||||||
warning: skipping const checks
|
|
||||||
--> $DIR/mutable_references.rs:11:23
|
|
||||||
|
|
|
||||||
LL | static BAR: &mut () = &mut ();
|
|
||||||
| ^^^^^^^
|
|
||||||
|
|
||||||
warning: skipping const checks
|
|
||||||
--> $DIR/mutable_references.rs:16:28
|
|
||||||
|
|
|
||||||
LL | static BOO: &mut Foo<()> = &mut Foo(());
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
||||||
warning: skipping const checks
|
|
||||||
--> $DIR/mutable_references.rs:26:8
|
|
||||||
|
|
|
|
||||||
LL | x: &UnsafeCell::new(42),
|
LL | x: &UnsafeCell::new(42),
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
warning: skipping const checks
|
|
||||||
--> $DIR/mutable_references.rs:30:27
|
|
||||||
|
|
|
||||||
LL | static OH_YES: &mut i32 = &mut 42;
|
|
||||||
| ^^^^^^^
|
|
||||||
|
|
||||||
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
|
error[E0594]: cannot assign to `*OH_YES`, as `OH_YES` is an immutable static item
|
||||||
--> $DIR/mutable_references.rs:37:5
|
--> $DIR/mutable_references.rs:39:5
|
||||||
|
|
|
|
||||||
LL | *OH_YES = 99;
|
LL | *OH_YES = 99;
|
||||||
| ^^^^^^^^^^^^ cannot assign
|
| ^^^^^^^^^^^^ cannot assign
|
||||||
|
|
11
src/test/ui/consts/miri_unleashed/read_from_static.rs
Normal file
11
src/test/ui/consts/miri_unleashed/read_from_static.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// run-pass
|
||||||
|
// compile-flags: -Zunleash-the-miri-inside-of-you
|
||||||
|
#![feature(const_mut_refs)]
|
||||||
|
#![allow(const_err)]
|
||||||
|
|
||||||
|
static OH_YES: &mut i32 = &mut 42;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Make sure `OH_YES` can be read.
|
||||||
|
assert_eq!(*OH_YES, 42);
|
||||||
|
}
|
12
src/test/ui/consts/projection_qualif.mut_refs.stderr
Normal file
12
src/test/ui/consts/projection_qualif.mut_refs.stderr
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||||
|
--> $DIR/projection_qualif.rs:11:18
|
||||||
|
|
|
||||||
|
LL | unsafe { *b = 5; }
|
||||||
|
| ^^^^^^
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/51911
|
||||||
|
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0658`.
|
|
@ -1,11 +1,15 @@
|
||||||
|
// revisions: stock mut_refs
|
||||||
|
|
||||||
|
#![cfg_attr(mut_refs, feature(const_mut_refs))]
|
||||||
|
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
|
||||||
const FOO: &u32 = {
|
const FOO: &u32 = {
|
||||||
let mut a = 42;
|
let mut a = 42;
|
||||||
{
|
{
|
||||||
let b: *mut u32 = &mut a; //~ ERROR may only refer to immutable values
|
let b: *mut u32 = &mut a; //[stock]~ ERROR may only refer to immutable values
|
||||||
unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants
|
unsafe { *b = 5; } //~ ERROR dereferencing raw pointers in constants
|
||||||
//~^ contains unimplemented expression
|
//[stock]~^ contains unimplemented expression
|
||||||
}
|
}
|
||||||
&{a}
|
&{a}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/projection_qualif.rs:6:27
|
--> $DIR/projection_qualif.rs:10:27
|
||||||
|
|
|
|
||||||
LL | let b: *mut u32 = &mut a;
|
LL | let b: *mut u32 = &mut a;
|
||||||
| ^^^^^^ constants require immutable values
|
| ^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0658]: dereferencing raw pointers in constants is unstable
|
error[E0658]: dereferencing raw pointers in constants is unstable
|
||||||
--> $DIR/projection_qualif.rs:7:18
|
--> $DIR/projection_qualif.rs:11:18
|
||||||
|
|
|
|
||||||
LL | unsafe { *b = 5; }
|
LL | unsafe { *b = 5; }
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
@ -14,12 +17,12 @@ LL | unsafe { *b = 5; }
|
||||||
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0019]: constant contains unimplemented expression type
|
error[E0019]: constant contains unimplemented expression type
|
||||||
--> $DIR/projection_qualif.rs:7:18
|
--> $DIR/projection_qualif.rs:11:18
|
||||||
|
|
|
|
||||||
LL | unsafe { *b = 5; }
|
LL | unsafe { *b = 5; }
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0017, E0019, E0658.
|
Some errors have detailed explanations: E0019, E0658.
|
||||||
For more information about an error, try `rustc --explain E0017`.
|
For more information about an error, try `rustc --explain E0019`.
|
|
@ -0,0 +1,9 @@
|
||||||
|
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; };
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ tried to modify 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 E0080`.
|
|
@ -1,7 +1,12 @@
|
||||||
|
// revisions: stock mut_refs
|
||||||
|
|
||||||
|
#![cfg_attr(mut_refs, feature(const_mut_refs))]
|
||||||
|
|
||||||
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
static mut STDERR_BUFFER_SPACE: u8 = 0;
|
||||||
|
|
||||||
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||||
//~^ ERROR references in statics may only refer to immutable values
|
//[mut_refs]~^ ERROR could not evaluate static initializer
|
||||||
//~| ERROR static contains unimplemented expression type
|
//[stock]~^^ ERROR references in statics may only refer to immutable values
|
||||||
|
//[stock]~| ERROR static contains unimplemented expression type
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
error[E0017]: references in statics may only refer to immutable values
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
--> $DIR/static_mut_containing_mut_ref2.rs:3:46
|
--> $DIR/static_mut_containing_mut_ref2.rs:7:46
|
||||||
|
|
|
|
||||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0019]: static contains unimplemented expression type
|
error[E0019]: static contains unimplemented expression type
|
||||||
--> $DIR/static_mut_containing_mut_ref2.rs:3:45
|
--> $DIR/static_mut_containing_mut_ref2.rs:7:45
|
||||||
|
|
|
|
||||||
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
LL | pub static mut STDERR_BUFFER: () = unsafe { *(&mut STDERR_BUFFER_SPACE) = 42; };
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0017, E0019.
|
Some errors have detailed explanations: E0019, E0658.
|
||||||
For more information about an error, try `rustc --explain E0017`.
|
For more information about an error, try `rustc --explain E0019`.
|
|
@ -2,10 +2,10 @@ static X: i32 = 1;
|
||||||
const C: i32 = 2;
|
const C: i32 = 2;
|
||||||
static mut M: i32 = 3;
|
static mut M: i32 = 3;
|
||||||
|
|
||||||
const CR: &'static mut i32 = &mut C; //~ ERROR E0017
|
const CR: &'static mut i32 = &mut C; //~ ERROR E0658
|
||||||
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0017
|
static STATIC_REF: &'static mut i32 = &mut X; //~ ERROR E0658
|
||||||
//~| ERROR E0019
|
//~| ERROR E0019
|
||||||
//~| ERROR cannot borrow
|
//~| ERROR cannot borrow
|
||||||
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0017
|
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0658
|
||||||
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0017
|
static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M }; //~ ERROR E0658
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/E0017.rs:5:30
|
--> $DIR/E0017.rs:5:30
|
||||||
|
|
|
|
||||||
LL | const CR: &'static mut i32 = &mut C;
|
LL | const CR: &'static mut i32 = &mut C;
|
||||||
| ^^^^^^ constants require immutable values
|
| ^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0019]: static contains unimplemented expression type
|
error[E0019]: static contains unimplemented expression type
|
||||||
--> $DIR/E0017.rs:6:39
|
--> $DIR/E0017.rs:6:39
|
||||||
|
@ -10,11 +13,14 @@ error[E0019]: static contains unimplemented expression type
|
||||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||||
| ^^^^^^
|
| ^^^^^^
|
||||||
|
|
||||||
error[E0017]: references in statics may only refer to immutable values
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
--> $DIR/E0017.rs:6:39
|
--> $DIR/E0017.rs:6:39
|
||||||
|
|
|
|
||||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||||
| ^^^^^^ statics require immutable values
|
| ^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0596]: cannot borrow immutable static item `X` as mutable
|
error[E0596]: cannot borrow immutable static item `X` as mutable
|
||||||
--> $DIR/E0017.rs:6:39
|
--> $DIR/E0017.rs:6:39
|
||||||
|
@ -22,19 +28,25 @@ error[E0596]: cannot borrow immutable static item `X` as mutable
|
||||||
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||||
| ^^^^^^ cannot borrow as mutable
|
| ^^^^^^ cannot borrow as mutable
|
||||||
|
|
||||||
error[E0017]: references in statics may only refer to immutable values
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
--> $DIR/E0017.rs:9:38
|
--> $DIR/E0017.rs:9:38
|
||||||
|
|
|
|
||||||
LL | static CONST_REF: &'static mut i32 = &mut C;
|
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||||
| ^^^^^^ statics require immutable values
|
| ^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0017]: references in statics may only refer to immutable values
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
--> $DIR/E0017.rs:10:52
|
--> $DIR/E0017.rs:10:52
|
||||||
|
|
|
|
||||||
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
LL | static STATIC_MUT_REF: &'static mut i32 = unsafe { &mut M };
|
||||||
| ^^^^^^ statics require immutable values
|
| ^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 6 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0017, E0019, E0596.
|
Some errors have detailed explanations: E0019, E0596, E0658.
|
||||||
For more information about an error, try `rustc --explain E0017`.
|
For more information about an error, try `rustc --explain E0019`.
|
||||||
|
|
10
src/test/ui/error-codes/E0388.rs
Normal file
10
src/test/ui/error-codes/E0388.rs
Normal file
|
@ -0,0 +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
|
||||||
|
//~| ERROR cannot borrow
|
||||||
|
//~| ERROR E0019
|
||||||
|
static CONST_REF: &'static mut i32 = &mut C; //~ ERROR E0658
|
||||||
|
|
||||||
|
fn main() {}
|
43
src/test/ui/error-codes/E0388.stderr
Normal file
43
src/test/ui/error-codes/E0388.stderr
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
|
--> $DIR/E0388.rs:4:30
|
||||||
|
|
|
||||||
|
LL | const CR: &'static mut i32 = &mut C;
|
||||||
|
| ^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0019]: static contains unimplemented expression type
|
||||||
|
--> $DIR/E0388.rs:5:39
|
||||||
|
|
|
||||||
|
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
|
--> $DIR/E0388.rs:5:39
|
||||||
|
|
|
||||||
|
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||||
|
| ^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error[E0596]: cannot borrow immutable static item `X` as mutable
|
||||||
|
--> $DIR/E0388.rs:5:39
|
||||||
|
|
|
||||||
|
LL | static STATIC_REF: &'static mut i32 = &mut X;
|
||||||
|
| ^^^^^^ cannot borrow as mutable
|
||||||
|
|
||||||
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
|
--> $DIR/E0388.rs:8:38
|
||||||
|
|
|
||||||
|
LL | static CONST_REF: &'static mut i32 = &mut C;
|
||||||
|
| ^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0019, E0596, E0658.
|
||||||
|
For more information about an error, try `rustc --explain E0019`.
|
|
@ -1,8 +1,11 @@
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/issue-17718-const-bad-values.rs:1:34
|
--> $DIR/issue-17718-const-bad-values.rs:1:34
|
||||||
|
|
|
|
||||||
LL | const C1: &'static mut [usize] = &mut [];
|
LL | const C1: &'static mut [usize] = &mut [];
|
||||||
| ^^^^^^^ constants require immutable values
|
| ^^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0013]: constants cannot refer to statics, use a constant instead
|
error[E0013]: constants cannot refer to statics, use a constant instead
|
||||||
--> $DIR/issue-17718-const-bad-values.rs:5:46
|
--> $DIR/issue-17718-const-bad-values.rs:5:46
|
||||||
|
@ -10,13 +13,16 @@ error[E0013]: constants cannot refer to statics, use a constant instead
|
||||||
LL | const C2: &'static mut usize = unsafe { &mut S };
|
LL | const C2: &'static mut usize = unsafe { &mut S };
|
||||||
| ^
|
| ^
|
||||||
|
|
||||||
error[E0017]: references in constants may only refer to immutable values
|
error[E0658]: references in constants may only refer to immutable values
|
||||||
--> $DIR/issue-17718-const-bad-values.rs:5:41
|
--> $DIR/issue-17718-const-bad-values.rs:5:41
|
||||||
|
|
|
|
||||||
LL | const C2: &'static mut usize = unsafe { &mut S };
|
LL | const C2: &'static mut usize = unsafe { &mut S };
|
||||||
| ^^^^^^ constants require immutable values
|
| ^^^^^^ constants require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0013, E0017.
|
Some errors have detailed explanations: E0013, E0658.
|
||||||
For more information about an error, try `rustc --explain E0013`.
|
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 E0017
|
static buf: &mut [u8] = &mut [1u8,2,3,4,5,7]; //~ ERROR E0658
|
||||||
fn write<T: AsRef<[u8]>>(buffer: T) { }
|
fn write<T: AsRef<[u8]>>(buffer: T) { }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
error[E0017]: references in statics may only refer to immutable values
|
error[E0658]: references in statics may only refer to immutable values
|
||||||
--> $DIR/issue-46604.rs:1:25
|
--> $DIR/issue-46604.rs:1:25
|
||||||
|
|
|
|
||||||
LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
|
LL | static buf: &mut [u8] = &mut [1u8,2,3,4,5,7];
|
||||||
| ^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
| ^^^^^^^^^^^^^^^^^^^^ statics require immutable values
|
||||||
|
|
|
||||||
|
= note: for more information, see https://github.com/rust-lang/rust/issues/57349
|
||||||
|
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0594]: cannot assign to `buf[_]`, as `buf` is an immutable static item
|
error[E0594]: cannot assign to `buf[_]`, as `buf` is an immutable static item
|
||||||
--> $DIR/issue-46604.rs:6:5
|
--> $DIR/issue-46604.rs:6:5
|
||||||
|
@ -12,5 +15,5 @@ LL | buf[0]=2;
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
Some errors have detailed explanations: E0017, E0594.
|
Some errors have detailed explanations: E0594, E0658.
|
||||||
For more information about an error, try `rustc --explain E0017`.
|
For more information about an error, try `rustc --explain E0594`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue