Skip to content

miri: make read_discriminant UB when the tag is not in the validity range of the tag field#153408

Open
RalfJung wants to merge 1 commit intorust-lang:mainfrom
RalfJung:tag-read-must-be-valid
Open

miri: make read_discriminant UB when the tag is not in the validity range of the tag field#153408
RalfJung wants to merge 1 commit intorust-lang:mainfrom
RalfJung:tag-read-must-be-valid

Conversation

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Mar 4, 2026

Arguably, reading an enum discriminant is an operation that uses the "type" of the discriminant field -- and therefore it should fail when the value in that field isn't valid at that type. Therefore, code like this should be UB:

fn main() {
    unsafe {
        let x = 12u8;
        let x_ptr: *const u8 = &x;
        let cast_ptr = x_ptr as *const Option<bool>;
        // Reading the discriminant should fail since the tag value is not in the valid
        // range for the tag field.
        let _val = matches!(*cast_ptr, None);
        //~^ ERROR: invalid tag
    }
}

However, Miri currently sees no UB here. (MiniRust does see UB.) This is because we never actually check whether the tag we read is in the validity range for its field. So let's add such a check, and a corresponding test.

In fact, we have to do this check, since the codegen backend adds range metadata on the discriminant load, as can be seen in this example. In other words, the above code has UB in LLVM IR but not in Miri, which is a critical Miri bug.

@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2026

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 4, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2026

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir
  • compiler, mir expanded to 69 candidates
  • Random selection from 16 candidates

@RalfJung RalfJung force-pushed the tag-read-must-be-valid branch from 4153e62 to b4b2429 Compare March 4, 2026 15:31
@RalfJung
Copy link
Member Author

RalfJung commented Mar 4, 2026

r? @oli-obk

@rustbot rustbot assigned oli-obk and unassigned JohnTitor Mar 4, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the tag-read-must-be-valid branch from b4b2429 to f2ff029 Compare March 4, 2026 16:22
@RalfJung RalfJung force-pushed the tag-read-must-be-valid branch from f2ff029 to afff350 Compare March 4, 2026 17:15
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-20 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           1.6G   12K  1.6G   1% /run/user/1001
================================================================================

Sufficient disk space available (95818632KB >= 52428800KB). Skipping cleanup.
##[group]Run echo "[CI_PR_NUMBER=$num]"
echo "[CI_PR_NUMBER=$num]"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---
set -ex

# Run a subset of tests. Used to run tests in parallel in multiple jobs.

# When this job partition is run as part of PR CI, skip tidy to allow revealing more failures. The
# dedicated `tidy` job failing won't block other PR CI jobs from completing, and so tidy failures
# shouldn't inhibit revealing other failures in PR CI jobs.
if [ "$PR_CI_JOB" == "1" ]; then
  echo "PR_CI_JOB set; skipping tidy"
  SKIP_TIDY="--skip tidy"
fi

../x.py --stage 2 test \
  ${SKIP_TIDY:+$SKIP_TIDY} \
  --skip compiler \
  --skip src
#!/bin/bash

set -ex

# Run a subset of tests. Used to run tests in parallel in multiple jobs.

# When this job partition is run as part of PR CI, skip tidy to allow revealing more failures. The
# dedicated `tidy` job failing won't block other PR CI jobs from completing, and so tidy failures
# shouldn't inhibit revealing other failures in PR CI jobs.
if [ "$PR_CI_JOB" == "1" ]; then
  echo "PR_CI_JOB set; skipping tidy"
  SKIP_TIDY="--skip tidy"
fi

../x.py --stage 2 test \
  ${SKIP_TIDY:+$SKIP_TIDY} \
  --skip tests \
  --skip coverage-map \
  --skip coverage-run \
  --skip library \
  --skip tidyselftest
