Skip to content

alloc: vec! macro with custom allocator support - #164801

Open
janis-bhm wants to merge 2 commits into
rust-lang:mainfrom
janis-bhm:alloc/vec-in-macro
Open

janis-bhm wants to merge 2 commits into
rust-lang:mainfrom
janis-bhm:alloc/vec-in-macro

Conversation

@janis-bhm

@janis-bhm janis-bhm commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

related to allocator_ext #163177

now that allocator_api is stablized and allocator_ext has everything else allocator-y, IMO there exists a gap for constructing vecs with custom allocators like the vec! macro does for Global.

the doc comment has a hidden #!feature(allocator_ext) to use the new arms which implicitly use that feature, there is no additional feature gate currently.

I've added a branch to the mir-opt test for checking that the correct mir is emitted (though I'm not sure i've done it correctly)

zulip discussion

discussion on zulip suggested that possibly a temporary macro with a new name for the new arms makes sense, I havent done that yet.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 23, 2026
@rustbot

rustbot commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 37 candidates
  • Random selection from 6 candidates

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-aarch64-gnu-llvm-22-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [mir-opt] tests/mir-opt/building/write_box_via_move.rs stdout ----
------rustc stdout------------------------------

------rustc stderr------------------------------
error[E0658]: use of unstable library feature `allocator_ext`
##[error]  --> /checkout/tests/mir-opt/building/write_box_via_move.rs:28:5
   |
28 |     vec![in alloc::alloc::Global; 0, 1, 2, 3, 4, 5, 6, 7]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #163177 <https://github.com/rust-lang/rust/issues/163177> for more information
   = help: add `#![feature(allocator_ext)]` to the crate attributes to enable
   = note: this compiler was built on 2026-10-23; consider upgrading it if it is out of date
---
------------------------------------------

error: compilation failed!
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/mir-opt/building/write_box_via_move.rs" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "-O" "-Copt-level=1" "-Zdump-mir=CleanupPostBorrowck | CleanupPostBorrowck" "-Zvalidate-mir" "-Zlint-mir" "-Zdump-mir-exclude-pass-number" "-Zmir-include-spans=false" "--crate-type=rlib" "-Zmir-opt-level=4" "-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals" "-Zdump-mir-dir=/checkout/obj/build/aarch64-unknown-linux-gnu/test/mir-opt/building/write_box_via_move" "--emit" "mir" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/mir-opt/building/write_box_via_move" "-Znext-solver=coherence" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "--edition=2015" "-Zmir-opt-level=0"
stdout: none
--- stderr -------------------------------
error[E0658]: use of unstable library feature `allocator_ext`
##[error]  --> /checkout/tests/mir-opt/building/write_box_via_move.rs:28:5
   |
28 |     vec![in alloc::alloc::Global; 0, 1, 2, 3, 4, 5, 6, 7]
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #163177 <https://github.com/rust-lang/rust/issues/163177> for more information
   = help: add `#![feature(allocator_ext)]` to the crate attributes to enable
   = note: this compiler was built on 2026-10-23; consider upgrading it if it is out of date

@maxdexh maxdexh left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write new unstable wrapper functions instead of calling the existing Vec functions? Some of these are not unstable, and even for those that are, if they get stabilized independently, I don't want us to accidentally stabilize the new match arms.

View changes since this review

() => (
$crate::vec::Vec::new()
);
(in $alloc:expr) => (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to allow a semicolon here, otherwise the empty vector is not a special case of the comma separated syntax.

@tgross35

Copy link
Copy Markdown
Member

As mentioned in the Zulip discussion, please do start with an ACP

@rustbot label +needs-acp

@rustbot rustbot added the needs-acp This change is blocked on the author creating an ACP. label Oct 23, 2026
@jhpratt

jhpratt commented Oct 25, 2026

Copy link
Copy Markdown
Member

@rustbot label -S-waiting-on-review +S-waiting-on-acp

@rustbot rustbot added S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-acp This change is blocked on the author creating an ACP. S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants