mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #153204 - xtqqczze:must-use-map, r=Amanieu,joboet
Add `#[must_use]` attribute to `HashMap` and `HashSet` constructors - `new_in` - `with_capacity_and_hasher` - `with_capacity_and_hasher_in` - `with_hasher` - `with_hasher_in` See also: https://github.com/rust-lang/rust/issues/89692
This commit is contained in:
@@ -693,6 +693,7 @@ pub fn clear(&mut self) {
|
||||
/// map.insert(1, "a");
|
||||
/// ```
|
||||
#[unstable(feature = "btreemap_alloc", issue = "32838")]
|
||||
#[must_use]
|
||||
pub const fn new_in(alloc: A) -> BTreeMap<K, V, A> {
|
||||
BTreeMap { root: None, length: 0, alloc: ManuallyDrop::new(alloc), _marker: PhantomData }
|
||||
}
|
||||
|
||||
@@ -361,6 +361,7 @@ impl<T, A: Allocator + Clone> BTreeSet<T, A> {
|
||||
/// let mut set: BTreeSet<i32> = BTreeSet::new_in(Global);
|
||||
/// ```
|
||||
#[unstable(feature = "btreemap_alloc", issue = "32838")]
|
||||
#[must_use]
|
||||
pub const fn new_in(alloc: A) -> BTreeSet<T, A> {
|
||||
BTreeSet { map: BTreeMap::new_in(alloc) }
|
||||
}
|
||||
|
||||
@@ -357,6 +357,7 @@ impl<K, V, S> HashMap<K, V, S> {
|
||||
/// map.insert(1, 2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
|
||||
#[rustc_const_stable(feature = "const_collections_with_hasher", since = "1.85.0")]
|
||||
pub const fn with_hasher(hash_builder: S) -> HashMap<K, V, S> {
|
||||
@@ -389,6 +390,7 @@ pub const fn with_hasher(hash_builder: S) -> HashMap<K, V, S> {
|
||||
/// map.insert(1, 2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
|
||||
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashMap<K, V, S> {
|
||||
HashMap { base: base::HashMap::with_capacity_and_hasher(capacity, hasher) }
|
||||
@@ -409,6 +411,7 @@ impl<K, V, S, A: Allocator> HashMap<K, V, S, A> {
|
||||
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
|
||||
/// the `HashMap` to be useful, see its documentation for details.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub fn with_hasher_in(hash_builder: S, alloc: A) -> Self {
|
||||
HashMap { base: base::HashMap::with_hasher_in(hash_builder, alloc) }
|
||||
@@ -430,6 +433,7 @@ pub fn with_hasher_in(hash_builder: S, alloc: A) -> Self {
|
||||
/// the `HashMap` to be useful, see its documentation for details.
|
||||
///
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub fn with_capacity_and_hasher_in(capacity: usize, hash_builder: S, alloc: A) -> Self {
|
||||
HashMap { base: base::HashMap::with_capacity_and_hasher_in(capacity, hash_builder, alloc) }
|
||||
|
||||
@@ -229,6 +229,7 @@ impl<T, S> HashSet<T, S> {
|
||||
/// set.insert(2);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
|
||||
#[rustc_const_stable(feature = "const_collections_with_hasher", since = "1.85.0")]
|
||||
pub const fn with_hasher(hasher: S) -> HashSet<T, S> {
|
||||
@@ -261,6 +262,7 @@ pub const fn with_hasher(hasher: S) -> HashSet<T, S> {
|
||||
/// set.insert(1);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "hashmap_build_hasher", since = "1.7.0")]
|
||||
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> HashSet<T, S> {
|
||||
HashSet { base: base::HashSet::with_capacity_and_hasher(capacity, hasher) }
|
||||
@@ -281,6 +283,7 @@ impl<T, S, A: Allocator> HashSet<T, S, A> {
|
||||
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
|
||||
/// the `HashSet` to be useful, see its documentation for details.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub fn with_hasher_in(hasher: S, alloc: A) -> HashSet<T, S, A> {
|
||||
HashSet { base: base::HashSet::with_hasher_in(hasher, alloc) }
|
||||
@@ -301,6 +304,7 @@ pub fn with_hasher_in(hasher: S, alloc: A) -> HashSet<T, S, A> {
|
||||
/// The `hash_builder` passed should implement the [`BuildHasher`] trait for
|
||||
/// the `HashSet` to be useful, see its documentation for details.
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[unstable(feature = "allocator_api", issue = "32838")]
|
||||
pub fn with_capacity_and_hasher_in(capacity: usize, hasher: S, alloc: A) -> HashSet<T, S, A> {
|
||||
HashSet { base: base::HashSet::with_capacity_and_hasher_in(capacity, hasher, alloc) }
|
||||
|
||||
Reference in New Issue
Block a user