Skip to content

Commit c7a116b

Browse files
committed
Deprecate string_to_string
1 parent 5ab48b6 commit c7a116b

9 files changed

+10
-82
lines changed

Diff for: clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,6 @@ pub static LINTS: &[&crate::LintInfo] = &[
697697
crate::strings::STRING_FROM_UTF8_AS_BYTES_INFO,
698698
crate::strings::STRING_LIT_AS_BYTES_INFO,
699699
crate::strings::STRING_SLICE_INFO,
700-
crate::strings::STRING_TO_STRING_INFO,
701700
crate::strings::STR_TO_STRING_INFO,
702701
crate::strings::TRIM_SPLIT_WHITESPACE_INFO,
703702
crate::strlen_on_c_strings::STRLEN_ON_C_STRINGS_INFO,

Diff for: clippy_lints/src/deprecated_lints.rs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION): &[(&str, &str)] = &[
4242
("clippy::wrong_pub_self_convention", "`clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config"),
4343
#[clippy::version = "1.86.0"]
4444
("clippy::option_map_or_err_ok", "`clippy::manual_ok_or` covers this case"),
45+
#[clippy::version = "1.86.0"]
46+
("clippy::string_to_string", "`clippy:implicit_clone` covers this case"),
4547
// end deprecated lints. used by `cargo dev deprecate_lint`
4648
]}
4749

Diff for: clippy_lints/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,6 @@ pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
820820
store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
821821
store.register_late_pass(|_| Box::new(empty_drop::EmptyDrop));
822822
store.register_late_pass(|_| Box::new(strings::StrToString));
823-
store.register_late_pass(|_| Box::new(strings::StringToString));
824823
store.register_late_pass(|_| Box::new(zero_sized_map_values::ZeroSizedMapValues));
825824
store.register_late_pass(|_| Box::<vec_init_then_push::VecInitThenPush>::default());
826825
store.register_late_pass(|_| Box::new(redundant_slicing::RedundantSlicing));

Diff for: clippy_lints/src/strings.rs

-52
Original file line numberDiff line numberDiff line change
@@ -410,58 +410,6 @@ impl<'tcx> LateLintPass<'tcx> for StrToString {
410410
}
411411
}
412412

413-
declare_clippy_lint! {
414-
/// ### What it does
415-
/// This lint checks for `.to_string()` method calls on values of type `String`.
416-
///
417-
/// ### Why restrict this?
418-
/// The `to_string` method is also used on other types to convert them to a string.
419-
/// When called on a `String` it only clones the `String`, which can be more specifically
420-
/// expressed with `.clone()`.
421-
///
422-
/// ### Example
423-
/// ```no_run
424-
/// let msg = String::from("Hello World");
425-
/// let _ = msg.to_string();
426-
/// ```
427-
/// Use instead:
428-
/// ```no_run
429-
/// let msg = String::from("Hello World");
430-
/// let _ = msg.clone();
431-
/// ```
432-
#[clippy::version = "pre 1.29.0"]
433-
pub STRING_TO_STRING,
434-
restriction,
435-
"using `to_string()` on a `String`, which should be `clone()`"
436-
}
437-
438-
declare_lint_pass!(StringToString => [STRING_TO_STRING]);
439-
440-
impl<'tcx> LateLintPass<'tcx> for StringToString {
441-
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'_>) {
442-
if expr.span.from_expansion() {
443-
return;
444-
}
445-
446-
if let ExprKind::MethodCall(path, self_arg, [], _) = &expr.kind
447-
&& path.ident.name == sym::to_string
448-
&& let ty = cx.typeck_results().expr_ty(self_arg)
449-
&& is_type_lang_item(cx, ty, LangItem::String)
450-
{
451-
#[expect(clippy::collapsible_span_lint_calls, reason = "rust-clippy#7797")]
452-
span_lint_and_then(
453-
cx,
454-
STRING_TO_STRING,
455-
expr.span,
456-
"`to_string()` called on a `String`",
457-
|diag| {
458-
diag.help("consider using `.clone()`");
459-
},
460-
);
461-
}
462-
}
463-
}
464-
465413
declare_clippy_lint! {
466414
/// ### What it does
467415
/// Warns about calling `str::trim` (or variants) before `str::split_whitespace`.

Diff for: tests/ui/deprecated.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
#![warn(clippy::pub_enum_variant_names)] //~ ERROR: lint `clippy::pub_enum_variant_names`
1717
#![warn(clippy::wrong_pub_self_convention)] //~ ERROR: lint `clippy::wrong_pub_self_convention`
1818
#![warn(clippy::option_map_or_err_ok)] //~ ERROR: lint `clippy::option_map_or_err_ok`
19+
#![warn(clippy::string_to_string)] //~ ERROR: lint `clippy::string_to_string`
1920

2021
fn main() {}

Diff for: tests/ui/deprecated.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,11 @@ error: lint `clippy::option_map_or_err_ok` has been removed: `clippy::manual_ok_
8585
LL | #![warn(clippy::option_map_or_err_ok)]
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

88-
error: aborting due to 14 previous errors
88+
error: lint `clippy::string_to_string` has been removed: `clippy:implicit_clone` covers this case
89+
--> tests/ui/deprecated.rs:19:9
90+
|
91+
LL | #![warn(clippy::string_to_string)]
92+
| ^^^^^^^^^^^^^^^^^^^^^^^^
93+
94+
error: aborting due to 15 previous errors
8995

Diff for: tests/ui/string_to_string.fixed

-8
This file was deleted.

Diff for: tests/ui/string_to_string.rs

-8
This file was deleted.

Diff for: tests/ui/string_to_string.stderr

-11
This file was deleted.

0 commit comments

Comments
 (0)