Open
Description
let a = const { [ "asdf".as_ptr() ].as_ptr() }; // error
let a = const { [const { "asdf".as_ptr() }].as_ptr() }; // okay
I think either both of these should pass, or both of these should error.
However, only the first line results in:
error: encountered dangling pointer in final value of constant
Fwiw, inlining as_ptr()
results in both lines being accepted:
let a = const { [ "asdf" as *const str as *const u8 ].as_ptr() }; // okay
let a = const { [const { "asdf" as *const str as *const u8 }].as_ptr() }; // okay
Meta
rustc --version --verbose
:
rustc 1.86.0-nightly (a567209da 2025-02-13)
binary: rustc
commit-hash: a567209daab72b7ea59eac533278064396bb0534
commit-date: 2025-02-13
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
Metadata
Metadata
Assignees
Labels
Area: Documentation for any part of the project, including the compiler, standard library, and toolsCategory: Discussion or questions that doesn't represent real issues.Inline constants (aka: const blocks, const expressions, anonymous constants)Relevant to the compiler team, which will review and decide on the PR/issue.