Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b08e51d

Browse files
committed
refactor away some 'else { None }'
1 parent 302e9ae commit b08e51d

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

src/machine.rs

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -367,20 +367,14 @@ impl<'mir, 'tcx> Evaluator<'mir, 'tcx> {
367367
measureme::Profiler::new(out).expect("Couldn't create `measureme` profiler")
368368
});
369369
let rng = StdRng::seed_from_u64(config.seed.unwrap_or(0));
370-
let stacked_borrows = if config.stacked_borrows {
371-
Some(RefCell::new(stacked_borrows::GlobalStateInner::new(
370+
let stacked_borrows = config.stacked_borrows.then(|| {
371+
RefCell::new(stacked_borrows::GlobalStateInner::new(
372372
config.tracked_pointer_tags.clone(),
373373
config.tracked_call_ids.clone(),
374374
config.retag_fields,
375-
)))
376-
} else {
377-
None
378-
};
379-
let data_race = if config.data_race_detector {
380-
Some(data_race::GlobalState::new(config))
381-
} else {
382-
None
383-
};
375+
))
376+
});
377+
let data_race = config.data_race_detector.then(|| data_race::GlobalState::new(config));
384378
Evaluator {
385379
stacked_borrows,
386380
data_race,
@@ -691,32 +685,24 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
691685
}
692686

693687
let alloc = alloc.into_owned();
694-
let stacks = if let Some(stacked_borrows) = &ecx.machine.stacked_borrows {
695-
Some(Stacks::new_allocation(
688+
let stacks = ecx.machine.stacked_borrows.as_ref().map(|stacked_borrows| {
689+
Stacks::new_allocation(
696690
id,
697691
alloc.size(),
698692
stacked_borrows,
699693
kind,
700694
ecx.machine.current_span(),
701-
))
702-
} else {
703-
None
704-
};
705-
let race_alloc = if let Some(data_race) = &ecx.machine.data_race {
706-
Some(data_race::AllocExtra::new_allocation(
695+
)
696+
});
697+
let race_alloc = ecx.machine.data_race.as_ref().map(|data_race| {
698+
data_race::AllocExtra::new_allocation(
707699
data_race,
708700
&ecx.machine.threads,
709701
alloc.size(),
710702
kind,
711-
))
712-
} else {
713-
None
714-
};
715-
let buffer_alloc = if ecx.machine.weak_memory {
716-
Some(weak_memory::AllocExtra::new_allocation())
717-
} else {
718-
None
719-
};
703+
)
704+
});
705+
let buffer_alloc = ecx.machine.weak_memory.then(weak_memory::AllocExtra::new_allocation);
720706
let alloc: Allocation<Provenance, Self::AllocExtra> = alloc.adjust_from_tcx(
721707
&ecx.tcx,
722708
AllocExtra {

0 commit comments

Comments
 (0)