---
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/context.cc: In function ‘void fancy_abort(const char*, int, const char*)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/context.cc:1796:15: warning: format not a string literal and no format arguments [-Wformat-security]
 1796 |       fnotice (stderr, diagnostics::get_text_for_kind (diagnostics::kind::ice));
      |       ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/digraphs-to-dot-from-cfg.cc: In member function ‘virtual void diagnostics::digraphs::to_dot::converter_from_cfg::add_any_node_attrs(const diagnostics::digraphs::to_dot::digraph_node&, dot::node_stmt&)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/digraphs-to-dot-from-cfg.cc:173:36: warning: spurious leading punctuation sequence ‘<’ in format [-Wformat-diag]
  173 |                   pp_printf (&pp, "<bb %li>:", bb_index);
      |                                    ^
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/digraphs-to-dot-from-cfg.cc:173:43: warning: spurious trailing punctuation sequence ‘>:’ in format [-Wformat-diag]
  173 |                   pp_printf (&pp, "<bb %li>:", bb_index);
      |                                           ^~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/digraphs-to-dot-from-cfg.cc: In member function ‘virtual void diagnostics::digraphs::to_dot::converter_from_cfg::add_any_edge_attrs(const diagnostics::digraphs::to_dot::digraph_edge&, dot::edge_stmt&)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/digraphs-to-dot-from-cfg.cc:246:26: warning: spurious leading punctuation sequence ‘[’ in format [-Wformat-diag]
  246 |         pp_printf (&pp, "[%li%%]", probability_pc);
      |                          ^
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/sarif-sink.cc: In member function ‘void diagnostics::sarif_socket_sink::send_rpc_notification(const json::object&)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/diagnostics/sarif-sink.cc:4282:11: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 4282 |     write (m_fd, buf, output_size);
      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/text-art/style.cc: In member function ‘void text_art::style::color::print_sgr(pretty_printer*, bool, bool&) const’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/i686-unknown-linux-gnu/src/gcc/text-art/style.cc:149:25: warning: spurious leading punctuation sequence ‘;’ in format [-Wformat-diag]
  149 |         pp_printf (pp, ";5;%i", (int)u.m_8bit);
      |                         ^
---
test [ui] tests/ui/abi/abi-sysv64-register-usage.rs ... ok
test [ui] tests/ui/abi/abi-typo-unstable.rs#feature_enabled ... ok
test [ui] tests/ui/abi/abi-typo-unstable.rs#feature_disabled ... ok
test [ui] tests/ui/abi/anon-extern-mod.rs ... ok
test [ui] tests/ui/abi/avr-sram.rs#disable_sram ... ok
test [ui] tests/ui/abi/avr-sram.rs#has_sram ... ok
test [ui] tests/ui/abi/arm-unadjusted-intrinsic.rs#aarch64 ... ok
test [ui] tests/ui/abi/avr-sram.rs#no_sram ... ok
test [ui] tests/ui/abi/c-stack-as-value.rs ... ok
test [ui] tests/ui/abi/arm-unadjusted-intrinsic.rs#arm ... ok
test [ui] tests/ui/abi/bad-custom.rs ... ok
test [ui] tests/ui/abi/c-stack-returning-int64.rs ... ok
test [ui] tests/ui/abi/c-zst.rs#aarch64-darwin ... ok
---
test [ui] tests/ui/asm/aarch64/type-f16.rs ... ignored, only executed when the architecture is aarch64
test [ui] tests/ui/array-slice-vec/vector-no-ann.rs ... ok
test [ui] tests/ui/array-slice-vec/vector-slice-matching-8498.rs ... ok
test [ui] tests/ui/asm/aarch64/arm64ec-sve.rs ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#hf ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#r82 ... ok
test [ui] tests/ui/asm/aarch64v8r.rs#sf ... ok
test [ui] tests/ui/asm/asm-with-nested-closure.rs ... ok
test [ui] tests/ui/asm/binary_asm_labels.rs ... ignored, only executed when the architecture is x86_64
test [ui] tests/ui/asm/binary_asm_labels_allowed.rs ... ignored, only executed when the architecture is aarch64
test [ui] tests/ui/asm/arm-low-dreg.rs ... ok
test [ui] tests/ui/asm/cfg.rs#reva ... ignored, only executed when the architecture is x86_64
---
test [ui] tests/ui/const-generics/occurs-check/unify-n-nplusone.rs ... ok
test [ui] tests/ui/const-generics/occurs-check/unused-substs-3.rs ... ok
test [ui] tests/ui/const-generics/occurs-check/unused-substs-5.rs ... ok
test [ui] tests/ui/const-generics/occurs-check/unused-substs-4.rs ... ok
test [ui] tests/ui/const-generics/ogca/basic-fail.rs ... ok
test [ui] tests/ui/const-generics/ogca/basic.rs ... ok
test [ui] tests/ui/const-generics/ogca/coherence-ambiguous.rs ... ok
test [ui] tests/ui/const-generics/ogca/rhs-but-not-root.rs ... ok
test [ui] tests/ui/const-generics/ogca/generic-param-rhs.rs ... ok
test [ui] tests/ui/const-generics/opaque_types.rs ... ok
test [ui] tests/ui/const-generics/outer-lifetime-in-const-generic-default.rs ... ok
test [ui] tests/ui/const-generics/overlapping_impls.rs ... ok
test [ui] tests/ui/const-generics/opaque_types2.rs ... ok
test [ui] tests/ui/const-generics/params-in-ct-in-ty-param-lazy-norm.rs#min ... ok
---
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#thin0 ... ok
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#thin1 ... ok
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#thin2 ... ok
test [ui] tests/ui/extern/issue-64655-extern-rust-must-allow-unwind.rs#thin3 ... ok
test [ui] tests/ui/extern/lgamma-linkage.rs ... ok
test [ui] tests/ui/extern/issue-95829.rs ... ok
test [ui] tests/ui/extern/not-in-block.rs ... ok
test [ui] tests/ui/extern/unsized-extern-derefmove.rs ... ok
test [ui] tests/ui/extern/windows-tcb-trash-13259.rs ... ok
test [ui] tests/ui/feature-gates/allow-features-empty.rs ... ok
---
test [ui] tests/ui/feature-gates/feature-gate-macro-derive.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-macro-metavar-expr-concat.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-marker_trait_attr.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-may-dangle.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-mgca-type-const-syntax.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-min-generic-const-args.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-movrs_target_feature.rs ... ignored, only executed when the architecture is x86_64
test [ui] tests/ui/feature-gates/feature-gate-min_const_fn.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-more-maybe-bounds.rs ... ok
test [ui] tests/ui/feature-gates/feature-gate-naked_functions_rustic_abi.rs ... ignored, only executed when the architecture is x86_64
---
test [ui] tests/ui/imports/ambiguous-7.rs ... ok
test [ui] tests/ui/imports/ambiguous-import-visibility-module.rs ... ok
test [ui] tests/ui/imports/ambiguous-8.rs ... ok
test [ui] tests/ui/imports/ambiguous-glob-vs-expanded-extern.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-glob-vs-multiouter.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-globvsglob.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-no-implicit-prelude.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-non-prelude-core-glob.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-non-prelude-std-glob.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-pick-core.rs ... ok
test [ui] tests/ui/imports/ambiguous-panic-pick-std.rs ... ok
---
test [ui] tests/ui/layout/null-pointer-optimization.rs ... ok
test [ui] tests/ui/layout/randomize.rs#normal ... ok
test [ui] tests/ui/layout/randomize.rs#randomize-layout ... ok
test [ui] tests/ui/layout/post-mono-layout-cycle.rs ... ok
test [ui] tests/ui/layout/rigid-alias-no-params.rs ... ok
test [ui] tests/ui/layout/rigid-alias-due-to-broken-impl.rs ... ok
test [ui] tests/ui/layout/reprc-power-alignment.rs ... ok
test [ui] tests/ui/layout/rust-call-abi-not-a-tuple-ice-81974.rs ... ok
test [ui] tests/ui/layout/struct.rs ... ok
test [ui] tests/ui/layout/thaw-validate-invalid-enum.rs ... ok
test [ui] tests/ui/layout/thin-meta-implies-thin-ptr.rs ... ok
---
- error[E0080]: constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
+ error[E0080]: constructing invalid value at .<enum-tag>: encountered 0x03, but expected a valid enum tag
35   --> $DIR/raw-bytes.rs:47:1
36    |
37 LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };


