summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/clippy/tests/ui/unnecessary_to_owned.fixed')
-rw-r--r--src/tools/clippy/tests/ui/unnecessary_to_owned.fixed88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
index f4f76cd3d..a920c63b1 100644
--- a/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
+++ b/src/tools/clippy/tests/ui/unnecessary_to_owned.fixed
@@ -329,3 +329,91 @@ mod issue_8759_variant {
rw.set_view(&rw.default_view().to_owned());
}
}
+
+mod issue_9317 {
+ #![allow(dead_code)]
+
+ struct Bytes {}
+
+ impl ToString for Bytes {
+ fn to_string(&self) -> String {
+ "123".to_string()
+ }
+ }
+
+ impl AsRef<[u8]> for Bytes {
+ fn as_ref(&self) -> &[u8] {
+ &[1, 2, 3]
+ }
+ }
+
+ fn consume<C: AsRef<[u8]>>(c: C) {
+ let _ = c;
+ }
+
+ pub fn main() {
+ let b = Bytes {};
+ // Should not lint.
+ consume(b.to_string());
+ }
+}
+
+mod issue_9351 {
+ #![allow(dead_code)]
+
+ use std::ops::Deref;
+ use std::path::{Path, PathBuf};
+
+ fn require_deref_path<T: Deref<Target = std::path::Path>>(x: T) -> T {
+ x
+ }
+
+ fn generic_arg_used_elsewhere<T: AsRef<Path>>(_x: T, _y: T) {}
+
+ fn id<T: AsRef<str>>(x: T) -> T {
+ x
+ }
+
+ fn predicates_are_satisfied(_x: impl std::fmt::Write) {}
+
+ // Should lint
+ fn single_return() -> impl AsRef<str> {
+ id("abc")
+ }
+
+ // Should not lint
+ fn multiple_returns(b: bool) -> impl AsRef<str> {
+ if b {
+ return String::new();
+ }
+
+ id("abc".to_string())
+ }
+
+ struct S1(String);
+
+ // Should not lint
+ fn fields1() -> S1 {
+ S1(id("abc".to_string()))
+ }
+
+ struct S2 {
+ s: String,
+ }
+
+ // Should not lint
+ fn fields2() {
+ let mut s = S2 { s: "abc".into() };
+ s.s = id("abc".to_string());
+ }
+
+ pub fn main() {
+ let path = std::path::Path::new("x");
+ let path_buf = path.to_owned();
+
+ // Should not lint.
+ let _x: PathBuf = require_deref_path(path.to_owned());
+ generic_arg_used_elsewhere(path.to_owned(), path_buf);
+ predicates_are_satisfied(id("abc".to_string()));
+ }
+}