Skip to content

Commit 6ea22ad

Browse files
committed
Add ?Sized
1 parent 4138501 commit 6ea22ad

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/liballoc/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ impl<T> [T] {
981981
/// ```
982982
#[stable(feature = "rust1", since = "1.0.0")]
983983
pub fn contains<U>(&self, x: &U) -> bool
984-
where T: PartialEq<U>
984+
where U: ?Sized, T: PartialEq<U>
985985
{
986986
core_slice::SliceExt::contains(self, x)
987987
}

src/liballoc/tests/slice.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,7 @@ fn test_contains() {
10621062
assert!(!strings.contains(&String::from("A")));
10631063
assert!(strings.contains(&"AB"));
10641064
assert!(!strings.contains(&"BC"));
1065+
assert!(strings.contains("AB"));
10651066
}
10661067

10671068
#[test]

src/libcore/slice/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub trait SliceExt {
192192
fn as_mut_ptr(&mut self) -> *mut Self::Item;
193193

194194
#[stable(feature = "core", since = "1.6.0")]
195-
fn contains<U>(&self, x: &U) -> bool where Self::Item: PartialEq<U>;
195+
fn contains<U>(&self, x: &U) -> bool where U: ?Sized, Self::Item: PartialEq<U>;
196196

197197
#[stable(feature = "core", since = "1.6.0")]
198198
fn starts_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq;
@@ -618,7 +618,7 @@ impl<T> SliceExt for [T] {
618618
}
619619

620620
#[inline]
621-
fn contains<U>(&self, x: &U) -> bool where T: PartialEq<U> {
621+
fn contains<U>(&self, x: &U) -> bool where U: ?Sized, T: PartialEq<U> {
622622
self.iter().any(|e| e == x)
623623
}
624624

0 commit comments

Comments
 (0)