The actual 32bit.stderr differed from the expected 32bit.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args consts/const-eval/raw-bytes.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/consts/const-eval/raw-bytes.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=i686-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/raw-bytes" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=x86_64-linux-gnu-gcc"
stdout: none
--- stderr -------------------------------
error[E0080]: constructing invalid value at .<enum-tag>: encountered 0x00000001, but expected a valid enum tag
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:23:1
   |
LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
   | ^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               01 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value at .<enum-tag>: encountered 0x00000000, but expected a valid enum tag
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:31:1
   |
LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               00 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value at .<enum-tag>: encountered an uninhabited enum variant
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:45:1
   |
LL | const BAD_UNINHABITED_VARIANT1: UninhDiscriminant = unsafe { mem::transmute(1u8) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 1, align: 1) {
               01                                              │ .
           }

error[E0080]: constructing invalid value at .<enum-tag>: encountered 0x03, but expected a valid enum tag
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:47:1
   |
LL | const BAD_UNINHABITED_VARIANT2: UninhDiscriminant = unsafe { mem::transmute(3u8) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 1, align: 1) {
               03                                              │ .
           }

error[E0080]: constructing invalid value at .<enum-variant(Some)>.0.1: encountered 0xffffffff, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:53:1
   |
LL | const BAD_OPTION_CHAR: Option<(char, char)> = Some(('x', unsafe { mem::transmute(!0u32) }));
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               78 00 00 00 ff ff ff ff                         │ x.......
           }

