From f683d4f3cd1cf741afc163ba7caec7c592d9af2e Mon Sep 17 00:00:00 2001 From: Jani Monoses Date: Mon, 18 Oct 2021 13:04:08 +0300 Subject: [PATCH] Remove useless into() conversions caught by clippy. --- crates/tor-dirmgr/src/lib.rs | 22 +++++++++++----------- crates/tor-dirmgr/src/shared_ref.rs | 2 +- crates/tor-dirmgr/src/state.rs | 18 +++++++++--------- crates/tor-dirmgr/src/storage.rs | 2 +- crates/tor-dirmgr/src/storage/sqlite.rs | 14 ++++++++------ 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/crates/tor-dirmgr/src/lib.rs b/crates/tor-dirmgr/src/lib.rs index 1c90ed59d..650c66550 100644 --- a/crates/tor-dirmgr/src/lib.rs +++ b/crates/tor-dirmgr/src/lib.rs @@ -160,9 +160,7 @@ impl DirMgr { // TODO: add some way to return a directory that isn't up-to-date let _success = dirmgr.load_directory().await?; - dirmgr - .opt_netdir() - .ok_or_else(|| Error::DirectoryNotPresent.into()) + dirmgr.opt_netdir().ok_or(Error::DirectoryNotPresent) } /// Return a current netdir, either loading it or bootstrapping it @@ -231,7 +229,7 @@ impl DirMgr { } Err(_) => { warn!("Bootstrapping task exited before finishing."); - return Err(Error::CantAdvanceState.into()); + return Err(Error::CantAdvanceState); } } } @@ -351,7 +349,7 @@ impl DirMgr { "We failed {} times to bootstrap a directory. We're going to give up.", retry_config.n_attempts() ); - return Err(Error::CantAdvanceState.into()); + return Err(Error::CantAdvanceState); } else { // Report success, if appropriate. if let Some(send_done) = on_complete.take() { @@ -373,7 +371,7 @@ impl DirMgr { self.circmgr .as_ref() .map(Arc::clone) - .ok_or_else(|| Error::NoDownloadSupport.into()) + .ok_or(Error::NoDownloadSupport) } /// Try to make this a directory manager with read-write access to its @@ -459,9 +457,9 @@ impl DirMgr { })?; if let Some((docid, doctext)) = item { if &docid != doc { - return Err( - Error::CacheCorruption("Item from storage had incorrect docid.").into(), - ); + return Err(Error::CacheCorruption( + "Item from storage had incorrect docid.", + )); } Ok(Some(doctext)) } else { @@ -625,7 +623,9 @@ impl DirMgr { return Ok(new_consensus.to_string()); } } - return Err(Error::Unwanted("Received a consensus diff we did not ask for").into()); + return Err(Error::Unwanted( + "Received a consensus diff we did not ask for", + )); } } Ok(text) @@ -712,5 +712,5 @@ trait DirState: Send { /// Try to upgrade a weak reference to a DirMgr, and give an error on /// failure. fn upgrade_weak_ref(weak: &Weak) -> Result> { - Weak::upgrade(weak).ok_or_else(|| Error::ManagerDropped.into()) + Weak::upgrade(weak).ok_or(Error::ManagerDropped) } diff --git a/crates/tor-dirmgr/src/shared_ref.rs b/crates/tor-dirmgr/src/shared_ref.rs index dc1f58a36..89a02da9c 100644 --- a/crates/tor-dirmgr/src/shared_ref.rs +++ b/crates/tor-dirmgr/src/shared_ref.rs @@ -90,7 +90,7 @@ impl SharedMutArc { .expect("Poisoned lock for directory reference") .as_mut() { - None => Err(Error::DirectoryNotPresent.into()), // Kinda bogus. + None => Err(Error::DirectoryNotPresent), // Kinda bogus. Some(arc) => func(Arc::make_mut(arc)), } } diff --git a/crates/tor-dirmgr/src/state.rs b/crates/tor-dirmgr/src/state.rs index efb655fd9..4f47a45d3 100644 --- a/crates/tor-dirmgr/src/state.rs +++ b/crates/tor-dirmgr/src/state.rs @@ -121,7 +121,7 @@ impl GetConsensusState { .map(|auth| *auth.v3ident()) .collect() } else { - return Err(Error::ManagerDropped.into()); + return Err(Error::ManagerDropped); }; Ok(GetConsensusState { cache_usage, @@ -166,7 +166,7 @@ impl DirState for GetConsensusState { if let Some(wd) = Weak::upgrade(&self.writedir) { Ok((1, *wd.config().schedule().retry_consensus())) } else { - Err(Error::ManagerDropped.into()) + Err(Error::ManagerDropped) } } fn add_from_cache(&mut self, docs: HashMap) -> Result { @@ -179,7 +179,7 @@ impl DirState for GetConsensusState { }, text, )) => text, - _ => return Err(Error::Unwanted("Not an md consensus").into()), + _ => return Err(Error::Unwanted("Not an md consensus")), }; self.add_consensus_text(true, text.as_str()?) @@ -242,7 +242,7 @@ impl GetConsensusState { let id_refs: Vec<_> = self.authority_ids.iter().collect(); if !unvalidated.authorities_are_correct(&id_refs[..]) { - return Err(Error::UnrecognizedAuthorities.into()); + return Err(Error::UnrecognizedAuthorities); } // Make a set of all the certificates we want -- the subset of @@ -327,7 +327,7 @@ impl DirState for GetCertsState { if let Some(wd) = Weak::upgrade(&self.writedir) { Ok((1, *wd.config().schedule().retry_certs())) } else { - Err(Error::ManagerDropped.into()) + Err(Error::ManagerDropped) } } fn add_from_cache(&mut self, docs: HashMap) -> Result { @@ -356,7 +356,7 @@ impl DirState for GetCertsState { ) -> Result { let asked_for: HashSet<_> = match request { ClientRequest::AuthCert(a) => a.keys().collect(), - _ => return Err(Error::BadArgument("Mismatched request").into()), + _ => return Err(Error::BadArgument("Mismatched request")), }; let mut newcerts = Vec::new(); @@ -474,7 +474,7 @@ impl GetMicrodescsState { } dir } - None => return Err(Error::ManagerDropped.into()), + None => return Err(Error::ManagerDropped), }; let missing = partial_dir.missing_microdescs().map(Clone::clone).collect(); @@ -565,7 +565,7 @@ impl DirState for GetMicrodescsState { *wd.config().schedule().retry_microdescs(), )) } else { - Err(Error::ManagerDropped.into()) + Err(Error::ManagerDropped) } } fn add_from_cache(&mut self, docs: HashMap) -> Result { @@ -600,7 +600,7 @@ impl DirState for GetMicrodescsState { let requested: HashSet<_> = if let ClientRequest::Microdescs(req) = request { req.digests().collect() } else { - return Err(Error::BadArgument("Mismatched request").into()); + return Err(Error::BadArgument("Mismatched request")); }; let mut new_mds = Vec::new(); for anno in MicrodescReader::new(text, &AllowAnnotations::AnnotationsNotAllowed).flatten() { diff --git a/crates/tor-dirmgr/src/storage.rs b/crates/tor-dirmgr/src/storage.rs index a46c7c71f..d3f601cd2 100644 --- a/crates/tor-dirmgr/src/storage.rs +++ b/crates/tor-dirmgr/src/storage.rs @@ -65,7 +65,7 @@ impl InputString { /// Return a view of this InputString as a &str, if it is valid UTF-8. pub(crate) fn as_str(&self) -> Result<&str> { self.as_str_impl() - .map_err(|_| Error::CacheCorruption("Invalid UTF-8").into()) + .map_err(|_| Error::CacheCorruption("Invalid UTF-8")) } /// Helper for [`Self::as_str()`], with unwrapped error type. diff --git a/crates/tor-dirmgr/src/storage/sqlite.rs b/crates/tor-dirmgr/src/storage/sqlite.rs index bb63d7c5c..c616e172e 100644 --- a/crates/tor-dirmgr/src/storage/sqlite.rs +++ b/crates/tor-dirmgr/src/storage/sqlite.rs @@ -182,7 +182,7 @@ impl SqliteStore { tx.commit()?; return Ok(()); } else if readable_by > SCHEMA_VERSION { - return Err(Error::UnrecognizedSchema.into()); + return Err(Error::UnrecognizedSchema); } // rolls back the transaction, but nothing was done. @@ -230,7 +230,7 @@ impl SqliteStore { .components() .all(|c| matches!(c, path::Component::Normal(_))) { - return Err(Error::CacheCorruption("Invalid path in database").into()); + return Err(Error::CacheCorruption("Invalid path in database")); } let mut result = self.path.clone(); @@ -419,7 +419,9 @@ impl SqliteStore { { Ok(text) } else { - Err(Error::CacheCorruption("couldn't find a consensus we thought we had.").into()) + Err(Error::CacheCorruption( + "couldn't find a consensus we thought we had.", + )) } } @@ -671,7 +673,7 @@ impl Drop for Unlinker { fn digest_from_hex(s: &str) -> Result<[u8; 32]> { hex::decode(s)? .try_into() - .map_err(|_| Error::CacheCorruption("Invalid digest in database").into()) + .map_err(|_| Error::CacheCorruption("Invalid digest in database")) } /// Convert a hexadecimal sha3-256 "digest string" as used in the @@ -680,9 +682,9 @@ fn digest_from_dstr(s: &str) -> Result<[u8; 32]> { if let Some(stripped) = s.strip_prefix("sha3-256-") { hex::decode(stripped)? .try_into() - .map_err(|_| Error::CacheCorruption("Invalid digest in database").into()) + .map_err(|_| Error::CacheCorruption("Invalid digest in database")) } else { - Err(Error::CacheCorruption("Invalid digest in database").into()) + Err(Error::CacheCorruption("Invalid digest in database")) } }