diff options
| author | Josh Stone <jistone@redhat.com> | 2019-05-16 16:21:31 -0700 |
|---|---|---|
| committer | Josh Stone <jistone@redhat.com> | 2019-05-16 16:21:31 -0700 |
| commit | 9161a4dbefd613fd86fab4bfea88ad93c55fb4da (patch) | |
| tree | 02dbbc4fe5be236892da63588c10391f7415d20b /src/libstd/collections | |
| parent | 5e2c9d38e9300239ebd1127cc0ed7424e9af3867 (diff) | |
| download | rust-9161a4dbefd613fd86fab4bfea88ad93c55fb4da.tar.gz rust-9161a4dbefd613fd86fab4bfea88ad93c55fb4da.zip | |
Comment why get_or_insert returns &T
Diffstat (limited to 'src/libstd/collections')
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index c3903806127..403914c0707 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -637,6 +637,8 @@ impl<T, S> HashSet<T, S> #[inline] #[unstable(feature = "hash_set_entry", issue = "60896")] pub fn get_or_insert(&mut self, value: T) -> &T { + // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with + // `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`. self.map.raw_entry_mut().from_key(&value).or_insert(value, ()).0 } @@ -667,6 +669,8 @@ impl<T, S> HashSet<T, S> Q: Hash + Eq, F: FnOnce(&Q) -> T { + // Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with + // `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`. self.map.raw_entry_mut().from_key(value).or_insert_with(|| (f(value), ())).0 } |
