From d7db9698e66084154a5e87a7268b21a17b4171b8 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Mon, 14 Jun 2021 08:17:11 +0900 Subject: [PATCH] Add a regression test for issue-76510 --- .../const-mut-refs/issue-76510.32bit.stderr | 36 +++++++++++++++++++ .../const-mut-refs/issue-76510.64bit.stderr | 36 +++++++++++++++++++ .../ui/consts/const-mut-refs/issue-76510.rs | 18 ++++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr create mode 100644 src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr create mode 100644 src/test/ui/consts/const-mut-refs/issue-76510.rs diff --git a/src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr b/src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr new file mode 100644 index 0000000000000..965bc67a381ae --- /dev/null +++ b/src/test/ui/consts/const-mut-refs/issue-76510.32bit.stderr @@ -0,0 +1,36 @@ +error[E0764]: mutable references are not allowed in the final value of constants + --> $DIR/issue-76510.rs:5:29 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^ + +error[E0658]: mutation through a reference is not allowed in constants + --> $DIR/issue-76510.rs:5:29 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^ + | + = note: see issue #57349 for more information + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable + +error[E0596]: cannot borrow data in a `&` reference as mutable + --> $DIR/issue-76510.rs:5:29 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^ cannot borrow as mutable + +error[E0080]: it is undefined behavior to use this value + --> $DIR/issue-76510.rs:5:1 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered mutable reference in a `const` + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 8, align: 4) { + ╾─alloc2──╼ 07 00 00 00 │ ╾──╼.... + } + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0080, E0596, E0658, E0764. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr b/src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr new file mode 100644 index 0000000000000..ac7d5993585e8 --- /dev/null +++ b/src/test/ui/consts/const-mut-refs/issue-76510.64bit.stderr @@ -0,0 +1,36 @@ +error[E0764]: mutable references are not allowed in the final value of constants + --> $DIR/issue-76510.rs:5:29 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^ + +error[E0658]: mutation through a reference is not allowed in constants + --> $DIR/issue-76510.rs:5:29 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^ + | + = note: see issue #57349 for more information + = help: add `#![feature(const_mut_refs)]` to the crate attributes to enable + +error[E0596]: cannot borrow data in a `&` reference as mutable + --> $DIR/issue-76510.rs:5:29 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^ cannot borrow as mutable + +error[E0080]: it is undefined behavior to use this value + --> $DIR/issue-76510.rs:5:1 + | +LL | const S: &'static mut str = &mut " hello "; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered mutable reference in a `const` + | + = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. + = note: the raw bytes of the constant (size: 16, align: 8) { + ╾───────alloc2────────╼ 07 00 00 00 00 00 00 00 │ ╾──────╼........ + } + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0080, E0596, E0658, E0764. +For more information about an error, try `rustc --explain E0080`. diff --git a/src/test/ui/consts/const-mut-refs/issue-76510.rs b/src/test/ui/consts/const-mut-refs/issue-76510.rs new file mode 100644 index 0000000000000..892f6c98116c2 --- /dev/null +++ b/src/test/ui/consts/const-mut-refs/issue-76510.rs @@ -0,0 +1,18 @@ +// stderr-per-bitwidth + +use std::mem::{transmute, ManuallyDrop}; + +const S: &'static mut str = &mut " hello "; +//~^ ERROR: mutable references are not allowed in the final value of constants +//~| ERROR: mutation through a reference is not allowed in constants +//~| ERROR: cannot borrow data in a `&` reference as mutable +//~| ERROR: it is undefined behavior to use this value + +const fn trigger() -> [(); unsafe { + let s = transmute::<(*const u8, usize), &ManuallyDrop>((S.as_ptr(), 3)); + 0 + }] { + [(); 0] +} + +fn main() {}