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); v.store(false, Ordering::SeqCst);
}); });
let schedule = match self.task_schedule.lock().expect("poisoned lock").take() { let schedule = {
Some(sched) => sched, let sched = self.task_schedule.lock().expect("poisoned lock").take();
None => { match sched {
debug!("Attempted to bootstrap twice; ignoring."); Some(sched) => sched,
return Ok(()); 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>, F: FnOnce(&mut T) -> Result<U>,
T: Clone, T: Clone,
{ {
match self let mut writeable = self
.dir .dir
.write() .write()
.expect("Poisoned lock for directory reference") .expect("Poisoned lock for directory reference");
.as_mut() let dir = writeable.as_mut();
{ match dir {
None => Err(Error::DirectoryNotPresent), // Kinda bogus. None => Err(Error::DirectoryNotPresent), // Kinda bogus.
Some(arc) => func(Arc::make_mut(arc)), Some(arc) => func(Arc::make_mut(arc)),
} }

View File

@ -591,8 +591,8 @@ impl<R: Runtime> GuardMgr<R> {
) { ) {
let now = self.runtime.now(); let now = self.runtime.now();
let mut inner = self.inner.lock().expect("Poisoned lock"); let mut inner = self.inner.lock().expect("Poisoned lock");
let ids = inner.lookup_ids(ed_identity, rsa_identity);
for id in inner.lookup_ids(ed_identity, rsa_identity) { for id in ids {
match &id.0 { match &id.0 {
FirstHopIdInner::Guard(id) => { FirstHopIdInner::Guard(id) => {
inner.guards.active_guards_mut().record_failure( 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 inner = self.inner.lock().expect("Lock poisoned.");
let storage = inner.storage.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)?)), Some(value) => Ok(Some(serde_json::from_str(value).map_err(load_error)?)),
None => Ok(None), None => Ok(None),
} }