about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorSamuel Moelius <samuel.moelius@trailofbits.com>2022-11-04 16:01:44 +0000
committerSamuel Moelius <samuel.moelius@trailofbits.com>2022-11-04 16:02:12 +0000
commitf27ca5c00a96d2dbd1e2b5dceee918d829891bc1 (patch)
tree411c245fa7bc1d7f4ea58c97158d984a156589b0 /tests
parent704e00cb75ef5be2080d21be0965afd938d6fbec (diff)
downloadrust-f27ca5c00a96d2dbd1e2b5dceee918d829891bc1.tar.gz
rust-f27ca5c00a96d2dbd1e2b5dceee918d829891bc1.zip
Fix #9771 (`unnecessary_to_owned` false positive)
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/unnecessary_to_owned.fixed29
-rw-r--r--tests/ui/unnecessary_to_owned.rs29
2 files changed, 58 insertions, 0 deletions
diff --git a/tests/ui/unnecessary_to_owned.fixed b/tests/ui/unnecessary_to_owned.fixed
index fe09aad06bc..fadcf7f9c9e 100644
--- a/tests/ui/unnecessary_to_owned.fixed
+++ b/tests/ui/unnecessary_to_owned.fixed
@@ -426,3 +426,32 @@ mod issue_9504 {
         foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
     }
 }
+
+mod issue_9771a {
+    #![allow(dead_code)]
+
+    use std::marker::PhantomData;
+
+    pub struct Key<K: AsRef<[u8]>, V: ?Sized>(K, PhantomData<V>);
+
+    impl<K: AsRef<[u8]>, V: ?Sized> Key<K, V> {
+        pub fn new(key: K) -> Key<K, V> {
+            Key(key, PhantomData)
+        }
+    }
+
+    pub fn pkh(pkh: &[u8]) -> Key<Vec<u8>, String> {
+        Key::new([b"pkh-", pkh].concat().to_vec())
+    }
+}
+
+mod issue_9771b {
+    #![allow(dead_code)]
+
+    pub struct Key<K: AsRef<[u8]>>(K);
+
+    pub fn from(c: &[u8]) -> Key<Vec<u8>> {
+        let v = [c].concat();
+        Key(v.to_vec())
+    }
+}
diff --git a/tests/ui/unnecessary_to_owned.rs b/tests/ui/unnecessary_to_owned.rs
index 3de6d0903c0..fe6864b9e07 100644
--- a/tests/ui/unnecessary_to_owned.rs
+++ b/tests/ui/unnecessary_to_owned.rs
@@ -426,3 +426,32 @@ mod issue_9504 {
         foo(std::path::PathBuf::new().to_string_lossy().to_string()).await;
     }
 }
+
+mod issue_9771a {
+    #![allow(dead_code)]
+
+    use std::marker::PhantomData;
+
+    pub struct Key<K: AsRef<[u8]>, V: ?Sized>(K, PhantomData<V>);
+
+    impl<K: AsRef<[u8]>, V: ?Sized> Key<K, V> {
+        pub fn new(key: K) -> Key<K, V> {
+            Key(key, PhantomData)
+        }
+    }
+
+    pub fn pkh(pkh: &[u8]) -> Key<Vec<u8>, String> {
+        Key::new([b"pkh-", pkh].concat().to_vec())
+    }
+}
+
+mod issue_9771b {
+    #![allow(dead_code)]
+
+    pub struct Key<K: AsRef<[u8]>>(K);
+
+    pub fn from(c: &[u8]) -> Key<Vec<u8>> {
+        let v = [c].concat();
+        Key(v.to_vec())
+    }
+}