Skip to content

Commit b69db01

Browse files
committed
changed function signature according to the rust library team request
1 parent 7ba6c5e commit b69db01

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

library/core/src/iter/traits/iterator.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::array;
2-
use crate::borrow::Borrow;
32
use crate::cmp::{self, Ordering};
43
use crate::num::NonZero;
54
use crate::ops::{ChangeOutputType, ControlFlow, FromResidual, Residual, Try};
@@ -4124,15 +4123,13 @@ pub trait Iterator {
41244123
/// assert!((1..1000).contain(&500));
41254124
/// ```
41264125
#[unstable(feature = "contains", reason = "new API", issue = "127494")]
4127-
fn contain<Q>(&mut self, item: Q) -> bool
4126+
fn contain<Q: Sized>(&mut self, item: Q) -> bool
41284127
where
4129-
Self::Item: PartialEq,
4130-
Q: Borrow<Self::Item>,
4128+
Self::Item: PartialEq<Q>,
41314129
Self: Sized,
41324130
{
4133-
let borrowed_item: &Self::Item = item.borrow();
41344131
for element in self {
4135-
if element == *borrowed_item {
4132+
if element == item {
41364133
return true;
41374134
}
41384135
}

library/core/tests/iter/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,3 @@ pub fn extend_for_unit() {
9999
}
100100
assert_eq!(x, 5);
101101
}
102-
103-
#[test]
104-
fn test_edge_case_handling_iterator_with_large_number_of_elements() {
105-
assert!((1..1000).contain(&500));
106-
}

library/core/tests/iter/traits/iterator.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ fn test_edge_case_handling_none_values() {
629629

630630
#[test]
631631
fn test_edge_case_handling_empty_iterator() {
632-
assert!(!vec![].iter().contain(&1));
632+
assert!(!Vec::<i32>::new().iter().contain(&1));
633633
}
634634

635635
#[test]
@@ -646,12 +646,31 @@ fn test_edge_case_handling_iterator_with_custom_struct() {
646646
assert!([Item { value: 1 }, Item { value: 2 }].iter().contain(&Item { value: 2 }));
647647
}
648648

649+
// #[test]
650+
// fn test_str_iterator_contain_string() {
651+
// assert!(["a", "b", "c"].iter().contain("b".to_owned()));
652+
// assert!(!["a", "b", "c"].iter().contain("d".to_owned()));
653+
// }
654+
649655
#[test]
650-
fn test_str_iterator_contain_string() {
651-
assert!([&"a", &"b", &"c"].iter().contain("b".to_string()));
652-
assert!(!&["a", "b", "c"].iter().contain("d".to_string()));
656+
fn test_str_iterator_contain_string_slice() {
657+
assert!(["a", "b", "c"].iter().contain(&"b"));
658+
assert!(!["a", "b", "c"].iter().contain(&"d"));
653659
}
654660

661+
#[test]
662+
fn test_string_iterator_contain_str_slice() {
663+
assert!(["a".to_owned(), "b".to_owned(), "c".to_owned()].iter().contain("b"));
664+
assert!(!["a".to_owned(), "b".to_owned(), "c".to_owned()].iter().contain("d"));
665+
}
666+
667+
668+
#[test]
669+
fn test_edge_case_handling_iterator_with_large_number_of_elements() {
670+
assert!((1..1000).contain(500));
671+
}
672+
673+
655674
// just tests by whether or not this compiles
656675
fn _empty_impl_all_auto_traits<T>() {
657676
use std::panic::{RefUnwindSafe, UnwindSafe};

0 commit comments

Comments
 (0)