Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constification of BinaryHeap construction #112353

Open
terrarier2111 opened this issue Jun 6, 2023 · 5 comments
Open

Constification of BinaryHeap construction #112353

terrarier2111 opened this issue Jun 6, 2023 · 5 comments
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@terrarier2111
Copy link
Contributor

Is there any reason this isn't const yet? This should only depend on vec's construction being const which it is.

@Nilstrieb Nilstrieb added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 7, 2023
@est31
Copy link
Member

est31 commented Jun 8, 2023

All the other collections already have const constructors (except for the ones for which it's hard, cc #112354). So I think it makes a lot of sense to make this const as well.

There was an entire ACP for VecDequeue::new(). I don't know if one is needed for BinaryHeap as well. On the other hand, the function became instantly const-stable, there was no period where it was unstably const, see #105072.

@tsemo4917
Copy link

impl<T: Ord> BinaryHeap<T> {
    pub fn new() -> BinaryHeap<T> {
        BinaryHeap { data: vec![] }
    }
}

BinaryHeap constructor is only depends on Vec constructor, and Vec::new() has been a const function since 1.39.0.

Constification of BinaryHeap constructor will be helpful when a static variable is of the BinaryHeap type.

@dtolnay

@dtolnay
Copy link
Member

dtolnay commented Oct 19, 2023

Please send a PR.

@Coekjan
Copy link
Contributor

Coekjan commented Oct 28, 2023

I also met this issue and I am trying to address it with #117316

@est31 est31 added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 28, 2023
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Oct 28, 2023
…tor, r=dtolnay

Mark constructor of `BinaryHeap` as const fn

rust-lang#112353
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Oct 29, 2023
…tor, r=dtolnay

Mark constructor of `BinaryHeap` as const fn

rust-lang#112353
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 29, 2023
Rollup merge of rust-lang#117316 - Coekjan:const-binary-heap-constructor, r=dtolnay

Mark constructor of `BinaryHeap` as const fn

rust-lang#112353
@Coekjan
Copy link
Contributor

Coekjan commented Oct 29, 2023

The feature const_binary_heap_constructor was added to nightly.

Due to the unstable feature (allocator_api, issue: #32838 ), this feature is not able to be stablized now.

@est31 est31 removed the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Oct 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants