Skip to content

Commit

Permalink
style: avoid using .to_owned()/.to_vec() on owned objects
Browse files Browse the repository at this point in the history
`.clone()` is more explicit when we already have an object
of the right type.
  • Loading branch information
samueltardieu committed Oct 2, 2024
1 parent 8f59473 commit 501519c
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ testutils = { path = "lib/testutils" }

[workspace.lints.clippy]
explicit_iter_loop = "deny"
implicit_clone = "deny"
semicolon_if_nothing_returned = "deny"
uninlined_format_args = "deny"

Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub(crate) fn cmd_fix(
// reliably produce well formatted code anyway. Deduplicating inputs helps
// to prevent quadratic growth in the number of tool executions required for
// doing this in long chains of commits with disjoint sets of modified files.
let commits: Vec<_> = RevsetExpression::commits(root_commits.to_vec())
let commits: Vec<_> = RevsetExpression::commits(root_commits.clone())
.descendants()
.evaluate_programmatic(tx.base_repo().as_ref())?
.iter()
Expand Down
12 changes: 6 additions & 6 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl LayeredConfigs {
config_vals.push(AnnotatedValue {
path,
value: value.to_owned(),
source: source.to_owned(),
source: source.clone(),
// Note: Value updated below.
is_overridden: false,
});
Expand Down Expand Up @@ -888,8 +888,8 @@ mod tests {
fn test_layered_configs_resolved_config_values_empty() {
let empty_config = config::Config::default();
let layered_configs = LayeredConfigs {
default: empty_config.to_owned(),
env_base: empty_config.to_owned(),
default: empty_config.clone(),
env_base: empty_config.clone(),
user: None,
repo: None,
env_overrides: empty_config,
Expand Down Expand Up @@ -919,7 +919,7 @@ mod tests {
.build()
.unwrap();
let layered_configs = LayeredConfigs {
default: empty_config.to_owned(),
default: empty_config.clone(),
env_base: env_base_config,
user: None,
repo: Some(repo_config),
Expand Down Expand Up @@ -1042,8 +1042,8 @@ mod tests {
.build()
.unwrap();
let layered_configs = LayeredConfigs {
default: empty_config.to_owned(),
env_base: empty_config.to_owned(),
default: empty_config.clone(),
env_base: empty_config.clone(),
user: Some(user_config),
repo: Some(repo_config),
env_overrides: empty_config,
Expand Down
6 changes: 3 additions & 3 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ fn test_config_list_layer() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
let user_config_path = test_env.config_path().join("config.toml");
test_env.set_config_path(user_config_path.to_owned());
test_env.set_config_path(user_config_path.clone());
let repo_path = test_env.env_root().join("repo");

// User
Expand Down Expand Up @@ -456,7 +456,7 @@ fn test_config_set_for_user() {
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
// Point to a config file since `config set` can't handle directories.
let user_config_path = test_env.config_path().join("config.toml");
test_env.set_config_path(user_config_path.to_owned());
test_env.set_config_path(user_config_path.clone());
let repo_path = test_env.env_root().join("repo");

test_env.jj_cmd_ok(
Expand Down Expand Up @@ -840,7 +840,7 @@ fn test_config_show_paths() {
let mut test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["git", "init", "repo"]);
let user_config_path = test_env.config_path().join("config.toml");
test_env.set_config_path(user_config_path.to_owned());
test_env.set_config_path(user_config_path.clone());
let repo_path = test_env.env_root().join("repo");

test_env.jj_cmd_ok(
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ fn test_op_recover_from_bad_gc() {
let repo_path = test_env.env_root().join("repo");
let git_object_path = |hex: &str| {
let (shard, file_name) = hex.split_at(2);
let mut file_path = repo_path.to_owned();
let mut file_path = repo_path.clone();
file_path.extend([".git", "objects", shard, file_name]);
file_path
};
Expand Down
2 changes: 1 addition & 1 deletion lib/src/git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ impl Backend for GitBackend {
.map_err(|err| to_read_object_err(err, id))?;
let target = String::from_utf8(blob.take_data())
.map_err(|err| to_invalid_utf8_err(err.utf8_error(), id))?
.to_owned();
.clone();
Ok(target)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/local_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ fn commit_from_proto(mut proto: crate::protos::local_store::Commit) -> Commit {
MergedTreeId::Merge(merge_builder.build())
} else {
assert_eq!(proto.root_tree.len(), 1);
MergedTreeId::Legacy(TreeId::new(proto.root_tree[0].to_vec()))
MergedTreeId::Legacy(TreeId::new(proto.root_tree[0].clone()))
};
let change_id = ChangeId::new(proto.change_id);
Commit {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ impl MutableRepo {
let commit = self
.new_commit(
settings,
new_commit_ids.to_vec(),
new_commit_ids.clone(),
merged_parents_tree.id().clone(),
)
.write()?;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl UserSettings {
pub const USER_EMAIL_PLACEHOLDER: &'static str = "(no email configured)";

pub fn commit_timestamp(&self) -> Option<Timestamp> {
self.timestamp.to_owned()
self.timestamp
}

pub fn operation_timestamp(&self) -> Option<Timestamp> {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ impl WorkspaceLoader for DefaultWorkspaceLoader {
) -> Result<Box<dyn WorkingCopy>, WorkspaceLoadError> {
Ok(working_copy_factory.load_working_copy(
store.clone(),
self.workspace_root.to_owned(),
self.working_copy_state_path.to_owned(),
self.workspace_root.clone(),
self.working_copy_state_path.clone(),
)?)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/tests/test_local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ fn test_checkout_file_transitions(backend: TestRepoBackend) {
let path = RepoPathBuf::from_internal_string(format!("{left_kind:?}_{right_kind:?}"));
write_path(&settings, repo, &mut left_tree_builder, *left_kind, &path);
write_path(&settings, repo, &mut right_tree_builder, *right_kind, &path);
files.push((*left_kind, *right_kind, path.to_owned()));
files.push((*left_kind, *right_kind, path.clone()));
}
}
let left_tree_id = left_tree_builder.write_tree(&store).unwrap();
Expand Down

0 comments on commit 501519c

Please sign in to comment.