Skip to content

Commit b48e9ea

Browse files
committed
Deprecate inefficient_to_string
The compiler now generates similar code with and without the `with_ref` cfg: ```rust fn f(x: impl IntoIterator<Item = String>) { for y in x { println!("{y}"); } } fn main() { #[cfg(with_ref)] let a = ["foo", "bar"].iter().map(|&s| s.to_string()); #[cfg(not(with_ref))] let a = ["foo", "bar"].iter().map(|s| s.to_string()); f(a); } ``` The generated code is strictly identical with `-O`, and identical modulo some minor reordering without.
1 parent d99cf5c commit b48e9ea

File tree

9 files changed

+24
-239
lines changed

9 files changed

+24
-239
lines changed

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
383383
crate::methods::GET_LAST_WITH_LEN_INFO,
384384
crate::methods::GET_UNWRAP_INFO,
385385
crate::methods::IMPLICIT_CLONE_INFO,
386-
crate::methods::INEFFICIENT_TO_STRING_INFO,
387386
crate::methods::INSPECT_FOR_EACH_INFO,
388387
crate::methods::INTO_ITER_ON_REF_INFO,
389388
crate::methods::IO_OTHER_ERROR_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION) = [
1818
("clippy::assign_ops", "compound operators are harmless and linting on them is not in scope for clippy"),
1919
#[clippy::version = "pre 1.29.0"]
2020
("clippy::extend_from_slice", "`Vec::extend_from_slice` is no longer faster than `Vec::extend` due to specialization"),
21+
#[clippy::version = "1.92.0"]
22+
("clippy::inefficient_to_string", "compiler now generates identical code for both code variants"),
2123
#[clippy::version = "1.86.0"]
2224
("clippy::match_on_vec_items", "`clippy::indexing_slicing` covers indexing and slicing on `Vec<_>`"),
2325
#[clippy::version = "pre 1.29.0"]

clippy_lints/src/methods/inefficient_to_string.rs

Lines changed: 0 additions & 69 deletions
This file was deleted.

clippy_lints/src/methods/mod.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ mod get_first;
3333
mod get_last_with_len;
3434
mod get_unwrap;
3535
mod implicit_clone;
36-
mod inefficient_to_string;
3736
mod inspect_for_each;
3837
mod into_iter_on_ref;
3938
mod io_other_error;
@@ -1074,30 +1073,6 @@ declare_clippy_lint! {
10741073
"using `clone` on a ref-counted pointer"
10751074
}
10761075

1077-
declare_clippy_lint! {
1078-
/// ### What it does
1079-
/// Checks for usage of `.to_string()` on an `&&T` where
1080-
/// `T` implements `ToString` directly (like `&&str` or `&&String`).
1081-
///
1082-
/// ### Why is this bad?
1083-
/// This bypasses the specialized implementation of
1084-
/// `ToString` and instead goes through the more expensive string formatting
1085-
/// facilities.
1086-
///
1087-
/// ### Example
1088-
/// ```no_run
1089-
/// // Generic implementation for `T: Display` is used (slow)
1090-
/// ["foo", "bar"].iter().map(|s| s.to_string());
1091-
///
1092-
/// // OK, the specialized impl is used
1093-
/// ["foo", "bar"].iter().map(|&s| s.to_string());
1094-
/// ```
1095-
#[clippy::version = "1.40.0"]
1096-
pub INEFFICIENT_TO_STRING,
1097-
pedantic,
1098-
"using `to_string` on `&&T` where `T: ToString`"
1099-
}
1100-
11011076
declare_clippy_lint! {
11021077
/// ### What it does
11031078
/// Checks for `new` not returning a type that contains `Self`.
@@ -4692,7 +4667,6 @@ impl_lint_pass!(Methods => [
46924667
ITER_OVEREAGER_CLONED,
46934668
CLONED_INSTEAD_OF_COPIED,
46944669
FLAT_MAP_OPTION,
4695-
INEFFICIENT_TO_STRING,
46964670
NEW_RET_NO_SELF,
46974671
SINGLE_CHAR_ADD_STR,
46984672
SEARCH_IS_SOME,
@@ -4868,7 +4842,6 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
48684842
);
48694843
clone_on_copy::check(cx, expr, method_call.ident.name, receiver, args);
48704844
clone_on_ref_ptr::check(cx, expr, method_call.ident.name, receiver, args);
4871-
inefficient_to_string::check(cx, expr, method_call.ident.name, receiver, args);
48724845
single_char_add_str::check(cx, expr, receiver, args);
48734846
into_iter_on_ref::check(cx, expr, method_span, method_call.ident.name, receiver);
48744847
unnecessary_to_owned::check(cx, expr, method_call.ident.name, receiver, args, self.msrv);

tests/ui/deprecated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#![warn(clippy::assign_ops)] //~ ERROR: lint `clippy::assign_ops`
66
#![warn(clippy::extend_from_slice)] //~ ERROR: lint `clippy::extend_from_slice`
7+
#![warn(clippy::inefficient_to_string)] //~ ERROR: lint `clippy::inefficient_to_string`
78
#![warn(clippy::match_on_vec_items)] //~ ERROR: lint `clippy::match_on_vec_items`
89
#![warn(clippy::misaligned_transmute)] //~ ERROR: lint `clippy::misaligned_transmute`
910
#![warn(clippy::option_map_or_err_ok)] //~ ERROR: lint `clippy::option_map_or_err_ok`

tests/ui/deprecated.stderr

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,89 +13,95 @@ error: lint `clippy::extend_from_slice` has been removed: `Vec::extend_from_slic
1313
LL | #![warn(clippy::extend_from_slice)]
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^
1515

16-
error: lint `clippy::match_on_vec_items` has been removed: `clippy::indexing_slicing` covers indexing and slicing on `Vec<_>`
16+
error: lint `clippy::inefficient_to_string` has been removed: compiler now generates identical code for both code variants
1717
--> tests/ui/deprecated.rs:7:9
1818
|
19+
LL | #![warn(clippy::inefficient_to_string)]
20+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
22+
error: lint `clippy::match_on_vec_items` has been removed: `clippy::indexing_slicing` covers indexing and slicing on `Vec<_>`
23+
--> tests/ui/deprecated.rs:8:9
24+
|
1925
LL | #![warn(clippy::match_on_vec_items)]
2026
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
2127

2228
error: lint `clippy::misaligned_transmute` has been removed: split into `clippy::cast_ptr_alignment` and `clippy::transmute_ptr_to_ptr`
23-
--> tests/ui/deprecated.rs:8:9
29+
--> tests/ui/deprecated.rs:9:9
2430
|
2531
LL | #![warn(clippy::misaligned_transmute)]
2632
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2733

2834
error: lint `clippy::option_map_or_err_ok` has been removed: `clippy::manual_ok_or` covers this case
29-
--> tests/ui/deprecated.rs:9:9
35+
--> tests/ui/deprecated.rs:10:9
3036
|
3137
LL | #![warn(clippy::option_map_or_err_ok)]
3238
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3339

3440
error: lint `clippy::pub_enum_variant_names` has been removed: `clippy::enum_variant_names` now covers this case via the `avoid-breaking-exported-api` config
35-
--> tests/ui/deprecated.rs:10:9
41+
--> tests/ui/deprecated.rs:11:9
3642
|
3743
LL | #![warn(clippy::pub_enum_variant_names)]
3844
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3945

4046
error: lint `clippy::range_step_by_zero` has been removed: `Iterator::step_by(0)` now panics and is no longer an infinite iterator
41-
--> tests/ui/deprecated.rs:11:9
47+
--> tests/ui/deprecated.rs:12:9
4248
|
4349
LL | #![warn(clippy::range_step_by_zero)]
4450
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
4551

4652
error: lint `clippy::regex_macro` has been removed: the `regex!` macro was removed from the regex crate in 2018
47-
--> tests/ui/deprecated.rs:12:9
53+
--> tests/ui/deprecated.rs:13:9
4854
|
4955
LL | #![warn(clippy::regex_macro)]
5056
| ^^^^^^^^^^^^^^^^^^^
5157

5258
error: lint `clippy::replace_consts` has been removed: `min_value` and `max_value` are now deprecated
53-
--> tests/ui/deprecated.rs:13:9
59+
--> tests/ui/deprecated.rs:14:9
5460
|
5561
LL | #![warn(clippy::replace_consts)]
5662
| ^^^^^^^^^^^^^^^^^^^^^^
5763

5864
error: lint `clippy::should_assert_eq` has been removed: `assert!(a == b)` can now print the values the same way `assert_eq!(a, b) can
59-
--> tests/ui/deprecated.rs:14:9
65+
--> tests/ui/deprecated.rs:15:9
6066
|
6167
LL | #![warn(clippy::should_assert_eq)]
6268
| ^^^^^^^^^^^^^^^^^^^^^^^^
6369

6470
error: lint `clippy::string_to_string` has been removed: `clippy:implicit_clone` covers those cases
65-
--> tests/ui/deprecated.rs:15:9
71+
--> tests/ui/deprecated.rs:16:9
6672
|
6773
LL | #![warn(clippy::string_to_string)]
6874
| ^^^^^^^^^^^^^^^^^^^^^^^^
6975

7076
error: lint `clippy::unsafe_vector_initialization` has been removed: the suggested alternative could be substantially slower
71-
--> tests/ui/deprecated.rs:16:9
77+
--> tests/ui/deprecated.rs:17:9
7278
|
7379
LL | #![warn(clippy::unsafe_vector_initialization)]
7480
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7581

7682
error: lint `clippy::unstable_as_mut_slice` has been removed: `Vec::as_mut_slice` is now stable
77-
--> tests/ui/deprecated.rs:17:9
83+
--> tests/ui/deprecated.rs:18:9
7884
|
7985
LL | #![warn(clippy::unstable_as_mut_slice)]
8086
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8187

8288
error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` is now stable
83-
--> tests/ui/deprecated.rs:18:9
89+
--> tests/ui/deprecated.rs:19:9
8490
|
8591
LL | #![warn(clippy::unstable_as_slice)]
8692
| ^^^^^^^^^^^^^^^^^^^^^^^^^
8793

8894
error: lint `clippy::unused_collect` has been removed: `Iterator::collect` is now marked as `#[must_use]`
89-
--> tests/ui/deprecated.rs:19:9
95+
--> tests/ui/deprecated.rs:20:9
9096
|
9197
LL | #![warn(clippy::unused_collect)]
9298
| ^^^^^^^^^^^^^^^^^^^^^^
9399

94100
error: lint `clippy::wrong_pub_self_convention` has been removed: `clippy::wrong_self_convention` now covers this case via the `avoid-breaking-exported-api` config
95-
--> tests/ui/deprecated.rs:20:9
101+
--> tests/ui/deprecated.rs:21:9
96102
|
97103
LL | #![warn(clippy::wrong_pub_self_convention)]
98104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99105

100-
error: aborting due to 16 previous errors
106+
error: aborting due to 17 previous errors
101107

tests/ui/inefficient_to_string.fixed

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/ui/inefficient_to_string.rs

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/ui/inefficient_to_string.stderr

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)