Skip to content

Commit 5230b8d

Browse files
committed
Add UnordMap::try_insert
1 parent a238816 commit 5230b8d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#![feature(lazy_cell)]
2727
#![feature(lint_reasons)]
2828
#![feature(macro_metavar_expr)]
29+
#![feature(map_try_insert)]
2930
#![feature(maybe_uninit_uninit_array)]
3031
#![feature(min_specialization)]
3132
#![feature(negative_impls)]

compiler/rustc_data_structures/src/unord.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! as required by the query system.
44
55
use rustc_hash::{FxHashMap, FxHashSet};
6+
use std::collections::hash_map::OccupiedError;
67
use std::{
78
borrow::{Borrow, BorrowMut},
89
collections::hash_map::Entry,
@@ -468,6 +469,11 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
468469
self.inner.insert(k, v)
469470
}
470471

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

0 commit comments

Comments
 (0)