diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index d24d292a1ec9a..da6254092382d 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -981,7 +981,7 @@ impl [T] { /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn contains(&self, x: &U) -> bool - where T: PartialEq + where U: ?Sized, T: PartialEq { core_slice::SliceExt::contains(self, x) } diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 6afff7ef9182a..d1642b1cdc75f 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -1062,6 +1062,7 @@ fn test_contains() { assert!(!strings.contains(&String::from("A"))); assert!(strings.contains(&"AB")); assert!(!strings.contains(&"BC")); + assert!(strings.contains("AB")); } #[test] diff --git a/src/libcore/slice/mod.rs b/src/libcore/slice/mod.rs index e2a4e37252481..963923dbeddf9 100644 --- a/src/libcore/slice/mod.rs +++ b/src/libcore/slice/mod.rs @@ -192,7 +192,7 @@ pub trait SliceExt { fn as_mut_ptr(&mut self) -> *mut Self::Item; #[stable(feature = "core", since = "1.6.0")] - fn contains(&self, x: &U) -> bool where Self::Item: PartialEq; + fn contains(&self, x: &U) -> bool where U: ?Sized, Self::Item: PartialEq; #[stable(feature = "core", since = "1.6.0")] fn starts_with(&self, needle: &[Self::Item]) -> bool where Self::Item: PartialEq; @@ -618,7 +618,7 @@ impl SliceExt for [T] { } #[inline] - fn contains(&self, x: &U) -> bool where T: PartialEq { + fn contains(&self, x: &U) -> bool where U: ?Sized, T: PartialEq { self.iter().any(|e| e == x) }