-
-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Open
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.F-const_heap`#[feature(const_heap)]``#[feature(const_heap)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
I tried this code:
#![feature(const_heap)]
fn main() {
const {
let mut inner_vec = Vec::<i32>::new();
let inner_slice = inner_vec.const_make_global();
}
}I expected const_make_global() to just return an empty 'static slice
Instead, it gave me this error:
error[E0080]: pointer not dereferenceable: pointer must point to some allocation, but got 0x4[noalloc] which is a dangling pointer (it has no provenance)
--> src\main.rs:6:27
|
6 | let inner_slice = inner_vec.const_make_global();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::{constant#0}` failed inside this call
|
note: inside `Vec::<i32>::const_make_global`
--> C:\Users\theiz\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\alloc\src\vec\mod.rs:897:18
|
897 | unsafe { core::intrinsics::const_make_global(self.as_mut_ptr().cast()) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the failure occurred here
But this code:
#![feature(const_heap)]
#![feature(const_trait_impl)]
fn main() {
const {
let mut inner_vec = Vec::<i32>::new();
inner_vec.push(4);
let inner_slice = inner_vec.const_make_global();
}
}works just fine
Meta
rustc --version --verbose:
rustc 1.95.0-nightly (859951e3c 2026-02-24)
binary: rustc
commit-hash: 859951e3c7c9d0322c39bad49221937455bdffcd
commit-date: 2026-02-24
host: x86_64-pc-windows-msvc
release: 1.95.0-nightly
LLVM version: 22.1.0
I am assuming it was because the Vec was empty
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`C-bugCategory: This is a bug.Category: This is a bug.F-const_heap`#[feature(const_heap)]``#[feature(const_heap)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.