Skip to content

Commit a635266

Browse files
committed
Add #[must_use] to constructors
Only the functions that match those in the standard library with `#[must_use]` annotations
1 parent ba0c71f commit a635266

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/map.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ impl<K, V> HashMap<K, V, DefaultHashBuilder> {
267267
/// assert_eq!(map.len(), 0);
268268
/// assert_eq!(map.capacity(), 0);
269269
/// ```
270+
#[must_use]
270271
#[cfg_attr(feature = "inline-more", inline)]
271272
pub fn new() -> Self {
272273
Self::default()
@@ -296,6 +297,7 @@ impl<K, V> HashMap<K, V, DefaultHashBuilder> {
296297
/// assert_eq!(map.len(), 0);
297298
/// assert!(map.capacity() >= 10);
298299
/// ```
300+
#[must_use]
299301
#[cfg_attr(feature = "inline-more", inline)]
300302
pub fn with_capacity(capacity: usize) -> Self {
301303
Self::with_capacity_and_hasher(capacity, DefaultHashBuilder::default())
@@ -342,6 +344,7 @@ impl<K, V, A: Allocator> HashMap<K, V, DefaultHashBuilder, A> {
342344
/// // And it also allocates some capacity
343345
/// assert!(map.capacity() > 1);
344346
/// ```
347+
#[must_use]
345348
#[cfg_attr(feature = "inline-more", inline)]
346349
pub fn new_in(alloc: A) -> Self {
347350
Self::with_hasher_in(DefaultHashBuilder::default(), alloc)
@@ -390,6 +393,7 @@ impl<K, V, A: Allocator> HashMap<K, V, DefaultHashBuilder, A> {
390393
/// // But its capacity isn't changed
391394
/// assert_eq!(map.capacity(), empty_map_capacity)
392395
/// ```
396+
#[must_use]
393397
#[cfg_attr(feature = "inline-more", inline)]
394398
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
395399
Self::with_capacity_and_hasher_in(capacity, DefaultHashBuilder::default(), alloc)

src/set.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl<T> HashSet<T, DefaultHashBuilder> {
148148
/// use hashbrown::HashSet;
149149
/// let set: HashSet<i32> = HashSet::new();
150150
/// ```
151+
#[must_use]
151152
#[cfg_attr(feature = "inline-more", inline)]
152153
pub fn new() -> Self {
153154
Self {
@@ -178,6 +179,7 @@ impl<T> HashSet<T, DefaultHashBuilder> {
178179
/// let set: HashSet<i32> = HashSet::with_capacity(10);
179180
/// assert!(set.capacity() >= 10);
180181
/// ```
182+
#[must_use]
181183
#[cfg_attr(feature = "inline-more", inline)]
182184
pub fn with_capacity(capacity: usize) -> Self {
183185
Self {
@@ -210,6 +212,7 @@ impl<T: Hash + Eq, A: Allocator> HashSet<T, DefaultHashBuilder, A> {
210212
/// use hashbrown::HashSet;
211213
/// let set: HashSet<i32> = HashSet::new();
212214
/// ```
215+
#[must_use]
213216
#[cfg_attr(feature = "inline-more", inline)]
214217
pub fn new_in(alloc: A) -> Self {
215218
Self {
@@ -240,6 +243,7 @@ impl<T: Hash + Eq, A: Allocator> HashSet<T, DefaultHashBuilder, A> {
240243
/// let set: HashSet<i32> = HashSet::with_capacity(10);
241244
/// assert!(set.capacity() >= 10);
242245
/// ```
246+
#[must_use]
243247
#[cfg_attr(feature = "inline-more", inline)]
244248
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
245249
Self {

src/table.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ impl<T> HashTable<T, Global> {
6666
/// assert_eq!(table.len(), 0);
6767
/// assert_eq!(table.capacity(), 0);
6868
/// ```
69+
#[must_use]
6970
pub const fn new() -> Self {
7071
Self {
7172
raw: RawTable::new(),
@@ -85,6 +86,7 @@ impl<T> HashTable<T, Global> {
8586
/// assert_eq!(table.len(), 0);
8687
/// assert!(table.capacity() >= 10);
8788
/// ```
89+
#[must_use]
8890
pub fn with_capacity(capacity: usize) -> Self {
8991
Self {
9092
raw: RawTable::with_capacity(capacity),
@@ -133,6 +135,7 @@ where
133135
/// # test()
134136
/// # }
135137
/// ```
138+
#[must_use]
136139
pub const fn new_in(alloc: A) -> Self {
137140
Self {
138141
raw: RawTable::new_in(alloc),
@@ -181,6 +184,7 @@ where
181184
/// # test()
182185
/// # }
183186
/// ```
187+
#[must_use]
184188
pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
185189
Self {
186190
raw: RawTable::with_capacity_in(capacity, alloc),

0 commit comments

Comments
 (0)