diff --git a/Cargo.lock b/Cargo.lock index 454ec90b9afd2..1bfa8c5a5570f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1968,9 +1968,9 @@ checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" [[package]] name = "indexmap" -version = "2.0.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "cf2a4f498956c7723dc280afc6a37d0dec50b39a29e232c6187ce4503703e8c2" dependencies = [ "equivalent", "hashbrown", diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index ea48e78509b7c..379e9ca0058c9 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -2473,7 +2473,7 @@ mod error { &mut self, span: Span, ) -> Option<(DiagnosticBuilder<'tcx>, usize)> { - self.errors.buffered_mut_errors.remove(&span) + self.errors.buffered_mut_errors.swap_remove(&span) } pub fn buffer_mut_error(&mut self, span: Span, t: DiagnosticBuilder<'tcx>, count: usize) { diff --git a/compiler/rustc_borrowck/src/used_muts.rs b/compiler/rustc_borrowck/src/used_muts.rs index 6ac8e1ba7156a..3a27b280ef4e8 100644 --- a/compiler/rustc_borrowck/src/used_muts.rs +++ b/compiler/rustc_borrowck/src/used_muts.rs @@ -60,7 +60,7 @@ impl GatherUsedMutsVisitor<'_, '_, '_> { // be those that were never initialized - we will consider those as being used as // they will either have been removed by unreachable code optimizations; or linted // as unused variables. - self.never_initialized_mut_locals.remove(&into.local); + self.never_initialized_mut_locals.swap_remove(&into.local); } } diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 3694e41a0e089..845f0dcbc04e9 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -104,7 +104,7 @@ fn asm_target_features(tcx: TyCtxt<'_>, did: DefId) -> &FxIndexSet { match attrs.instruction_set { None => {} Some(InstructionSetAttr::ArmA32) => { - target_features.remove(&sym::thumb_mode); + target_features.swap_remove(&sym::thumb_mode); } Some(InstructionSetAttr::ArmT32) => { target_features.insert(sym::thumb_mode); diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index 274ff25fb9b58..f300b901b4d8f 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -125,7 +125,7 @@ impl interpret::AllocMap for FxIndexMap { where K: Borrow, { - FxIndexMap::remove(self, k) + FxIndexMap::swap_remove(self, k) } #[inline(always)] diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 751fbfacaad00..31763935e8fe9 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -50,7 +50,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, T, M: CompileTimeMachine<'mir, 'tcx, T>>( ) -> Result<(), ()> { trace!("intern_shallow {:?}", alloc_id); // remove allocation - let Some((_kind, mut alloc)) = ecx.memory.alloc_map.remove(&alloc_id) else { + let Some((_kind, mut alloc)) = ecx.memory.alloc_map.swap_remove(&alloc_id) else { return Err(()); }; // Set allocation mutability as appropriate. This is used by LLVM to put things into diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 23efdaea0ebb8..9c61e0a5c1c2b 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -1640,7 +1640,7 @@ impl HumanEmitter { let mut to_add = FxHashMap::default(); for (depth, style) in depths { - if multilines.remove(&depth).is_none() { + if multilines.swap_remove(&depth).is_none() { to_add.insert(depth, style); } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index ee831c4f560c0..e477c0090764e 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -692,7 +692,7 @@ impl DiagCtxt { pub fn steal_diagnostic(&self, span: Span, key: StashKey) -> Option> { let mut inner = self.inner.borrow_mut(); let key = (span.with_parent(None), key); - let diag = inner.stashed_diagnostics.remove(&key)?; + let diag = inner.stashed_diagnostics.swap_remove(&key)?; if diag.is_error() { if diag.is_lint.is_some() { inner.lint_err_count -= 1; diff --git a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs index 5f35f75c77b0f..89744f8198768 100644 --- a/compiler/rustc_hir_analysis/src/astconv/object_safety.rs +++ b/compiler/rustc_hir_analysis/src/astconv/object_safety.rs @@ -218,7 +218,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { for def_ids in associated_types.values_mut() { for (projection_bound, span) in &projection_bounds { let def_id = projection_bound.projection_def_id(); - def_ids.remove(&def_id); + def_ids.swap_remove(&def_id); if tcx.generics_require_sized_self(def_id) { tcx.emit_node_span_lint( UNUSED_ASSOCIATED_TYPE_BOUNDS, diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index a857e01f4fa7b..3a9fa0a0a1db7 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -1872,7 +1872,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { lifetime_ref: &'tcx hir::Lifetime, bad_def: ResolvedArg, ) { - let old_value = self.map.defs.remove(&lifetime_ref.hir_id); + let old_value = self.map.defs.swap_remove(&lifetime_ref.hir_id); assert_eq!(old_value, Some(bad_def)); } } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index c6b9197d0e986..245e19e302f56 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1549,7 +1549,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ctxt = { let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); debug_assert!(enclosing_breakables.stack.len() == index + 1); - enclosing_breakables.by_id.remove(&id).expect("missing breakable context"); + enclosing_breakables.by_id.swap_remove(&id).expect("missing breakable context"); enclosing_breakables.stack.pop().expect("missing breakable context") }; (ctxt, result) diff --git a/compiler/rustc_infer/src/infer/opaque_types/table.rs b/compiler/rustc_infer/src/infer/opaque_types/table.rs index 6a684dba8dec5..0c2c7542565cf 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/table.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/table.rs @@ -20,7 +20,7 @@ impl<'tcx> OpaqueTypeStorage<'tcx> { if let Some(idx) = idx { self.opaque_types.get_mut(&key).unwrap().hidden_type = idx; } else { - match self.opaque_types.remove(&key) { + match self.opaque_types.swap_remove(&key) { None => bug!("reverted opaque type inference that was never registered: {:?}", key), Some(_) => {} } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index eed35326c4501..a44fdea8cab8a 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -712,7 +712,7 @@ impl LintBuffer { } pub fn take(&mut self, id: NodeId) -> Vec { - self.map.remove(&id).unwrap_or_default() + self.map.swap_remove(&id).unwrap_or_default() } pub fn buffer_lint( diff --git a/compiler/rustc_mir_transform/src/dest_prop.rs b/compiler/rustc_mir_transform/src/dest_prop.rs index 0ac4ab61d409c..aa60df5fcc02c 100644 --- a/compiler/rustc_mir_transform/src/dest_prop.rs +++ b/compiler/rustc_mir_transform/src/dest_prop.rs @@ -398,7 +398,7 @@ impl<'alloc> Candidates<'alloc> { let candidates = entry.get_mut(); Self::vec_filter_candidates(p, candidates, f, at); if candidates.len() == 0 { - entry.remove(); + entry.swap_remove(); } } diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index c1fe8c2133b75..3e1aef8b37055 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -957,8 +957,8 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { // available as we'd like it to be. // FIXME: only remove `libc` when `stdbuild` is active. // FIXME: remove special casing for `test`. - remaining_lib_features.remove(&sym::libc); - remaining_lib_features.remove(&sym::test); + remaining_lib_features.swap_remove(&sym::libc); + remaining_lib_features.swap_remove(&sym::test); /// For each feature in `defined_features`.. /// @@ -996,7 +996,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) { unnecessary_stable_feature_lint(tcx, *span, feature, since); } } - remaining_lib_features.remove(&feature); + remaining_lib_features.swap_remove(&feature); // `feature` is the feature doing the implying, but `implied_by` is the feature with // the attribute that establishes this relationship. `implied_by` is guaranteed to be a diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs index fc72d76c3a797..0e3125e6f5bd9 100644 --- a/compiler/rustc_resolve/src/check_unused.rs +++ b/compiler/rustc_resolve/src/check_unused.rs @@ -92,7 +92,7 @@ impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> { } else { // This trait import is definitely used, in a way other than // method resolution. - self.r.maybe_unused_trait_imports.remove(&def_id); + self.r.maybe_unused_trait_imports.swap_remove(&def_id); if let Some(i) = self.unused_imports.get_mut(&self.base_id) { i.unused.remove(&id); } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index c43447585746a..43a884de7f366 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -523,13 +523,13 @@ impl<'tcx> AutoTraitFinder<'tcx> { if let Entry::Occupied(v) = vid_map.entry(*smaller) { let smaller_deps = v.into_mut(); smaller_deps.larger.insert(*larger); - smaller_deps.larger.remove(&target); + smaller_deps.larger.swap_remove(&target); } if let Entry::Occupied(v) = vid_map.entry(*larger) { let larger_deps = v.into_mut(); larger_deps.smaller.insert(*smaller); - larger_deps.smaller.remove(&target); + larger_deps.smaller.swap_remove(&target); } } (&RegionTarget::RegionVid(v1), &RegionTarget::Region(r1)) => { @@ -542,13 +542,13 @@ impl<'tcx> AutoTraitFinder<'tcx> { if let Entry::Occupied(v) = vid_map.entry(*smaller) { let smaller_deps = v.into_mut(); smaller_deps.larger.insert(*larger); - smaller_deps.larger.remove(&target); + smaller_deps.larger.swap_remove(&target); } if let Entry::Occupied(v) = vid_map.entry(*larger) { let larger_deps = v.into_mut(); larger_deps.smaller.insert(*smaller); - larger_deps.smaller.remove(&target); + larger_deps.smaller.swap_remove(&target); } } } diff --git a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs index bfc6937a3eb39..7f34ab006e2e9 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/mod.rs @@ -516,7 +516,7 @@ pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Opti for (p, _) in predicates { if let Some(poly_trait_ref) = p.as_trait_clause() { if Some(poly_trait_ref.def_id()) == sized_trait { - types_without_default_bounds.remove(&poly_trait_ref.self_ty().skip_binder()); + types_without_default_bounds.swap_remove(&poly_trait_ref.self_ty().skip_binder()); continue; } }