about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorQuentin Santos <qsantos@qsantos.fr>2025-01-01 22:14:17 +0100
committerQuentin Santos <qsantos@qsantos.fr>2025-01-01 22:16:07 +0100
commit7331cc0f81d97fbc4f4eb47890cb10fe7c275696 (patch)
tree11cc0dfa872775d78cef16f1990432e46f7c6e76 /tests
parent27acfd8a5b9dd1eb91e044e07201b4a9044a2bbd (diff)
Only complain about default Iterator::last()
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/double_ended_iterator_last.fixed18
-rw-r--r--tests/ui/double_ended_iterator_last.rs18
2 files changed, 36 insertions, 0 deletions
diff --git a/tests/ui/double_ended_iterator_last.fixed b/tests/ui/double_ended_iterator_last.fixed
index cfafd104576..06c48e33753 100644
--- a/tests/ui/double_ended_iterator_last.fixed
+++ b/tests/ui/double_ended_iterator_last.fixed
@@ -32,4 +32,22 @@ fn main() {
         }
     }
     let _ = SimpleIterator.last();
+
+    // Should not apply to custom implementations of last()
+    struct CustomLast;
+    impl Iterator for CustomLast {
+        type Item = ();
+        fn next(&mut self) -> Option<Self::Item> {
+            Some(())
+        }
+        fn last(self) -> Option<Self::Item> {
+            Some(())
+        }
+    }
+    impl DoubleEndedIterator for CustomLast {
+        fn next_back(&mut self) -> Option<Self::Item> {
+            Some(())
+        }
+    }
+    let _ = CustomLast.last();
 }
diff --git a/tests/ui/double_ended_iterator_last.rs b/tests/ui/double_ended_iterator_last.rs
index ae80fb64838..9c13b496d11 100644
--- a/tests/ui/double_ended_iterator_last.rs
+++ b/tests/ui/double_ended_iterator_last.rs
@@ -32,4 +32,22 @@ fn main() {
         }
     }
     let _ = SimpleIterator.last();
+
+    // Should not apply to custom implementations of last()
+    struct CustomLast;
+    impl Iterator for CustomLast {
+        type Item = ();
+        fn next(&mut self) -> Option<Self::Item> {
+            Some(())
+        }
+        fn last(self) -> Option<Self::Item> {
+            Some(())
+        }
+    }
+    impl DoubleEndedIterator for CustomLast {
+        fn next_back(&mut self) -> Option<Self::Item> {
+            Some(())
+        }
+    }
+    let _ = CustomLast.last();
 }