diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-06-03 11:53:09 -0600 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-06-03 11:53:09 -0600 |
| commit | 242056cadf2073325cc8b8edea9dd2960db99e93 (patch) | |
| tree | 1304dc46d1ec2b147ba228df38cb4074cae4e1b9 | |
| parent | 7096ff0ce16b0544b717986ec335798b3151dd8e (diff) | |
| download | rust-242056cadf2073325cc8b8edea9dd2960db99e93.tar.gz rust-242056cadf2073325cc8b8edea9dd2960db99e93.zip | |
Do not panic in tidy on unbalanced parentheses in cfg's
| -rw-r--r-- | src/tools/tidy/src/pal.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/tools/tidy/src/pal.rs b/src/tools/tidy/src/pal.rs index 837be69f7ca..d4a6cf73bf9 100644 --- a/src/tools/tidy/src/pal.rs +++ b/src/tools/tidy/src/pal.rs @@ -204,7 +204,7 @@ fn parse_cfgs<'a>(contents: &'a str) -> Vec<(usize, &'a str)> { succeeds_non_ident && preceeds_whitespace_and_paren }); - cfgs.map(|i| { + cfgs.flat_map(|i| { let mut depth = 0; let contents_from = &contents[i..]; for (j, byte) in contents_from.bytes().enumerate() { @@ -215,13 +215,15 @@ fn parse_cfgs<'a>(contents: &'a str) -> Vec<(usize, &'a str)> { b')' => { depth -= 1; if depth == 0 { - return (i, &contents_from[..=j]); + return Some((i, &contents_from[..=j])); } } _ => { } } } - unreachable!() + // if the parentheses are unbalanced just ignore this cfg -- it'll be caught when attempting + // to run the compiler, and there's no real reason to lint it separately here + None }).collect() } |
