Skip to content

Implement extract_if for BinaryHeap#154317

Open
Nokel81 wants to merge 1 commit intorust-lang:mainfrom
Nokel81:extract-if-binary-heap
Open

Implement extract_if for BinaryHeap#154317
Nokel81 wants to merge 1 commit intorust-lang:mainfrom
Nokel81:extract-if-binary-heap

Conversation

@Nokel81
Copy link
Contributor

@Nokel81 Nokel81 commented Mar 24, 2026

  • Implement using the sort and rebuild on drop method as maintaining the heap invariant during each extraction would cost more on average

resolves #42849

I have seen #104210 and I took away from reading the comments there that this might be accepted if it does the sort-in-place and then rebuild on drop semantics

- Implement using the sort and rebuild on drop method as maintaining the heap invariant during each extraction would cost more on average
@rustbot rustbot added 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. labels Mar 24, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 24, 2026

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
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 7 candidates

@rust-log-analyzer
Copy link
Collaborator

The job aarch64-gnu-llvm-21-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
Executing "/scripts/stage_2_test_set2.sh"
+ /scripts/stage_2_test_set2.sh
PR_CI_JOB set; skipping tidy
+ '[' 1 == 1 ']'
+ echo 'PR_CI_JOB set; skipping tidy'
+ SKIP_TIDY='--skip tidy'
+ ../x.py --stage 2 test --skip tidy --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest
##[group]Building bootstrap
    Finished `dev` profile [unoptimized] target(s) in 0.04s
##[endgroup]
downloading https://static.rust-lang.org/dist/2026-03-05/rustfmt-nightly-aarch64-unknown-linux-gnu.tar.xz
---
    |
127 | mod tests;
    | ^^^^^^^^^^
    |
    = help: to create the module `tests`, create file "alloctests/../alloc/src/collections/binary_heap/extract_if/tests.rs" or "alloctests/../alloc/src/collections/binary_heap/extract_if/tests/mod.rs"
    = note: if there is a `mod tests` elsewhere in the crate already, import it with `use crate::...` instead

error[E0658]: use of unstable library feature `binary_heap_extract_if`
##[error]   --> alloctests/tests/collections/binary_heap.rs:597:21
    |
597 |     let iter = heap.extract_if(|_: &usize| unreachable!("there's nothing to decide on"));
    |                     ^^^^^^^^^^
    |
    = note: see issue #42849 <https://github.com/rust-lang/rust/issues/42849> for more information
    = help: add `#![feature(binary_heap_extract_if)]` to the crate attributes to enable
    = note: this compiler was built on 2026-03-24; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `binary_heap_extract_if`
##[error]   --> alloctests/tests/collections/binary_heap.rs:607:30
    |
607 |     let v: Vec<usize> = heap.extract_if(|_: &usize| true).collect();
    |                              ^^^^^^^^^^
    |
    = note: see issue #42849 <https://github.com/rust-lang/rust/issues/42849> for more information
    = help: add `#![feature(binary_heap_extract_if)]` to the crate attributes to enable
    = note: this compiler was built on 2026-03-24; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `binary_heap_extract_if`
##[error]   --> alloctests/tests/collections/binary_heap.rs:620:26
    |
620 |     let v: Vec<_> = heap.extract_if(|_| true).collect();
    |                          ^^^^^^^^^^
    |
    = note: see issue #42849 <https://github.com/rust-lang/rust/issues/42849> for more information
    = help: add `#![feature(binary_heap_extract_if)]` to the crate attributes to enable
    = note: this compiler was built on 2026-03-24; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `binary_heap_extract_if`
##[error]   --> alloctests/tests/collections/binary_heap.rs:632:26
    |
632 |     let v: Vec<_> = heap.extract_if(|&x| x % 2 == 0).collect();
    |                          ^^^^^^^^^^
    |
    = note: see issue #42849 <https://github.com/rust-lang/rust/issues/42849> for more information
    = help: add `#![feature(binary_heap_extract_if)]` to the crate attributes to enable
    = note: this compiler was built on 2026-03-24; consider upgrading it if it is out of date

error[E0658]: use of unstable library feature `binary_heap_extract_if`
##[error]   --> alloctests/tests/collections/binary_heap.rs:648:15
    |
648 |     drop(heap.extract_if(|&x| x % 2 == 0));
    |               ^^^^^^^^^^
    |
    = note: see issue #42849 <https://github.com/rust-lang/rust/issues/42849> for more information
    = help: add `#![feature(binary_heap_extract_if)]` to the crate attributes to enable
    = note: this compiler was built on 2026-03-24; consider upgrading it if it is out of date
