Fix clippy::significant_drop_in_scrutinee warnings

This is apparently a new warning from clippy nightly, documented in
https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee .

I'm not in love with the temporary variables that this warning wants
me to introduce, but it does seem like a decent way to avoid some
kinds of deadlock.
This commit is contained in:
Nick Mathewson 2022-06-14 14:52:39 -04:00
parent 425af9db91
commit 647d4410bb
4 changed files with 16 additions and 12 deletions

View File

@ -376,11 +376,14 @@ impl<R: Runtime> DirMgr<R> {
v.store(false, Ordering::SeqCst);
});
let schedule = match self.task_schedule.lock().expect("poisoned lock").take() {
Some(sched) => sched,
None => {
debug!("Attempted to bootstrap twice; ignoring.");
return Ok(());
let schedule = {
let sched = self.task_schedule.lock().expect("poisoned lock").take();
match sched {
Some(sched) => sched,
None => {
debug!("Attempted to bootstrap twice; ignoring.");
return Ok(());
}
}
};

View File

@ -79,12 +79,12 @@ impl<T> SharedMutArc<T> {
F: FnOnce(&mut T) -> Result<U>,
T: Clone,
{
match self
let mut writeable = self
.dir
.write()
.expect("Poisoned lock for directory reference")
.as_mut()
{
.expect("Poisoned lock for directory reference");
let dir = writeable.as_mut();
match dir {
None => Err(Error::DirectoryNotPresent), // Kinda bogus.
Some(arc) => func(Arc::make_mut(arc)),
}

View File

@ -591,8 +591,8 @@ impl<R: Runtime> GuardMgr<R> {
) {
let now = self.runtime.now();
let mut inner = self.inner.lock().expect("Poisoned lock");
for id in inner.lookup_ids(ed_identity, rsa_identity) {
let ids = inner.lookup_ids(ed_identity, rsa_identity);
for id in ids {
match &id.0 {
FirstHopIdInner::Guard(id) => {
inner.guards.active_guards_mut().record_failure(

View File

@ -96,7 +96,8 @@ impl StateMgr for TestingStateMgr {
{
let inner = self.inner.lock().expect("Lock poisoned.");
let storage = inner.storage.lock().expect("Lock poisoned.");
match storage.entries.get(key) {
let content = storage.entries.get(key);
match content {
Some(value) => Ok(Some(serde_json::from_str(value).map_err(load_error)?)),
None => Ok(None),
}