diff options
| author | Ralf Jung <post@ralfj.de> | 2021-05-15 15:04:41 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2021-05-15 15:04:41 +0200 |
| commit | a1507b80c2d438cc7e72bd164cccb456408c0ac7 (patch) | |
| tree | 237649e9ad711a44ba7755042a5063dad36e275c /src/test/ui/consts | |
| parent | 75da570d784a798a34ff1e5048cd9a6a2fb23170 (diff) | |
| download | rust-a1507b80c2d438cc7e72bd164cccb456408c0ac7.tar.gz rust-a1507b80c2d438cc7e72bd164cccb456408c0ac7.zip | |
handle pointers in str
Diffstat (limited to 'src/test/ui/consts')
| -rw-r--r-- | src/test/ui/consts/issue-83182.rs | 6 | ||||
| -rw-r--r-- | src/test/ui/consts/issue-83182.stderr | 14 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/test/ui/consts/issue-83182.rs b/src/test/ui/consts/issue-83182.rs new file mode 100644 index 00000000000..13c6e94f101 --- /dev/null +++ b/src/test/ui/consts/issue-83182.rs @@ -0,0 +1,6 @@ +use std::mem; +struct MyStr(str); +const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; +//~^ ERROR: it is undefined behavior to use this value +//~| type validation failed: encountered a pointer in `str` +fn main() {} diff --git a/src/test/ui/consts/issue-83182.stderr b/src/test/ui/consts/issue-83182.stderr new file mode 100644 index 00000000000..f7ee6a21ab2 --- /dev/null +++ b/src/test/ui/consts/issue-83182.stderr @@ -0,0 +1,14 @@ +error[E0080]: it is undefined behavior to use this value + --> $DIR/issue-83182.rs:3:1 + | +LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered a pointer in `str` at .<deref>.0 + | + = 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) { + ╾───────alloc3────────╼ 01 00 00 00 00 00 00 00 │ ╾──────╼........ + } + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`. |
