Skip to content

Commit

Permalink
Simplify search
Browse files Browse the repository at this point in the history
  • Loading branch information
kraigher committed Jun 17, 2023
1 parent 1cdda52 commit ec67fa0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions vhdl_lang/src/ast/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ pub use SearchResult::*;
pub use SearchState::*;

impl SearchState {
fn or_else(self, nested_fun: impl FnOnce() -> SearchResult) -> SearchResult {
fn or_not_found(self) -> SearchResult {
match self {
Finished(result) => result,
NotFinished => nested_fun(),
NotFinished => NotFound,
}
}

fn or_not_found(self) -> SearchResult {
self.or_else(|| NotFound)
}
}

#[derive(PartialEq, Debug)]
Expand Down Expand Up @@ -1026,9 +1022,8 @@ impl Search for Declaration {
}
}
Declaration::Use(use_clause) => {
return_if_found!(searcher
.search_with_pos(&use_clause.pos)
.or_else(|| use_clause.item.name_list.search(searcher)));
return_if_found!(searcher.search_with_pos(&use_clause.pos).or_not_found());
return_if_found!(use_clause.item.name_list.search(searcher));
}
Declaration::Component(component) => {
return_if_found!(searcher
Expand Down

0 comments on commit ec67fa0

Please sign in to comment.