Skip to content

Commit 25eada1

Browse files
dylanedealexcrichton
authored andcommitted
[breaking change] Revert Entry behaviour to take keys by value.
1 parent 6539cb4 commit 25eada1

File tree

18 files changed

+60
-69
lines changed

18 files changed

+60
-69
lines changed

src/libcollections/btree/map.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub use self::Entry::*;
1919

2020
use core::prelude::*;
2121

22-
use core::borrow::{BorrowFrom, ToOwned};
22+
use core::borrow::BorrowFrom;
2323
use core::cmp::Ordering;
2424
use core::default::Default;
2525
use core::fmt::Show;
@@ -130,17 +130,17 @@ pub struct Values<'a, K: 'a, V: 'a> {
130130

131131
#[stable]
132132
/// A view into a single entry in a map, which may either be vacant or occupied.
133-
pub enum Entry<'a, Q: ?Sized +'a, K:'a, V:'a> {
133+
pub enum Entry<'a, K:'a, V:'a> {
134134
/// A vacant Entry
135-
Vacant(VacantEntry<'a, Q, K, V>),
135+
Vacant(VacantEntry<'a, K, V>),
136136
/// An occupied Entry
137137
Occupied(OccupiedEntry<'a, K, V>),
138138
}
139139

140140
#[stable]
141141
/// A vacant Entry.
142-
pub struct VacantEntry<'a, Q: ?Sized +'a, K:'a, V:'a> {
143-
key: &'a Q,
142+
pub struct VacantEntry<'a, K:'a, V:'a> {
143+
key: K,
144144
stack: stack::SearchStack<'a, K, V, node::handle::Edge, node::handle::Leaf>,
145145
}
146146

@@ -1111,23 +1111,23 @@ impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> {
11111111
#[stable]
11121112
impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {}
11131113

1114-
impl<'a, Q: ?Sized, K: Ord, V> Entry<'a, Q, K, V> {
1114+
impl<'a, K: Ord, V> Entry<'a, K, V> {
11151115
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
11161116
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
1117-
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, Q, K, V>> {
1117+
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
11181118
match self {
11191119
Occupied(entry) => Ok(entry.into_mut()),
11201120
Vacant(entry) => Err(entry),
11211121
}
11221122
}
11231123
}
11241124

1125-
impl<'a, Q: ?Sized + ToOwned<K>, K: Ord, V> VacantEntry<'a, Q, K, V> {
1125+
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
11261126
#[stable]
11271127
/// Sets the value of the entry with the VacantEntry's key,
11281128
/// and returns a mutable reference to it.
11291129
pub fn insert(self, value: V) -> &'a mut V {
1130-
self.stack.insert(self.key.to_owned(), value)
1130+
self.stack.insert(self.key, value)
11311131
}
11321132
}
11331133

@@ -1362,14 +1362,12 @@ impl<K: Ord, V> BTreeMap<K, V> {
13621362
/// ```
13631363
/// The key must have the same ordering before or after `.to_owned()` is called.
13641364
#[stable]
1365-
pub fn entry<'a, Q: ?Sized>(&'a mut self, mut key: &'a Q) -> Entry<'a, Q, K, V>
1366-
where Q: Ord + ToOwned<K>
1367-
{
1365+
pub fn entry<'a>(&'a mut self, mut key: K) -> Entry<'a, K, V> {
13681366
// same basic logic of `swap` and `pop`, blended together
13691367
let mut stack = stack::PartialSearchStack::new(self);
13701368
loop {
13711369
let result = stack.with(move |pusher, node| {
1372-
return match Node::search(node, key) {
1370+
return match Node::search(node, &key) {
13731371
Found(handle) => {
13741372
// Perfect match
13751373
Finished(Occupied(OccupiedEntry {
@@ -1412,7 +1410,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
14121410
#[cfg(test)]
14131411
mod test {
14141412
use prelude::*;
1415-
use std::borrow::{ToOwned, BorrowFrom};
1413+
use std::borrow::BorrowFrom;
14161414

14171415
use super::{BTreeMap, Occupied, Vacant};
14181416

@@ -1562,7 +1560,7 @@ mod test {
15621560
let mut map: BTreeMap<int, int> = xs.iter().map(|&x| x).collect();
15631561

15641562
// Existing key (insert)
1565-
match map.entry(&1) {
1563+
match map.entry(1) {
15661564
Vacant(_) => unreachable!(),
15671565
Occupied(mut view) => {
15681566
assert_eq!(view.get(), &10);
@@ -1574,7 +1572,7 @@ mod test {
15741572

15751573

15761574
// Existing key (update)
1577-
match map.entry(&2) {
1575+
match map.entry(2) {
15781576
Vacant(_) => unreachable!(),
15791577
Occupied(mut view) => {
15801578
let v = view.get_mut();
@@ -1585,7 +1583,7 @@ mod test {
15851583
assert_eq!(map.len(), 6);
15861584

15871585
// Existing key (take)
1588-
match map.entry(&3) {
1586+
match map.entry(3) {
15891587
Vacant(_) => unreachable!(),
15901588
Occupied(view) => {
15911589
assert_eq!(view.remove(), 30);
@@ -1596,7 +1594,7 @@ mod test {
15961594

15971595

15981596
// Inexistent key (insert)
1599-
match map.entry(&10) {
1597+
match map.entry(10) {
16001598
Occupied(_) => unreachable!(),
16011599
Vacant(view) => {
16021600
assert_eq!(*view.insert(1000), 1000);

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ impl UnusedMut {
13281328
let ident = path1.node;
13291329
if let ast::BindByValue(ast::MutMutable) = mode {
13301330
if !token::get_ident(ident).get().starts_with("_") {
1331-
match mutables.entry(&ident.name.uint()) {
1331+
match mutables.entry(ident.name.uint()) {
13321332
Vacant(entry) => { entry.insert(vec![id]); },
13331333
Occupied(mut entry) => { entry.get_mut().push(id); },
13341334
}

src/librustc/metadata/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'a> Context<'a> {
400400
info!("lib candidate: {}", path.display());
401401

402402
let hash_str = hash.to_string();
403-
let slot = candidates.entry(&hash_str).get().unwrap_or_else(
403+
let slot = candidates.entry(hash_str).get().unwrap_or_else(
404404
|vacant_entry| vacant_entry.insert((HashSet::new(), HashSet::new())));
405405
let (ref mut rlibs, ref mut dylibs) = *slot;
406406
if rlib {

src/librustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ pub fn const_expr_to_pat(tcx: &ty::ctxt, expr: &Expr) -> P<ast::Pat> {
311311

312312
ast::ExprCall(ref callee, ref args) => {
313313
let def = tcx.def_map.borrow()[callee.id].clone();
314-
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(&expr.id) {
314+
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(expr.id) {
315315
entry.insert(def);
316316
}
317317
let path = match def {

src/librustc/middle/infer/freshen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
6666
None => { }
6767
}
6868

69-
match self.freshen_map.entry(&key) {
69+
match self.freshen_map.entry(key) {
7070
Entry::Occupied(entry) => *entry.get(),
7171
Entry::Vacant(entry) => {
7272
let index = self.freshen_count;

src/librustc/middle/infer/region_inference/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a, 'tcx> ConstraintGraph<'a, 'tcx> {
137137
let mut node_ids = FnvHashMap::new();
138138
{
139139
let mut add_node = |&mut : node| {
140-
if let Vacant(e) = node_ids.entry(&node) {
140+
if let Vacant(e) = node_ids.entry(node) {
141141
e.insert(i);
142142
i += 1;
143143
}

src/librustc/middle/traits/fulfill.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,9 @@ fn register_region_obligation<'tcx>(tcx: &ty::ctxt<'tcx>,
437437
debug!("register_region_obligation({})",
438438
region_obligation.repr(tcx));
439439

440-
let body_id = region_obligation.cause.body_id;
441-
match region_obligations.entry(&body_id) {
440+
match region_obligations.entry(region_obligation.cause.body_id) {
442441
Vacant(entry) => { entry.insert(vec![region_obligation]); },
443442
Occupied(mut entry) => { entry.get_mut().push(region_obligation); },
444443
}
445444

446445
}
447-

src/librustc/middle/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5584,7 +5584,7 @@ pub fn lookup_field_type<'tcx>(tcx: &ctxt<'tcx>,
55845584
node_id_to_type(tcx, id.node)
55855585
} else {
55865586
let mut tcache = tcx.tcache.borrow_mut();
5587-
let pty = tcache.entry(&id).get().unwrap_or_else(
5587+
let pty = tcache.entry(id).get().unwrap_or_else(
55885588
|vacant_entry| vacant_entry.insert(csearch::get_field_type(tcx, struct_id, id)));
55895589
pty.ty
55905590
};
@@ -6747,7 +6747,7 @@ pub fn replace_late_bound_regions<'tcx, T, F>(
67476747
debug!("region={}", region.repr(tcx));
67486748
match region {
67496749
ty::ReLateBound(debruijn, br) if debruijn.depth == current_depth => {
6750-
* map.entry(&br).get().unwrap_or_else(
6750+
* map.entry(br).get().unwrap_or_else(
67516751
|vacant_entry| vacant_entry.insert(mapf(br, debruijn)))
67526752
}
67536753
_ => {

src/librustc/session/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
11151115
None => early_error("--extern value must be of the format `foo=bar`"),
11161116
};
11171117

1118-
match externs.entry(&name.to_string()) {
1118+
match externs.entry(name.to_string()) {
11191119
Vacant(entry) => { entry.insert(vec![location.to_string()]); },
11201120
Occupied(mut entry) => { entry.get_mut().push(location.to_string()); },
11211121
}

src/librustc_resolve/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,7 +1701,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17011701
let is_public = import_directive.is_public;
17021702

17031703
let mut import_resolutions = module_.import_resolutions.borrow_mut();
1704-
let dest_import_resolution = import_resolutions.entry(&name).get().unwrap_or_else(
1704+
let dest_import_resolution = import_resolutions.entry(name).get().unwrap_or_else(
17051705
|vacant_entry| {
17061706
// Create a new import resolution from this child.
17071707
vacant_entry.insert(ImportResolution::new(id, is_public))
@@ -2639,14 +2639,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26392639
def = DefUpvar(node_id, function_id, last_proc_body_id);
26402640

26412641
let mut seen = self.freevars_seen.borrow_mut();
2642-
let seen = match seen.entry(&function_id) {
2642+
let seen = match seen.entry(function_id) {
26432643
Occupied(v) => v.into_mut(),
26442644
Vacant(v) => v.insert(NodeSet::new()),
26452645
};
26462646
if seen.contains(&node_id) {
26472647
continue;
26482648
}
2649-
match self.freevars.borrow_mut().entry(&function_id) {
2649+
match self.freevars.borrow_mut().entry(function_id) {
26502650
Occupied(v) => v.into_mut(),
26512651
Vacant(v) => v.insert(vec![]),
26522652
}.push(Freevar { def: prev_def, span: span });
@@ -4723,7 +4723,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
47234723
"Import should only be used for `use` directives");
47244724
self.last_private.insert(node_id, lp);
47254725

4726-
match self.def_map.borrow_mut().entry(&node_id) {
4726+
match self.def_map.borrow_mut().entry(node_id) {
47274727
// Resolve appears to "resolve" the same ID multiple
47284728
// times, so here is a sanity check it at least comes to
47294729
// the same conclusion! - nmatsakis

src/librustc_typeck/check/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ pub fn check_struct_pat_fields<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,
603603

604604
// Typecheck each field.
605605
for &Spanned { node: ref field, span } in fields.iter() {
606-
let field_type = match used_fields.entry(&field.ident.name) {
606+
let field_type = match used_fields.entry(field.ident.name) {
607607
Occupied(occupied) => {
608608
span_err!(tcx.sess, span, E0025,
609609
"field `{}` bound multiple times in the pattern",

src/librustdoc/html/render.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ impl DocFolder for Cache {
821821
if let clean::ImplItem(ref i) = item.inner {
822822
match i.trait_ {
823823
Some(clean::ResolvedPath{ did, .. }) => {
824-
let v = self.implementors.entry(&did).get().unwrap_or_else(
824+
let v = self.implementors.entry(did).get().unwrap_or_else(
825825
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
826826
v.push(Implementor {
827827
def_id: item.def_id,
@@ -1011,7 +1011,7 @@ impl DocFolder for Cache {
10111011
};
10121012

10131013
if let Some(did) = did {
1014-
let v = self.impls.entry(&did).get().unwrap_or_else(
1014+
let v = self.impls.entry(did).get().unwrap_or_else(
10151015
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
10161016
v.push(Impl {
10171017
impl_: i,
@@ -1260,7 +1260,7 @@ impl Context {
12601260
Some(ref s) => s.to_string(),
12611261
};
12621262
let short = short.to_string();
1263-
let v = map.entry(&short).get().unwrap_or_else(
1263+
let v = map.entry(short).get().unwrap_or_else(
12641264
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
12651265
v.push(myname);
12661266
}

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
330330
}
331331
};
332332
let name = name.to_string();
333-
let locs = externs.entry(&name).get().unwrap_or_else(
333+
let locs = externs.entry(name).get().unwrap_or_else(
334334
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
335335
locs.push(location.to_string());
336336
}

0 commit comments

Comments
 (0)