From d19c9107b263b33a7c025e067c1dc1a9946e7cc7 Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Sat, 13 Aug 2022 10:30:58 -0700 Subject: [PATCH] swap_remove rather than removing in place --- crates/compiler/can/src/module.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/compiler/can/src/module.rs b/crates/compiler/can/src/module.rs index 99c9469976..b0e3cab3d4 100644 --- a/crates/compiler/can/src/module.rs +++ b/crates/compiler/can/src/module.rs @@ -988,9 +988,12 @@ fn fix_values_captured_in_closure_expr( // initially `outer` captures [inner], but this is then replaced with just [x]. let (captured_symbol, _) = captured_symbols[i]; if let Some(captures) = closure_captures.get(&captured_symbol) { - captured_symbols.remove(i); + debug_assert!(!captures.is_empty()); + captured_symbols.swap_remove(i); captured_symbols.extend(captures); - // Don't advance because the next capture was shifted down. + // Jump two, because the next element is now one of the newly-added captures, + // which we don't need to check. + i += 2; } else { i += 1; }