about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-04 04:48:27 +0200
committerGitHub <noreply@github.com>2019-06-04 04:48:27 +0200
commit6ad6ef235581e9db4fd5160880b98eedbdc2d488 (patch)
tree4f404ff94341dc6eac9962a6ae177e7739f0f6a3
parentcb2feb6460be7185b5f030235758da38825f311a (diff)
parent242056cadf2073325cc8b8edea9dd2960db99e93 (diff)
downloadrust-6ad6ef235581e9db4fd5160880b98eedbdc2d488.tar.gz
rust-6ad6ef235581e9db4fd5160880b98eedbdc2d488.zip
Rollup merge of #61496 - Mark-Simulacrum:tidy-unbalanced-parens, r=varkor
Do not panic in tidy on unbalanced parentheses in cfg's

Fixes #60505
-rw-r--r--src/tools/tidy/src/pal.rs8
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()
 }