error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:58:1
   |
LL | const NULL_PTR: NonNull<u8> = unsafe { mem::transmute(0usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               00 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:61:1
   |
LL | const NULL_U8: NonZero<u8> = unsafe { mem::transmute(0u8) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 1, align: 1) {
               00                                              │ .
           }

error[E0080]: constructing invalid value at .0.0: encountered 0, but expected something greater or equal to 1
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:63:1
   |
LL | const NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(0usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               00 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value: encountered 42, but expected something in the range 10..=30
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:69:1
   |
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               2a 00 00 00                                     │ *...
           }

error[E0080]: constructing invalid value: encountered 20, but expected something less or equal to 10, or greater or equal to 30
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:75:1
   |
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               14 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value: encountered 0, but expected something greater or equal to 1
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:78:1
   |
LL | const NULL_FAT_PTR: NonNull<dyn Send> = unsafe {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               00 00 00 00 ╾─alloc32─╼                         │ ....╾──╼
           }

error[E0080]: constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:85:1
   |
LL | const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
   | ^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               ╾a38<imm>─╼                                     │ ╾──╼
           }

error[E0080]: constructing invalid value: encountered an unaligned box (required 2 byte alignment but found 1)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:88:1
   |
LL | const UNALIGNED_BOX: Box<u16> = unsafe { mem::transmute(&[0u8; 4]) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               ╾a42<imm>─╼                                     │ ╾──╼
           }

error[E0080]: constructing invalid value: encountered a null reference
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:91:1
   |
LL | const NULL: &u16 = unsafe { mem::transmute(0usize) };
   | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               00 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value: encountered a null box
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:94:1
   |
LL | const NULL_BOX: Box<u16> = unsafe { mem::transmute(0usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               00 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value: encountered a dangling reference (0x539[noalloc] has no provenance)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:97:1
   |
LL | const USIZE_AS_REF: &'static u8 = unsafe { mem::transmute(1337usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               39 05 00 00                                     │ 9...
           }

error[E0080]: constructing invalid value: encountered a dangling box (0x539[noalloc] has no provenance)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:100:1
   |
LL | const USIZE_AS_BOX: Box<u8> = unsafe { mem::transmute(1337usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               39 05 00 00                                     │ 9...
           }

error[E0080]: constructing invalid value: encountered null pointer, but expected a function pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:103:1
   |
LL | const NULL_FN_PTR: fn() = unsafe { mem::transmute(0usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               00 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value: encountered 0xd[noalloc], but expected a function pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:105:1
   |
LL | const DANGLING_FN_PTR: fn() = unsafe { mem::transmute(13usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               0d 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value: encountered alloc58<imm>, but expected a function pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:107:1
   |
LL | const DATA_FN_PTR: fn() = unsafe { mem::transmute(&13) };
   | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               ╾a58<imm>─╼                                     │ ╾──╼
           }

error[E0080]: constructing invalid value: encountered a reference pointing to uninhabited type Bar
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:113:1
   |
LL | const BAD_BAD_REF: &Bar = unsafe { mem::transmute(1usize) };
   | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               01 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:137:1
   |
LL | const STR_TOO_LONG: &str = unsafe { mem::transmute((&42u8, 999usize)) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a64<imm>─╼ e7 03 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value at .0: encountered invalid reference metadata: slice is bigger than largest supported object
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:139:1
   |
LL | const NESTED_STR_MUCH_TOO_LONG: (&str,) = (unsafe { mem::transmute((&42, usize::MAX)) },);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a69<imm>─╼ ff ff ff ff                         │ ╾──╼....
           }

error[E0080]: constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:141:1
   |
LL | const MY_STR_MUCH_TOO_LONG: &MyStr = unsafe { mem::transmute((&42u8, usize::MAX)) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a75<imm>─╼ ff ff ff ff                         │ ╾──╼....
           }

error[E0080]: constructing invalid value at .<deref>: encountered uninitialized memory, but expected a string
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:144:1
   |
LL | const STR_NO_INIT: &str = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
   | ^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a81<imm>─╼ 01 00 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value at .<deref>.0: encountered uninitialized memory, but expected a string
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:146:1
   |
LL | const MYSTR_NO_INIT: &MyStr = unsafe { mem::transmute::<&[_], _>(&[MaybeUninit::<u8> { uninit: () }]) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a86<imm>─╼ 01 00 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value at .<deref>.0: encountered a pointer, but expected a string
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:148:1
   |
LL | const MYSTR_NO_INIT_ISSUE83182: &MyStr = unsafe { mem::transmute::<&[_], _>(&[&()]) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = help: this code performed an operation that depends on the underlying bytes representing a pointer
   = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
   = 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) {
               ╾a91<imm>─╼ 01 00 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value: encountered a dangling reference (going beyond the bounds of its allocation)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:152:1
   |
LL | const SLICE_TOO_LONG: &[u8] = unsafe { mem::transmute((&42u8, 999usize)) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a95<imm>─╼ e7 03 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value: encountered invalid reference metadata: slice is bigger than largest supported object
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:154:1
   |
LL | const SLICE_TOO_LONG_OVERFLOW: &[u32] = unsafe { mem::transmute((&42u32, isize::MAX)) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a101<imm>╼ ff ff ff 7f                         │ ╾──╼....
           }

error[E0080]: constructing invalid value: encountered a dangling box (going beyond the bounds of its allocation)
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:157:1
   |
LL | const SLICE_TOO_LONG_BOX: Box<[u8]> = unsafe { mem::transmute((&42u8, 999usize)) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a106<imm>╼ e7 03 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value at .<deref>[0]: encountered 0x03, but expected a boolean
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:160:1
   |
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               ╾a112<imm>╼                                     │ ╾──╼
           }

note: erroneous constant encountered
  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:160:40
   |
LL | const SLICE_CONTENT_INVALID: &[bool] = &[unsafe { mem::transmute(3u8) }];
   |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0080]: constructing invalid value at .<deref>.0: encountered 0x03, but expected a boolean
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:164:1
   |
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               ╾a117<imm>╼                                     │ ╾──╼
           }

note: erroneous constant encountered
  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:164:42
   |
LL | const MYSLICE_PREFIX_BAD: &MySliceBool = &MySlice(unsafe { mem::transmute(3u8) }, [false]);
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0080]: constructing invalid value at .<deref>.1[0]: encountered 0x03, but expected a boolean
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:167:1
   |
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               ╾a122<imm>╼                                     │ ╾──╼
           }

note: erroneous constant encountered
  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:167:42
   |
LL | const MYSLICE_SUFFIX_BAD: &MySliceBool = &MySlice(true, [unsafe { mem::transmute(3u8) }]);
   |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0080]: constructing invalid value at .0: encountered alloc127<imm>, but expected a vtable pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:171:1
   |
LL | const TRAIT_OBJ_SHORT_VTABLE_1: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u8))) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a125<imm>╼ ╾a127<imm>╼                         │ ╾──╼╾──╼
           }

