Upgraded the toolchain, it seems rustc gets invoked with --check-cfg cfg(default, simd, ...)
, which broke the existing parser code. This is definitely a balance between going overkill on parsing and doing just enough to get by, hopefully there won't be many more breakages like this."
IU3B2YBIUC3YJYN7XV3UND6CONSUX25SYMZD24K4GUS65I3XCPVAC
}
fn count_parens(source: &str) -> i32 {
source.chars().fold(0, |count, character| match character {
'(' => count + 1,
')' => count - 1,
_ => count,
})
}
fn balance_parens<'a>(source: &'a str, iterator: &mut impl Iterator<Item = &'a str>) -> String {
let mut buffer = source.to_string();
// If there are more closing parentheses than opening, there's a bug
// (most likely from this argument parsing code)
let mut open_parens = Self::count_parens(&buffer);
assert!(
open_parens >= 0,
"Got too many closing parentheses while parsing argument: `{source}`"
);
while open_parens > 0 {
let next_chunk = iterator.next().expect(&format!(
"Ran out of arguments while searching for closing parenthesis: `{buffer}`"
));
buffer.push_str(next_chunk);
open_parens += Self::count_parens(next_chunk);
}
buffer
while let Some(chunk) = arg_chunks.next() {
while let Some(initial_chunk) = arg_chunks.next() {
// Need to handle cases such as `--check-cfg cfg(feature, values("default", "simd"))`
// To do this, consume more chunks until the parentheses are balanced
let owned_chunk = Self::balance_parens(initial_chunk, &mut arg_chunks);
let chunk = owned_chunk.as_str();
panic!("Found multiple unexpected arguments, unable to parse filename. First: `{previous_filename}` Second: `{chunk}`")
panic!("Found multiple unexpected arguments, unable to parse filename. First: `{previous_filename}` Second: `{chunk}`");
// .map(|arg| {
// // Can't split on commas if inside (parentheses)
// // Example: `--check-cfg cfg(feature, values("default", "simd"))`
// let mut split_points = Vec::new();
// let mut open_parens = 0;
// for (index, character) in arg.chars().enumerate() {
// match character {
// '(' => open_parens += 1,
// ')' => open_parens -= 1,
// ',' => {
// if open_parens == 0 {
// split_points.push(index)
// }
// }
// _ => (),
// }
// }
// })