- Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-opsemRelevant to the opsem teamRelevant to the opsem team
Description
I tried this code:
const fn test() -> &'static [&'static str] { const ITEMS: &[&str] = const { std::slice::from_ref(&[ "hello", "world", ][0]) }; ITEMS } #[inline(never)] pub fn main() { std::hint::black_box(test()); }
I expected to see this happen:
The string world
to be pruned from the final binary.
Instead, this happened:
https://godbolt.org/z/WTM5jz987
The array was not pruned at all.
Meta
rustc --version --verbose
:
godbolt rustc nightly.
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing suchT-opsemRelevant to the opsem teamRelevant to the opsem team