Skip to content

Commit 48859db

Browse files
Relax bounds on HashSet to match hashbrown
No functional changes are made, and all APIs are moved to strictly less restrictive bounds. These APIs changed from the old bound listed to the new bound: T: Hash + Eq -> T * new * with_capacity T: Eq + Hash, S: BuildHasher -> T * with_hasher * with_capacity_and_hasher * hasher T: Eq + Hash + Debug -> T: Debug S: BuildHasher -> S <HashSet as Debug> T: Eq + Hash -> T S: BuildHasher + Default -> S: Default <HashSet as Default>
1 parent 3b92689 commit 48859db

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

src/libstd/collections/hash/set.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct HashSet<T, S = RandomState> {
110110
map: HashMap<T, (), S>,
111111
}
112112

113-
impl<T: Hash + Eq> HashSet<T, RandomState> {
113+
impl<T> HashSet<T, RandomState> {
114114
/// Creates an empty `HashSet`.
115115
///
116116
/// The hash set is initially created with a capacity of 0, so it will not allocate until it
@@ -261,13 +261,7 @@ impl<T, S> HashSet<T, S> {
261261
pub fn clear(&mut self) {
262262
self.map.clear()
263263
}
264-
}
265264

266-
impl<T, S> HashSet<T, S>
267-
where
268-
T: Eq + Hash,
269-
S: BuildHasher,
270-
{
271265
/// Creates a new empty hash set which will use the given hasher to hash
272266
/// keys.
273267
///
@@ -340,7 +334,13 @@ where
340334
pub fn hasher(&self) -> &S {
341335
self.map.hasher()
342336
}
337+
}
343338

339+
impl<T, S> HashSet<T, S>
340+
where
341+
T: Eq + Hash,
342+
S: BuildHasher,
343+
{
344344
/// Reserves capacity for at least `additional` more elements to be inserted
345345
/// in the `HashSet`. The collection may reserve more space to avoid
346346
/// frequent reallocations.
@@ -896,8 +896,7 @@ where
896896
#[stable(feature = "rust1", since = "1.0.0")]
897897
impl<T, S> fmt::Debug for HashSet<T, S>
898898
where
899-
T: Eq + Hash + fmt::Debug,
900-
S: BuildHasher,
899+
T: fmt::Debug,
901900
{
902901
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
903902
f.debug_set().entries(self.iter()).finish()
@@ -945,8 +944,7 @@ where
945944
#[stable(feature = "rust1", since = "1.0.0")]
946945
impl<T, S> Default for HashSet<T, S>
947946
where
948-
T: Eq + Hash,
949-
S: BuildHasher + Default,
947+
S: Default,
950948
{
951949
/// Creates an empty `HashSet<T, S>` with the `Default` value for the hasher.
952950
#[inline]

src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.rs

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ pub fn no_debug() {
66
pub fn no_hash() {
77
use std::collections::HashSet;
88
let mut set = HashSet::new();
9-
//~^ ERROR arrays only have std trait implementations for lengths 0..=32
109
set.insert([0_usize; 33]);
1110
//~^ ERROR arrays only have std trait implementations for lengths 0..=32
1211
}

src/test/ui/const-generics/array-impls/core-traits-no-impls-length-33.stderr

+5-14
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,15 @@ LL | println!("{:?}", [0_usize; 33]);
88
= note: required by `std::fmt::Debug::fmt`
99

1010
error[E0277]: arrays only have std trait implementations for lengths 0..=32
11-
--> $DIR/core-traits-no-impls-length-33.rs:10:16
11+
--> $DIR/core-traits-no-impls-length-33.rs:9:16
1212
|
1313
LL | set.insert([0_usize; 33]);
1414
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[usize; 33]`
1515
|
1616
= note: required because of the requirements on the impl of `std::cmp::Eq` for `[usize; 33]`
1717

18-
error[E0277]: arrays only have std trait implementations for lengths 0..=32
19-
--> $DIR/core-traits-no-impls-length-33.rs:8:19
20-
|
21-
LL | let mut set = HashSet::new();
22-
| ^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[usize; 33]`
23-
|
24-
= note: required because of the requirements on the impl of `std::cmp::Eq` for `[usize; 33]`
25-
= note: required by `std::collections::HashSet::<T>::new`
26-
2718
error[E0369]: binary operation `==` cannot be applied to type `[usize; 33]`
28-
--> $DIR/core-traits-no-impls-length-33.rs:15:19
19+
--> $DIR/core-traits-no-impls-length-33.rs:14:19
2920
|
3021
LL | [0_usize; 33] == [1_usize; 33]
3122
| ------------- ^^ ------------- [usize; 33]
@@ -35,7 +26,7 @@ LL | [0_usize; 33] == [1_usize; 33]
3526
= note: an implementation of `std::cmp::PartialEq` might be missing for `[usize; 33]`
3627

3728
error[E0369]: binary operation `<` cannot be applied to type `[usize; 33]`
38-
--> $DIR/core-traits-no-impls-length-33.rs:20:19
29+
--> $DIR/core-traits-no-impls-length-33.rs:19:19
3930
|
4031
LL | [0_usize; 33] < [1_usize; 33]
4132
| ------------- ^ ------------- [usize; 33]
@@ -45,7 +36,7 @@ LL | [0_usize; 33] < [1_usize; 33]
4536
= note: an implementation of `std::cmp::PartialOrd` might be missing for `[usize; 33]`
4637

4738
error[E0277]: the trait bound `&[usize; 33]: std::iter::IntoIterator` is not satisfied
48-
--> $DIR/core-traits-no-impls-length-33.rs:25:14
39+
--> $DIR/core-traits-no-impls-length-33.rs:24:14
4940
|
5041
LL | for _ in &[0_usize; 33] {
5142
| ^^^^^^^^^^^^^^ the trait `std::iter::IntoIterator` is not implemented for `&[usize; 33]`
@@ -57,7 +48,7 @@ LL | for _ in &[0_usize; 33] {
5748
<&'a mut [T] as std::iter::IntoIterator>
5849
= note: required by `std::iter::IntoIterator::into_iter`
5950

60-
error: aborting due to 6 previous errors
51+
error: aborting due to 5 previous errors
6152

6253
Some errors have detailed explanations: E0277, E0369.
6354
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)