Fix bug in removing used parameters

The current implementation removes parameters if they are used - however, it only removes the first instance, and removes instances by index. However, when multiple items are being removed, following indices must be decremented by 1 to account for previously removed items.
This commit is contained in:
philippeitis
2022-10-10 17:13:38 -07:00
parent fa1c5a84ec
commit d611a319de

View File

@@ -670,15 +670,8 @@ else {
}
## Remove all used parameters
{
let mut indices_for_removal: Vec<usize> = Vec::with_capacity(${len(replacements)});
for param_name in [${', '.join(reversed(['"%s"' % r[1] for r in replacements]))}].iter() {
if let Some(index) = params.iter().position(|t| &t.0 == param_name) {
indices_for_removal.push(index);
}
}
for &index in indices_for_removal.iter() {
params.remove(index);
}
let to_remove = [${', '.join(reversed(['"%s"' % r[1] for r in replacements]))}];
params.retain(|(n, _)| !to_remove.contains(n));
}
% endif