Files
rust/library/core/src
bors 74fd7516da Auto merge of #147893 - fee1-dead-contrib:constheapheapheap, r=oli-obk
`Vec::push` in consts MVP

Example:

```rust
const X: &'static [u32] = {
    let mut v = Vec::with_capacity(6);
    let mut x = 1;
    while x < 42 {
        v.push(x);
        x *= 2;
    }
    assert!(v.len() == 6);
    v.const_make_global()
};

assert_eq!([1, 2, 4, 8, 16, 32], X);
```

Oh this is fun...

* We split out the implementation of `Global` such that it calls `intrinsics::const_allocate` and `intrinsics::const_deallocate` during compile time. This is achieved using `const_eval_select`
* This allows us to `impl const Allocator for Global`
* We then constify everything necessary for `Vec::with_capacity` and `Vec::push`.
* Added `Vec::const_make_global` to leak and intern the final value via `intrinsics::const_make_global`. If we see any pointer in the final value of a `const` that did not call `const_make_global`, we error as implemented in rust-lang/rust#143595.

r? `@rust-lang/wg-const-eval`

To-do for me:
* [x] Assess the rustdoc impact of additional bounds in the method
* [x] ~~Increase test coverage~~ I think this is enough for an unstable feature.
2026-01-06 11:39:17 +00:00
..
2026-01-01 19:17:11 -05:00
2025-11-11 23:46:10 +03:00
fix
2025-11-27 17:55:34 +07:00
2025-12-19 15:04:30 -08:00
2025-09-01 21:38:26 -04:00
2025-12-23 18:16:59 +00:00
2025-12-15 13:02:47 -08:00
2025-05-12 15:33:30 +02:00
2025-10-20 12:20:15 -06:00
2025-12-23 10:06:23 +00:00
2025-10-16 03:04:51 +01:00
2025-09-07 21:16:35 -07:00
2025-06-15 22:08:41 +02:00
2025-12-15 18:57:33 +08:00
2025-11-12 14:33:41 +01:00
2025-11-09 04:17:15 +07:00