mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
refactor: return option
This commit is contained in:
parent
ca16dc3459
commit
60311fc7ce
1 changed files with 7 additions and 8 deletions
|
@ -351,7 +351,7 @@ fn tests_at_path<'a>(
|
||||||
let mut all_tests = Vec::new();
|
let mut all_tests = Vec::new();
|
||||||
|
|
||||||
for branch in branches {
|
for branch in branches {
|
||||||
test_at_path(selected_path, branch, &mut all_tests);
|
all_tests.extend(test_at_path(selected_path, branch));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The rust HashMap also uses equality, here we really want to use the custom hash function
|
// The rust HashMap also uses equality, here we really want to use the custom hash function
|
||||||
|
@ -382,8 +382,7 @@ fn tests_at_path<'a>(
|
||||||
fn test_at_path<'a>(
|
fn test_at_path<'a>(
|
||||||
selected_path: &[PathInstruction],
|
selected_path: &[PathInstruction],
|
||||||
branch: &Branch<'a>,
|
branch: &Branch<'a>,
|
||||||
guarded_tests: &mut Vec<GuardedTest<'a>>,
|
) -> Option<GuardedTest<'a>> {
|
||||||
) {
|
|
||||||
use Pattern::*;
|
use Pattern::*;
|
||||||
use Test::*;
|
use Test::*;
|
||||||
|
|
||||||
|
@ -392,18 +391,18 @@ fn test_at_path<'a>(
|
||||||
.iter()
|
.iter()
|
||||||
.find(|(path, _, _)| path == selected_path)
|
.find(|(path, _, _)| path == selected_path)
|
||||||
{
|
{
|
||||||
None => {}
|
None => None,
|
||||||
Some((_, guard, pattern)) => {
|
Some((_, guard, pattern)) => {
|
||||||
let test = match pattern {
|
let test = match pattern {
|
||||||
Identifier(_) | Underscore => {
|
Identifier(_) | Underscore => {
|
||||||
if let Guard::Guard { id, stmt, .. } = guard {
|
if let Guard::Guard { id, stmt, .. } = guard {
|
||||||
guarded_tests.push(GuardedTest::GuardedNoTest {
|
return Some(GuardedTest::GuardedNoTest {
|
||||||
stmt: stmt.clone(),
|
stmt: stmt.clone(),
|
||||||
id: *id,
|
id: *id,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RecordDestructure(destructs, _) => {
|
RecordDestructure(destructs, _) => {
|
||||||
|
@ -485,7 +484,7 @@ fn test_at_path<'a>(
|
||||||
GuardedTest::TestNotGuarded { test }
|
GuardedTest::TestNotGuarded { test }
|
||||||
};
|
};
|
||||||
|
|
||||||
guarded_tests.push(guarded_test);
|
Some(guarded_test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue