Skip to content

Commit

Permalink
style: fix clippy warnings/suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Shadow53 committed Oct 5, 2023
1 parent 188a307 commit 6e87056
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/checkers/history/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ async fn get_history_dirs_not_for_id(id: &Uuid) -> Result<Vec<HoardPath>, io::Er
///
/// Any I/O unexpected errors that may occur while reading and/or
/// writing the UUID file.
#[allow(clippy::missing_panics_doc)]
pub async fn get_or_generate_uuid() -> Result<Uuid, io::Error> {
let uuid_file = get_uuid_file();
let _span = tracing::debug_span!("get_or_generate_uuid", file = ?uuid_file);
Expand Down
4 changes: 4 additions & 0 deletions src/checkers/history/operation/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ pub(crate) async fn cleanup_operations() -> Result<u32, (u32, Error)> {
// Get hoard history root
// Iterate over every uuid in the directory
let root = get_history_root_dir();

// The .fold() at the end creates a new error based on the old one, which
// is not compatible with try_fold()
#[allow(clippy::manual_try_fold)]
fs::read_dir(&root)
.await
.map(ReadDirStream::new)
Expand Down
2 changes: 1 addition & 1 deletion src/config/builder/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ mod tests {
path_exists: Some(Combinator(vec![Inner::Single(path_exists.clone())])),
};

let expected = vec![
let expected = [
format!("({hostname})"),
format!("({os})"),
format!("({env_var})"),
Expand Down
33 changes: 13 additions & 20 deletions src/config/builder/envtrie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ fn get_weighted_map(
// Check for cycles, then discard graph
tracing::trace!("checking for cycles");
let mut score_dag = DiGraph::<EnvironmentName, ()>::new();
for list in exclusive_list.iter() {
for list in exclusive_list {
let mut prev_idx = None;

for name in list.iter().rev() {
Expand Down Expand Up @@ -433,22 +433,17 @@ impl EnvTrie {
let tree =
nodes
.into_iter()
.fold(Ok(BTreeMap::<EnvironmentName, Node>::new()), |acc, node| {
.try_fold(BTreeMap::<EnvironmentName, Node>::new(), |mut acc, node| {
// TODO: Use result flattening when stable
match acc {
Err(err) => Err(err),
Ok(mut tree) => {
// Explicitly call `drop()` to drop any old value.
match tree.remove(&node.name) {
None => drop(tree.insert(node.name.clone(), node)),
Some(existing) => {
let new_node = existing.merge_with(node)?;
drop(tree.insert(new_node.name.clone(), new_node));
}
}
Ok(tree)
// Explicitly call `drop()` to drop any old value.
match acc.remove(&node.name) {
None => drop(acc.insert(node.name.clone(), node)),
Some(existing) => {
let new_node = existing.merge_with(node)?;
drop(acc.insert(new_node.name.clone(), new_node));
}
}
Ok(acc)
})?;
Ok(EnvTrie(tree))
}
Expand Down Expand Up @@ -476,10 +471,9 @@ impl EnvTrie {
.transpose()
.map(|path| (env, node, path))
})
.fold(Ok(None), |acc, (_, node, path)| match (acc, path) {
(Err(err), _) | (_, Err(err)) => Err(err),
(Ok(None), Ok(path)) => Ok(Some((node, path))),
(Ok(Some((acc, acc_path))), Ok(path)) => match acc.score.cmp(&node.score) {
.try_fold(None, |acc: Option<(&Node, _)>, (_, node, path)| match (acc, path) {
(None, path) => Ok(Some((node, path))),
(Some((acc, acc_path)), path) => match acc.score.cmp(&node.score) {
Ordering::Equal => Err(Error::Indecision(
acc.name.clone().into(),
node.name.clone().into(),
Expand All @@ -489,7 +483,6 @@ impl EnvTrie {
},
})?
.map(|(_, path)| path)
.map(Ok)
.transpose()
}
}
Expand Down Expand Up @@ -549,7 +542,7 @@ mod tests {
return false;
}

for (key, node1) in tree1.iter() {
for (key, node1) in tree1 {
let equal = match tree2.get(key) {
None => false,
Some(node2) => node_eq_ignore_score(node1, node2),
Expand Down
2 changes: 1 addition & 1 deletion src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{env, fmt};
//
// The `+?` is non-greedy matching, which is necessary for if there are multiple variables.
static ENV_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r#"\$\{[^(=|\x{0}|$)]+?}"#).expect("failed to compile regular expression")
Regex::new(r"\$\{[^(=|\x{0}|$)]+?}").expect("failed to compile regular expression")
});

/// An error that may occur during expansion.
Expand Down
2 changes: 2 additions & 0 deletions src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ impl HoardPath {
/// use it as the prefix directory for a [`RelativePath`]. It is up to the caller to make
/// sure the resulting path is valid for use.
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn join(&self, rhs: &RelativePath) -> Self {
Self::try_from(
rhs.0
Expand Down Expand Up @@ -227,6 +228,7 @@ impl SystemPath {
/// use it as the prefix directory for a [`RelativePath`]. It is up to the caller to make
/// sure the resulting path is valid for use.
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn join(&self, rhs: &RelativePath) -> Self {
Self::try_from(
rhs.0
Expand Down

0 comments on commit 6e87056

Please sign in to comment.