From 4fda0f8b6a552c4db77b4f7045e48e1ad8fc18d5 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Sat, 21 May 2022 22:59:43 -0700 Subject: [PATCH] matchers: simplify `DifferenceMatcher` slightly The new `Visit::Nothing` variant lets us more easily restructure `DifferenceMatcher::visit()` to make it handle the case of not removing anything. I think this makes the code a little clearer. --- lib/src/matchers.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/src/matchers.rs b/lib/src/matchers.rs index 1772934ef..cc1d35e9b 100644 --- a/lib/src/matchers.rs +++ b/lib/src/matchers.rs @@ -187,17 +187,12 @@ impl Matcher for DifferenceMatcher<'_> { fn visit(&self, dir: &RepoPath) -> Visit { match self.unwanted.visit(dir) { Visit::AllRecursively => Visit::Nothing, - unwanted_visit => match self.wanted.visit(dir) { - Visit::AllRecursively => { - if unwanted_visit == Visit::Nothing { - Visit::AllRecursively - } else { - Visit::Specific { - dirs: VisitDirs::All, - files: VisitFiles::All, - } - } - } + Visit::Nothing => self.wanted.visit(dir), + Visit::Specific { .. } => match self.wanted.visit(dir) { + Visit::AllRecursively => Visit::Specific { + dirs: VisitDirs::All, + files: VisitFiles::All, + }, wanted_visit => wanted_visit, }, }