Skip to content

Commit 3c815a6

Browse files
committedMay 2, 2024
Add UnordMap::try_insert
1 parent fe9c5e6 commit 3c815a6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed
 

‎compiler/rustc_data_structures/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#![feature(lazy_cell)]
2626
#![feature(lint_reasons)]
2727
#![feature(macro_metavar_expr)]
28+
#![feature(map_try_insert)]
2829
#![feature(maybe_uninit_uninit_array)]
2930
#![feature(min_specialization)]
3031
#![feature(negative_impls)]

‎compiler/rustc_data_structures/src/unord.rs

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use rustc_hash::{FxHashMap, FxHashSet};
66
use rustc_macros::{Decodable_Generic, Encodable_Generic};
7+
use std::collections::hash_map::OccupiedError;
78
use std::{
89
borrow::{Borrow, BorrowMut},
910
collections::hash_map::Entry,
@@ -469,6 +470,11 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
469470
self.inner.insert(k, v)
470471
}
471472

473+
#[inline]
474+
pub fn try_insert(&mut self, k: K, v: V) -> Result<&mut V, OccupiedError<'_, K, V>> {
475+
self.inner.try_insert(k, v)
476+
}
477+
472478
#[inline]
473479
pub fn contains_key<Q: ?Sized>(&self, k: &Q) -> bool
474480
where

0 commit comments

Comments
 (0)
Please sign in to comment.