Remove useless into() conversions caught by clippy.

This commit is contained in:
Jani Monoses 2021-10-18 13:04:08 +03:00
parent 8d39a6e96e
commit f683d4f3cd
5 changed files with 30 additions and 28 deletions

View File

@ -160,9 +160,7 @@ impl<R: Runtime> DirMgr<R> {
// 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<R: Runtime> DirMgr<R> {
}
Err(_) => {
warn!("Bootstrapping task exited before finishing.");
return Err(Error::CantAdvanceState.into());
return Err(Error::CantAdvanceState);
}
}
}
@ -351,7 +349,7 @@ impl<R: Runtime> DirMgr<R> {
"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<R: Runtime> DirMgr<R> {
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<R: Runtime> DirMgr<R> {
})?;
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<R: Runtime> DirMgr<R> {
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<T>(weak: &Weak<T>) -> Result<Arc<T>> {
Weak::upgrade(weak).ok_or_else(|| Error::ManagerDropped.into())
Weak::upgrade(weak).ok_or(Error::ManagerDropped)
}

View File

@ -90,7 +90,7 @@ impl<T> SharedMutArc<T> {
.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)),
}
}

View File

@ -121,7 +121,7 @@ impl<DM: WriteNetDir> GetConsensusState<DM> {
.map(|auth| *auth.v3ident())
.collect()
} else {
return Err(Error::ManagerDropped.into());
return Err(Error::ManagerDropped);
};
Ok(GetConsensusState {
cache_usage,
@ -166,7 +166,7 @@ impl<DM: WriteNetDir> DirState for GetConsensusState<DM> {
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<DocId, DocumentText>) -> Result<bool> {
@ -179,7 +179,7 @@ impl<DM: WriteNetDir> DirState for GetConsensusState<DM> {
},
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<DM: WriteNetDir> GetConsensusState<DM> {
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<DM: WriteNetDir> DirState for GetCertsState<DM> {
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<DocId, DocumentText>) -> Result<bool> {
@ -356,7 +356,7 @@ impl<DM: WriteNetDir> DirState for GetCertsState<DM> {
) -> Result<bool> {
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<DM: WriteNetDir> GetMicrodescsState<DM> {
}
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<DM: WriteNetDir> DirState for GetMicrodescsState<DM> {
*wd.config().schedule().retry_microdescs(),
))
} else {
Err(Error::ManagerDropped.into())
Err(Error::ManagerDropped)
}
}
fn add_from_cache(&mut self, docs: HashMap<DocId, DocumentText>) -> Result<bool> {
@ -600,7 +600,7 @@ impl<DM: WriteNetDir> DirState for GetMicrodescsState<DM> {
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() {

View File

@ -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.

View File

@ -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"))
}
}