Prefer .to_owned() on &str

pull/652/head^2
Wilfred Hughes 2024-05-07 08:32:30 +07:00
parent 33542a47d5
commit 9474635076
6 changed files with 19 additions and 17 deletions

@ -142,7 +142,7 @@ impl<'s, 'b> fmt::Debug for EnteredDelimiter<'s, 'b> {
rhs_delims.size()
)
}
EnteredDelimiter::PopBoth(_) => "PopBoth".to_string(),
EnteredDelimiter::PopBoth(_) => "PopBoth".to_owned(),
};
f.write_str(&desc)
}

@ -619,7 +619,7 @@ mod tests {
);
assert_eq!(
format_missing_line_num(0.into(), &source_dims, Side::Left, false),
". ".to_string()
". ".to_owned()
);
}
@ -639,7 +639,7 @@ mod tests {
);
assert_eq!(
format_missing_line_num(1.into(), &source_dims, Side::Left, false),
" ".to_string()
" ".to_owned()
);
}
@ -650,7 +650,7 @@ mod tests {
"foo.py",
None,
&FileFormat::SupportedLanguage(Language::Python),
&["print(123)\n".to_string()],
&["print(123)\n".to_owned()],
Side::Right,
&DisplayOptions::default(),
);

@ -413,7 +413,7 @@ fn apply_header_color(
) -> String {
if use_color {
if hunk_num != 1 {
s.to_string()
s.to_owned()
} else if background.is_dark() {
s.bright_yellow().to_string()
} else {
@ -422,7 +422,7 @@ fn apply_header_color(
.bold()
.to_string()
} else {
s.to_string()
s.to_owned()
}
}
@ -437,7 +437,7 @@ pub(crate) fn print_warning(s: &str, display_options: &DisplayOptions) {
.bold()
.to_string()
} else {
"warning: ".to_string()
"warning: ".to_owned()
};
eprint!("{}", prefix);
@ -468,7 +468,7 @@ pub(crate) fn apply_line_number_color(
s.style(style).to_string()
} else {
s.to_string()
s.to_owned()
}
}

@ -141,7 +141,7 @@ pub(crate) enum ProbableFileKind {
pub(crate) fn guess_content(bytes: &[u8]) -> ProbableFileKind {
// If the bytes are entirely valid UTF-8, treat them as a string.
if let Ok(valid_utf8_string) = std::str::from_utf8(bytes) {
return ProbableFileKind::Text(valid_utf8_string.to_string());
return ProbableFileKind::Text(valid_utf8_string.to_owned());
}
// Only consider the first 1,000 bytes, as tree_magic_mini

@ -19,6 +19,8 @@
// implementation does not consider the mutable fields, so it is still
// correct.
#![allow(clippy::mutable_key_type)]
// .to_owned() is more explicit on string references.
#![warn(clippy::str_to_string)]
// Debugging features shouldn't be in checked-in code.
#![warn(clippy::todo)]
#![warn(clippy::dbg_macro)]
@ -163,7 +165,7 @@ fn main() {
LanguageOverride::Language(lang) => language_name(lang),
LanguageOverride::PlainText => "Text",
}
.to_string();
.to_owned();
if use_color {
name = name.bold().to_string();
}
@ -175,7 +177,7 @@ fn main() {
}
for language in Language::iter() {
let mut name = language_name(language).to_string();
let mut name = language_name(language).to_owned();
if use_color {
name = name.bold().to_string();
}
@ -475,7 +477,7 @@ fn check_only_text(
let has_changes = lhs_src != rhs_src;
DiffResult {
display_path: display_path.to_string(),
display_path: display_path.to_owned(),
extra_info,
file_format: file_format.clone(),
lhs_src: FileContent::Text(lhs_src.into()),
@ -518,7 +520,7 @@ fn diff_file_content(
// rather than doing any more work.
return DiffResult {
extra_info,
display_path: display_path.to_string(),
display_path: display_path.to_owned(),
file_format,
lhs_src: FileContent::Text("".into()),
rhs_src: FileContent::Text("".into()),
@ -559,7 +561,7 @@ fn diff_file_content(
let has_syntactic_changes = lhs != rhs;
return DiffResult {
extra_info,
display_path: display_path.to_string(),
display_path: display_path.to_owned(),
file_format: FileFormat::SupportedLanguage(language),
lhs_src: FileContent::Text(lhs_src.to_owned()),
rhs_src: FileContent::Text(rhs_src.to_owned()),
@ -700,7 +702,7 @@ fn diff_file_content(
DiffResult {
extra_info,
display_path: display_path.to_string(),
display_path: display_path.to_owned(),
file_format,
lhs_src: FileContent::Text(lhs_src.to_owned()),
rhs_src: FileContent::Text(rhs_src.to_owned()),

@ -635,7 +635,7 @@ pub(crate) fn parse_args() -> Mode {
if let Some(path) = matches.value_of("dump-syntax") {
return Mode::DumpSyntax {
path: path.to_string(),
path: path.to_owned(),
ignore_comments,
language_overrides,
};
@ -643,7 +643,7 @@ pub(crate) fn parse_args() -> Mode {
if let Some(path) = matches.value_of("dump-ts") {
return Mode::DumpTreeSitter {
path: path.to_string(),
path: path.to_owned(),
language_overrides,
};
}