Skip to content

Commit acd3cff

Browse files
committed
Deprecate string_to_string
1 parent c9d6a9a commit acd3cff

File tree

6 files changed

+10
-55
lines changed

6 files changed

+10
-55
lines changed

clippy_lints/src/declared_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,6 @@ pub static LINTS: &[&crate::LintInfo] = &[
703703
crate::strings::STRING_FROM_UTF8_AS_BYTES_INFO,
704704
crate::strings::STRING_LIT_AS_BYTES_INFO,
705705
crate::strings::STRING_SLICE_INFO,
706-
crate::strings::STRING_TO_STRING_INFO,
707706
crate::strings::STR_TO_STRING_INFO,
708707
crate::strings::TRIM_SPLIT_WHITESPACE_INFO,
709708
crate::strlen_on_c_strings::STRLEN_ON_C_STRINGS_INFO,

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

clippy_lints/src/lib.rs

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

clippy_lints/src/strings.rs

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

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

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() {}

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

0 commit comments

Comments
 (0)