---
[RUSTC-TIMING] allocbenches test:true 7.693
[RUSTC-TIMING] corebenches test:true 8.652
For more information about this error, try `rustc --explain E0658`.
[RUSTC-TIMING] alloctests test:true 9.161
error: could not compile `alloctests` (test "alloctests") due to 5 previous errors
env -u RUSTC_WRAPPER CARGO_ENCODED_RUSTDOCFLAGS="-Csymbol-mangling-version=v0\u{1f}-Zannotate-moves\u{1f}-Zrandomize-layout\u{1f}-Zunstable-options\u{1f}--check-cfg=cfg(bootstrap)\u{1f}-Wrustdoc::invalid_codeblock_attributes\u{1f}--crate-version\u{1f}1.96.0-nightly\t(d6a294dfb\t2026-03-24)" CARGO_ENCODED_RUSTFLAGS="-Csymbol-mangling-version=v0\u{1f}-Zannotate-moves\u{1f}-Zrandomize-layout\u{1f}-Zunstable-options\u{1f}--check-cfg=cfg(bootstrap)\u{1f}-Zmacro-backtrace\u{1f}-Csplit-debuginfo=off\u{1f}-Clink-arg=-L/usr/lib/llvm-21/lib\u{1f}-Cllvm-args=-import-instr-limit=10\u{1f}-Clink-args=-Wl,-z,origin\u{1f}-Clink-args=-Wl,-rpath,$ORIGIN/../lib\u{1f}--cap-lints=allow\u{1f}--cfg\u{1f}randomized_layouts" RUSTC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustc-clif" RUSTDOC="/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/dist/rustdoc-clif" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo" "test" "--manifest-path" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/sysroot_tests/Cargo.toml" "--target-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif/build/sysroot_tests_target" "--locked" "--target" "aarch64-unknown-linux-gnu" "-p" "coretests" "-p" "alloctests" "--tests" "--" "-q" exited with status ExitStatus(unix_wait_status(25856))
Bootstrap failed while executing `--stage 2 test --skip tidy --skip tests --skip coverage-map --skip coverage-run --skip library --skip tidyselftest`
Command `/checkout/obj/build/aarch64-unknown-linux-gnu/stage0/bin/cargo run -Zwarnings --target aarch64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout --locked --color=always --profile=release --manifest-path /checkout/compiler/rustc_codegen_cranelift/build_system/Cargo.toml -- test --download-dir /checkout/obj/build/cg_clif_download --out-dir /checkout/obj/build/aarch64-unknown-linux-gnu/stage2-codegen/cg_clif --no-unstable-features --use-backend cranelift --sysroot llvm --skip-test testsuite.extended_sysroot [workdir=/checkout/compiler/rustc_codegen_cranelift]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/test.rs:3909:25
Executed at: src/bootstrap/src/core/build_steps/test.rs:3954:26

--- BACKTRACE vvv
   0: std::backtrace_rs::backtrace::libunwind::trace
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1: std::backtrace_rs::backtrace::trace_unsynchronized::<<std::backtrace::Backtrace>::create::{closure#0}>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2: <std::backtrace::Backtrace>::create
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/backtrace.rs:331:13
   3: <bootstrap::utils::exec::DeferredCommand>::finish_process
             at /checkout/src/bootstrap/src/utils/exec.rs:939:17
   4: <bootstrap::utils::exec::DeferredCommand>::wait_for_output::<&bootstrap::utils::exec::ExecutionContext>
             at /checkout/src/bootstrap/src/utils/exec.rs:831:21
   5: <bootstrap::utils::exec::ExecutionContext>::run
             at /checkout/src/bootstrap/src/utils/exec.rs:741:45
   6: <bootstrap::utils::exec::BootstrapCommand>::run::<&bootstrap::core::builder::Builder>
             at /checkout/src/bootstrap/src/utils/exec.rs:339:27
   7: <bootstrap::core::build_steps::test::CodegenCranelift as bootstrap::core::builder::Step>::run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:3954:26
   8: <bootstrap::core::builder::Builder>::ensure::<bootstrap::core::build_steps::test::CodegenCranelift>
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1579:36
   9: <bootstrap::core::build_steps::test::CodegenCranelift as bootstrap::core::builder::Step>::make_run
             at /checkout/src/bootstrap/src/core/build_steps/test.rs:3895:17
  10: <bootstrap::core::builder::StepDescription>::maybe_run
             at /checkout/src/bootstrap/src/core/builder/mod.rs:476:13
  11: bootstrap::core::builder::cli_paths::match_paths_to_steps_and_run
             at /checkout/src/bootstrap/src/core/builder/cli_paths.rs:141:22
  12: <bootstrap::core::builder::Builder>::run_step_descriptions
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1122:9
  13: <bootstrap::core::builder::Builder>::execute_cli
             at /checkout/src/bootstrap/src/core/builder/mod.rs:1101:14
  14: <bootstrap::Build>::build
             at /checkout/src/bootstrap/src/lib.rs:799:25
  15: bootstrap::main
             at /checkout/src/bootstrap/src/bin/main.rs:130:11
  16: <fn() as core::ops::function::FnOnce<()>>::call_once
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/ops/function.rs:250:5
  17: std::sys::backtrace::__rust_begin_short_backtrace::<fn(), ()>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/sys/backtrace.rs:166:18
  18: std::rt::lang_start::<()>::{closure#0}
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/rt.rs:206:18
  19: <&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync as core::ops::function::FnOnce<()>>::call_once
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/core/src/ops/function.rs:287:21
  20: std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:581:40
  21: std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:544:19
  22: std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::panic::unwind_safe::RefUnwindSafe + core::marker::Sync, i32>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panic.rs:359:14
  23: std::rt::lang_start_internal::{closure#0}
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/rt.rs:175:24
  24: std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/ad726b5063362ec9897ef3d67452fc5606ee70fa/library/std/src/panicking.rs:581:40
---
  31: __libc_start_main
  32: _start


Command has failed. Rerun with -v to see more details.
Build completed unsuccessfully in 0:21:04
  local time: Tue Mar 24 16:06:49 UTC 2026
  network time: Tue, 24 Mar 2026 16:06:50 GMT
##[error]Process completed with exit code 1.
##[group]Run echo "disk usage:"

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.

Add drain_filter for BinaryHeap

4 participants