From 0d87eee3a9d3950cd02a80bf3974b4b165c5a76c Mon Sep 17 00:00:00 2001 From: Paul Daniel Faria Date: Tue, 23 Jun 2020 19:35:09 -0400 Subject: Improve readability be replacing hard-to-read if-else branches with a match --- crates/ra_ide/src/syntax_highlighting.rs | 36 ++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/crates/ra_ide/src/syntax_highlighting.rs b/crates/ra_ide/src/syntax_highlighting.rs index 91f27aa2a..028b55902 100644 --- a/crates/ra_ide/src/syntax_highlighting.rs +++ b/crates/ra_ide/src/syntax_highlighting.rs @@ -372,22 +372,26 @@ impl HighlightedRangeStack { } else { let maybe_idx = prev.iter().position(|parent| parent.range.contains(child.range.start())); - if let (Some(_), Some(idx)) = (overwrite_parent, maybe_idx) { - Self::intersect_partial(&mut prev[idx], &child); - let insert_idx = if prev[idx].range.is_empty() { - prev.remove(idx); - idx - } else { - idx + 1 - }; - prev.insert(insert_idx, child); - } else if let None = maybe_idx { - let idx = prev - .binary_search_by_key(&child.range.start(), |range| range.range.start()) - .unwrap_or_else(|x| x); - prev.insert(idx, child); - } else { - unreachable!("child range should be completely contained in parent range"); + match (overwrite_parent, maybe_idx) { + (Some(_), Some(idx)) => { + Self::intersect_partial(&mut prev[idx], &child); + let insert_idx = if prev[idx].range.is_empty() { + prev.remove(idx); + idx + } else { + idx + 1 + }; + prev.insert(insert_idx, child); + } + (_, None) => { + let idx = prev + .binary_search_by_key(&child.range.start(), |range| range.range.start()) + .unwrap_or_else(|x| x); + prev.insert(idx, child); + } + _ => { + unreachable!("child range should be completely contained in parent range"); + } } } } -- cgit v1.2.3