Skip to content

Commit

Permalink
style: remove redundant else blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Oct 2, 2024
1 parent 501519c commit 9db0467
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ testutils = { path = "lib/testutils" }
[workspace.lints.clippy]
explicit_iter_loop = "deny"
implicit_clone = "deny"
redundant_else = "deny"
semicolon_if_nothing_returned = "deny"
uninlined_format_args = "deny"

Expand Down
12 changes: 5 additions & 7 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3009,15 +3009,13 @@ fn resolve_aliases(
string_args.extend_from_slice(&alias_args);
resolved_aliases.insert(alias_name.clone());
continue;
} else {
return Err(user_error(format!(
r#"Alias definition for "{alias_name}" must be a string list"#
)));
}
} else {
// Not a real command and not an alias, so return what we've resolved so far
return Ok(string_args);
return Err(user_error(format!(
r#"Alias definition for "{alias_name}" must be a string list"#
)));
}
// Not a real command and not an alias, so return what we've resolved so far
return Ok(string_args);
}
}
// No more alias commands, or hit unknown option
Expand Down
7 changes: 3 additions & 4 deletions cli/src/commands/file/untrack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,10 @@ pub(crate) fn cmd_file_untrack(
"Files that are not ignored will be added back by the next command.
Make sure they're ignored, then try again.",
));
} else {
// This means there were some concurrent changes made in the working copy. We
// don't want to mix those in, so reset the working copy again.
locked_ws.locked_wc().reset(&new_commit)?;
}
// This means there were some concurrent changes made in the working copy. We
// don't want to mix those in, so reset the working copy again.
locked_ws.locked_wc().reset(&new_commit)?;
}
let num_rebased = tx.repo_mut().rebase_descendants(command.settings())?;
if num_rebased > 0 {
Expand Down
Binary file added cli/src/commands/workspace/.add.rs.swp
Binary file not shown.
3 changes: 1 addition & 2 deletions cli/src/commands/workspace/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ pub fn cmd_workspace_add(
let destination_path = command.cwd().join(&args.destination);
if destination_path.exists() {
return Err(user_error("Workspace already exists"));
} else {
fs::create_dir(&destination_path).context(&destination_path)?;
}
fs::create_dir(&destination_path).context(&destination_path)?;
let name = if let Some(name) = &args.name {
name.to_string()
} else {
Expand Down
5 changes: 2 additions & 3 deletions lib/src/default_index/rev_walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,9 @@ impl<I: RevWalkIndex + ?Sized> RevWalk<I> for RevWalkImpl<I::Position> {
// No more wanted entries to walk
debug_assert!(!self.queue.items.iter().any(|x| x.is_wanted()));
return None;
} else {
self.queue
.extend_unwanted(index.adjacent_positions(item.pos));
}
self.queue
.extend_unwanted(index.adjacent_positions(item.pos));
}

debug_assert_eq!(
Expand Down
4 changes: 1 addition & 3 deletions lib/src/default_index/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,7 @@ impl IndexStore for DefaultIndexStore {
);
}
ReadonlyIndexLoadError::Other { name: _, error } => {
eprintln!(
"{err} (maybe the format has changed): {error}. Reindexing..."
);
eprintln!("{err} (maybe the format has changed): {error}. Reindexing...");
}
}
self.reinit().map_err(|err| IndexReadError(err.into()))?;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/file_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ pub fn relative_path(from: &Path, to: &Path) -> PathBuf {
// Find common prefix.
for (i, base) in from.ancestors().enumerate() {
if let Ok(suffix) = to.strip_prefix(base) {
if i == 0 && suffix.as_os_str().is_empty() {
return ".".into();
return if i == 0 && suffix.as_os_str().is_empty() {
".".into()
} else {
let mut result = PathBuf::from_iter(iter::repeat("..").take(i));
result.push(suffix);
return result;
}
result
};
}
}

Expand Down
3 changes: 1 addition & 2 deletions lib/src/merged_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,8 @@ impl Iterator for TreeDiffIterator<'_> {
path,
values: Ok((before, after)),
});
} else {
unreachable!();
}
unreachable!();
}
};

Expand Down
8 changes: 4 additions & 4 deletions lib/src/simple_op_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ impl OpStore for SimpleOpStore {
let hex_prefix = prefix.hex();
if hex_prefix.len() == OPERATION_ID_LENGTH * 2 {
// Fast path for full-length ID
if matches_root || op_dir.join(hex_prefix).try_exists()? {
return Ok(if matches_root || op_dir.join(hex_prefix).try_exists()? {
let id = OperationId::from_bytes(prefix.as_full_bytes().unwrap());
return Ok(PrefixResolution::SingleMatch(id));
PrefixResolution::SingleMatch(id)
} else {
return Ok(PrefixResolution::NoMatch);
}
PrefixResolution::NoMatch
});
}

let mut matched = matches_root.then(|| self.root_operation_id.clone());
Expand Down

0 comments on commit 9db0467

Please sign in to comment.