Repository: rust
Issue: Promotion rules are surprising and insufficiently documented
Labels: T-compiler,A-docs,C-bug,A-const-eval

The code in question ([playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8e4e28528c2cc66f5e1feae5db9cb636)):

```rust
const S_CONST: &'static [u8] = unsafe {
    std::slice::from_raw_parts(
        std::convert::identity([0]).as_ptr(),
        1,
    )
};

fn main() {
    let s_rt: &'static [u8] = unsafe {
        std::slice::from_raw_parts(
            std::convert::identity([0]).as_ptr(),
            1,
        )
    };
    println!("{s_rt:?}");
    println!("{S_CONST:?}");
}
```

When I run this code under miri, it complains about dangling reference on attempt to print `s_rt`:

<details>

```
error: Undefined Behavior: constructing invalid value: encountered a dangling reference (use-after-free)
    --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2382:1
     |
2382 | fmt_refs! { Debug, Display, Octal, Binary, LowerHex, UpperHex, LowerExp, UpperExp }
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered a dangling reference (use-after-free)
     |
     = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
     = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
     = note: BACKTRACE:
     = note: inside `<&[u8] as std::fmt::Debug>::fmt` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2372:71
     = note: inside `std::fmt::write` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1208:17
     = note: inside `<std::io::StdoutLock<'_> as std::io::Write>::write_fmt` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:1682:15
     = note: inside `<&std::io::Stdout as std::io::Write>::write_fmt` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:716:9
     = note: inside `<std::io::Stdout as std::io::Write>::write_fmt` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:690:9
     = note: inside `std::io::stdio::print_to::<std::io::Stdout>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:1008:21
     = note: inside `std::io::_print` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:1075:5
note: inside `main` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs:136:9
    --> src/main.rs:15:5
     |
15   |     println!("{s_rt:?}");
     |     ^^^^^^^^^^^^^^^^^^^^
     = note: this error originates in the macro `fmt_refs` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
```

</details>

However, if I comment out this line and keep the line which prints `S_CONST`, miri runs this program just fine.

### Meta

I used the latest stable at the moment (1.65.0), but since miri requires nightly toolchain anyway I believe it used latest nightly (2022-12-03 2341517).