Skip to content

Commit 6ee4265

Browse files
committed
Auto merge of #104455 - the8472:dont-drain-on-drop, r=Amanieu
Don't drain-on-drop in DrainFilter impls of various collections. This removes drain-on-drop behavior from various unstable DrainFilter impls (not yet for HashSet/Map) because that behavior [is problematic](#43244 (comment)) (because it can lead to panic-in-drop when user closures panic) and may become forbidden if [this draft RFC passes](rust-lang/rfcs#3288). closes #101122 [ACP](rust-lang/libs-team#136) affected tracking issues * #43244 * #70530 * #59618 Related hashbrown update: rust-lang/hashbrown#374
2 parents 8c74a5d + 0c5f442 commit 6ee4265

File tree

43 files changed

+449
-577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+449
-577
lines changed

Cargo.lock

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ dependencies = [
6565
"rand_xorshift",
6666
]
6767

68+
[[package]]
69+
name = "allocator-api2"
70+
version = "0.2.14"
71+
source = "registry+https://github.com/rust-lang/crates.io-index"
72+
checksum = "c4f263788a35611fba42eb41ff811c5d0360c58b97402570312a350736e2542e"
73+
6874
[[package]]
6975
name = "ammonia"
7076
version = "3.2.0"
@@ -1522,6 +1528,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
15221528
checksum = "33ff8ae62cd3a9102e5637afc8452c55acf3844001bd5374e0b0bd7b6616c038"
15231529
dependencies = [
15241530
"ahash 0.8.2",
1531+
]
1532+
1533+
[[package]]
1534+
name = "hashbrown"
1535+
version = "0.14.0"
1536+
source = "registry+https://github.com/rust-lang/crates.io-index"
1537+
checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a"
1538+
dependencies = [
1539+
"allocator-api2",
15251540
"compiler_builtins",
15261541
"rustc-std-workspace-alloc",
15271542
"rustc-std-workspace-core",
@@ -4633,7 +4648,7 @@ dependencies = [
46334648
"core",
46344649
"dlmalloc",
46354650
"fortanix-sgx-abi",
4636-
"hashbrown 0.13.1",
4651+
"hashbrown 0.14.0",
46374652
"hermit-abi 0.3.0",
46384653
"libc",
46394654
"miniz_oxide",

compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
66
#![feature(array_windows)]
7-
#![feature(drain_filter)]
7+
#![feature(extract_if)]
88
#![feature(if_let_guard)]
99
#![feature(let_chains)]
1010
#![feature(never_type)]
@@ -1399,7 +1399,7 @@ impl HandlerInner {
13991399
!self.emitted_diagnostics.insert(diagnostic_hash)
14001400
};
14011401

1402-
diagnostic.children.drain_filter(already_emitted_sub).for_each(|_| {});
1402+
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {});
14031403

14041404
self.emitter.emit_diagnostic(diagnostic);
14051405
if diagnostic.is_error() {

compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ This API is completely unstable and subject to change.
5959
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
6060
#![feature(box_patterns)]
6161
#![feature(control_flow_enum)]
62-
#![feature(drain_filter)]
63-
#![feature(hash_drain_filter)]
6462
#![feature(if_let_guard)]
6563
#![feature(is_sorted)]
6664
#![feature(iter_intersperse)]

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -753,20 +753,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
753753
return;
754754
}
755755

756-
errors.drain_filter(|error| {
756+
errors.retain(|error| {
757757
let Error::Invalid(
758758
provided_idx,
759759
expected_idx,
760760
Compatibility::Incompatible(Some(e)),
761-
) = error else { return false };
761+
) = error else { return true };
762762
let (provided_ty, provided_span) = provided_arg_tys[*provided_idx];
763763
let trace =
764764
mk_trace(provided_span, formal_and_expected_inputs[*expected_idx], provided_ty);
765765
if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308) {
766766
self.err_ctxt().report_and_explain_type_error(trace, *e).emit();
767-
return true;
767+
return false;
768768
}
769-
false
769+
true
770770
});
771771

772772
// We're done if we found errors, but we already emitted them.

compiler/rustc_hir_typeck/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#![feature(box_patterns)]
66
#![feature(min_specialization)]
77
#![feature(control_flow_enum)]
8-
#![feature(drain_filter)]
98
#![feature(option_as_slice)]
109
#![allow(rustc::potential_query_instability)]
1110
#![recursion_limit = "256"]

compiler/rustc_metadata/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
22
#![feature(decl_macro)]
3-
#![feature(drain_filter)]
3+
#![feature(extract_if)]
44
#![feature(generators)]
55
#![feature(iter_from_generator)]
66
#![feature(let_chains)]

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ impl<'tcx> Collector<'tcx> {
425425
// can move them to the end of the list below.
426426
let mut existing = self
427427
.libs
428-
.drain_filter(|lib| {
428+
.extract_if(|lib| {
429429
if lib.name.as_str() == passed_lib.name {
430430
// FIXME: This whole logic is questionable, whether modifiers are
431431
// involved or not, library reordering and kind overriding without

compiler/rustc_middle/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
#![feature(try_reserve_kind)]
5555
#![feature(nonzero_ops)]
5656
#![feature(decl_macro)]
57-
#![feature(drain_filter)]
57+
#![feature(extract_if)]
5858
#![feature(intra_doc_pointers)]
5959
#![feature(yeet_expr)]
6060
#![feature(result_option_inspect)]

compiler/rustc_middle/src/ty/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn suggest_constraining_type_params<'a>(
237237

238238
{
239239
let mut sized_constraints =
240-
constraints.drain_filter(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
240+
constraints.extract_if(|(_, def_id)| *def_id == tcx.lang_items().sized_trait());
241241
if let Some((constraint, def_id)) = sized_constraints.next() {
242242
applicability = Applicability::MaybeIncorrect;
243243

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![deny(rustc::untranslatable_diagnostic)]
33
#![deny(rustc::diagnostic_outside_of_impl)]
44
#![feature(box_patterns)]
5-
#![feature(drain_filter)]
65
#![feature(is_sorted)]
76
#![feature(let_chains)]
87
#![feature(map_try_insert)]

0 commit comments

Comments
 (0)