Skip to content

constify vec![1, 2, 3] macro#155795

Open
Lars-Schumann wants to merge 1 commit into
rust-lang:mainfrom
Lars-Schumann:const-vec-macro
Open

constify vec![1, 2, 3] macro#155795
Lars-Schumann wants to merge 1 commit into
rust-lang:mainfrom
Lars-Schumann:const-vec-macro

Conversation

@Lars-Schumann

@Lars-Schumann Lars-Schumann commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

Tracking issues:
const_heap: #79597

makes all the parts needed for non-empty vec![] macros const:

alloc::boxed::box_assume_init_into_vec_unsafe
alloc::boxed::Box::assume_init
alloc::boxed::Box::into_raw_with_allocator
alloc::boxed::Box::new_uninit
alloc::slice::[T]::into_vec

Note that this does not allow for the use of the vec![(); 4] arm of this macro to be used in const-eval, since that uses specialization (spec and const traits don't really like each other so I didn't want to touch any of that in this).

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Apr 25, 2026
@rust-log-analyzer

This comment has been minimized.

@Lars-Schumann
Lars-Schumann marked this pull request as ready for review July 14, 2026 13:13
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 14, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 14, 2026
@rustbot

rustbot commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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: compiler
  • compiler expanded to 75 candidates
  • Random selection from 21 candidates

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Lars-Schumann

Copy link
Copy Markdown
Contributor Author

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

@rustbot rustbot assigned lcnr and unassigned TaKO8Ki Jul 15, 2026
@lcnr

lcnr commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

r? wg-const-eval

@rustbot rustbot assigned oli-obk and unassigned lcnr Jul 21, 2026
Comment thread tests/ui/consts/min_const_fn/bad_const_fn_body_ice.rs Outdated
static STATIC11: Vec<MyOwned> = vec![MyOwned];
static STATIC11: Vec<MyOwned> = non_const(MyOwned);
//~^ ERROR cannot call non-const function
//~| ERROR cannot call non-const

@oli-obk oli-obk Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Keep using the vec macro and just fix up the diagnostics. Can even enable the feature

View changes since the review

@Lars-Schumann Lars-Schumann Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, many of these have no more errors now since a Vec of ZSTs doesn't allocate.
If we would rather keep these failure cases, I can make MyOwned non-ZST, or introduce cases with a separate non-ZST type.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2026
@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Lars-Schumann

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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