error[E0080]: constructing invalid value at .0: encountered alloc135<imm>, but expected a vtable pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:174:1
   |
LL | const TRAIT_OBJ_SHORT_VTABLE_2: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &3u64))) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a133<imm>╼ ╾a135<imm>╼                         │ ╾──╼╾──╼
           }

error[E0080]: constructing invalid value at .0: encountered 0x4[noalloc], but expected a vtable pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:177:1
   |
LL | const TRAIT_OBJ_INT_VTABLE: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, 4usize))) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a141<imm>╼ 04 00 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value at .0: encountered alloc150<imm>, but expected a vtable pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:179:1
   |
LL | const TRAIT_OBJ_BAD_DROP_FN_NOT_FN_PTR: W<&dyn Trait> = unsafe { mem::transmute(W((&92u8, &[&42u8; 8]))) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a147<imm>╼ ╾a150<imm>╼                         │ ╾──╼╾──╼
           }

error[E0080]: constructing invalid value at .<deref>.<dyn-downcast>: encountered 0x03, but expected a boolean
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:182:1
   |
LL | const TRAIT_OBJ_CONTENT_INVALID: &dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a156<imm>╼ ╾alloc158─╼                         │ ╾──╼╾──╼
           }

error[E0080]: constructing invalid value: encountered null pointer, but expected a vtable pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:185:1
   |
LL | const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92u8, 0usize)) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a161<imm>╼ 00 00 00 00                         │ ╾──╼....
           }

error[E0080]: constructing invalid value: encountered alloc168<imm>, but expected a vtable pointer
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:187:1
   |
LL | const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) };
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               ╾a166<imm>╼ ╾a168<imm>╼                         │ ╾──╼╾──╼
           }

error[E0080]: constructing invalid value: encountered a reference pointing to uninhabited type [!; 1]
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:191:1
   |
LL | const _: &[!; 1] = unsafe { &*(1_usize as *const [!; 1]) }; //~ ERROR constructing invalid value
   | ^^^^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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: 4, align: 4) {
               01 00 00 00                                     │ ....
           }

error[E0080]: constructing invalid value at .<deref>[0]: encountered a value of the never type `!`
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:192:1
   |
LL | const _: &[!] = unsafe { &*(1_usize as *const [!; 1]) }; //~ ERROR constructing invalid value
   | ^^^^^^^^^^^^^ it is undefined behavior to use this value
   |
   = 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) {
               01 00 00 00 01 00 00 00                         │ ........
           }

error[E0080]: constructing invalid value at .<deref>[0]: encountered a value of the never type `!`
##[error]  --> /checkout/tests/ui/consts/const-eval/raw-bytes.rs:193:1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants