Skip to content

Commit 7c01721

Browse files
committed
Auto merge of rust-lang#10179 - llogiq:trim-suspicious-to-owned-paths, r=xFrednet
trim paths in `suspicious_to_owned` This continues my path trimming spree. I'm not going to add yet another changelog entry, we should have one "trim paths in some applicable lints" entry instead. --- changelog: none
2 parents a95286b + bd76d91 commit 7c01721

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

clippy_lints/src/methods/suspicious_to_owned.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use if_chain::if_chain;
55
use rustc_errors::Applicability;
66
use rustc_hir as hir;
77
use rustc_lint::LateContext;
8-
use rustc_middle::ty;
8+
use rustc_middle::ty::{self, print::with_forced_trimmed_paths};
99
use rustc_span::sym;
1010

1111
use super::SUSPICIOUS_TO_OWNED;
@@ -24,7 +24,9 @@ pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) -
2424
cx,
2525
SUSPICIOUS_TO_OWNED,
2626
expr.span,
27-
&format!("this `to_owned` call clones the {input_type} itself and does not cause the {input_type} contents to become owned"),
27+
&with_forced_trimmed_paths!(format!(
28+
"this `to_owned` call clones the {input_type} itself and does not cause the {input_type} contents to become owned"
29+
)),
2830
"consider using, depending on intent",
2931
format!("{recv_snip}.clone()` or `{recv_snip}.into_owned()"),
3032
app,

tests/ui/suspicious_to_owned.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned
1+
error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned
22
--> $DIR/suspicious_to_owned.rs:16:13
33
|
44
LL | let _ = cow.to_owned();
55
| ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()`
66
|
77
= note: `-D clippy::suspicious-to-owned` implied by `-D warnings`
88

9-
error: this `to_owned` call clones the std::borrow::Cow<'_, [char; 3]> itself and does not cause the std::borrow::Cow<'_, [char; 3]> contents to become owned
9+
error: this `to_owned` call clones the Cow<'_, [char; 3]> itself and does not cause the Cow<'_, [char; 3]> contents to become owned
1010
--> $DIR/suspicious_to_owned.rs:26:13
1111
|
1212
LL | let _ = cow.to_owned();
1313
| ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()`
1414

15-
error: this `to_owned` call clones the std::borrow::Cow<'_, std::vec::Vec<char>> itself and does not cause the std::borrow::Cow<'_, std::vec::Vec<char>> contents to become owned
15+
error: this `to_owned` call clones the Cow<'_, Vec<char>> itself and does not cause the Cow<'_, Vec<char>> contents to become owned
1616
--> $DIR/suspicious_to_owned.rs:36:13
1717
|
1818
LL | let _ = cow.to_owned();
1919
| ^^^^^^^^^^^^^^ help: consider using, depending on intent: `cow.clone()` or `cow.into_owned()`
2020

21-
error: this `to_owned` call clones the std::borrow::Cow<'_, str> itself and does not cause the std::borrow::Cow<'_, str> contents to become owned
21+
error: this `to_owned` call clones the Cow<'_, str> itself and does not cause the Cow<'_, str> contents to become owned
2222
--> $DIR/suspicious_to_owned.rs:46:13
2323
|
2424
LL | let _ = cow.to_owned();

0 commit comments

Comments
 (0)