style: avoid using .to_owned()/.to_vec() on owned objects

`.clone()` is more explicit when we already have an object
of the right type.
This commit is contained in:
Samuel Tardieu 2024-10-02 22:00:32 +02:00
parent 3f2ef2ee04
commit 12f4d6d17b
11 changed files with 19 additions and 19 deletions

View file

@ -134,6 +134,7 @@ testutils = { path = "lib/testutils" }
[workspace.lints.clippy]
explicit_iter_loop = "warn"
implicit_clone = "warn"
semicolon_if_nothing_returned = "warn"
uninlined_format_args = "warn"

View file

@ -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()

View file

@ -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,
});
@ -889,8 +889,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,
@ -920,7 +920,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),
@ -1043,8 +1043,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,

View file

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

View file

@ -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
};

View file

@ -956,8 +956,7 @@ impl Backend for GitBackend {
.try_into_blob()
.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();
.map_err(|err| to_invalid_utf8_err(err.utf8_error(), id))?;
Ok(target)
}

View file

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

View file

@ -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()?;

View file

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

View file

@ -611,8 +611,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(),
)?)
}
}

View file

@ -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();