Skip to content

Commit 242056c

Browse files
Do not panic in tidy on unbalanced parentheses in cfg's
1 parent 7096ff0 commit 242056c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/tools/tidy/src/pal.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn parse_cfgs<'a>(contents: &'a str) -> Vec<(usize, &'a str)> {
204204
succeeds_non_ident && preceeds_whitespace_and_paren
205205
});
206206

207-
cfgs.map(|i| {
207+
cfgs.flat_map(|i| {
208208
let mut depth = 0;
209209
let contents_from = &contents[i..];
210210
for (j, byte) in contents_from.bytes().enumerate() {
@@ -215,13 +215,15 @@ fn parse_cfgs<'a>(contents: &'a str) -> Vec<(usize, &'a str)> {
215215
b')' => {
216216
depth -= 1;
217217
if depth == 0 {
218-
return (i, &contents_from[..=j]);
218+
return Some((i, &contents_from[..=j]));
219219
}
220220
}
221221
_ => { }
222222
}
223223
}
224224

225-
unreachable!()
225+
// if the parentheses are unbalanced just ignore this cfg -- it'll be caught when attempting
226+
// to run the compiler, and there's no real reason to lint it separately here
227+
None
226228
}).collect()
227229
}

0 commit comments

Comments
 (0)