Skip to content

Commit e3f047c

Browse files
committed
rollup merge of rust-lang#20653: alexcrichton/entry-unstable
There's been some debate over the precise form that these APIs should take, and they've undergone some changes recently, so these APIs are going to be left unstable for now to be fleshed out during the next release cycle.
2 parents ed61bd8 + 169fbed commit e3f047c

File tree

18 files changed

+77
-90
lines changed

18 files changed

+77
-90
lines changed

src/libcollections/btree/map.rs

Lines changed: 26 additions & 28 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;
@@ -128,24 +128,24 @@ pub struct Values<'a, K: 'a, V: 'a> {
128128
inner: Map<(&'a K, &'a V), &'a V, Iter<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>
129129
}
130130

131-
#[stable]
132131
/// 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> {
132+
#[unstable = "precise API still under development"]
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

140-
#[stable]
141140
/// A vacant Entry.
142-
pub struct VacantEntry<'a, Q: ?Sized +'a, K:'a, V:'a> {
143-
key: &'a Q,
141+
#[unstable = "precise API still under development"]
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

147-
#[stable]
148147
/// An occupied Entry.
148+
#[unstable = "precise API still under development"]
149149
pub struct OccupiedEntry<'a, K:'a, V:'a> {
150150
stack: stack::SearchStack<'a, K, V, node::handle::KV, node::handle::LeafOrInternal>,
151151
}
@@ -1111,55 +1111,55 @@ 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> {
1126-
#[stable]
1125+
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
11271126
/// Sets the value of the entry with the VacantEntry's key,
11281127
/// and returns a mutable reference to it.
1128+
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
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

11341134
impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
1135-
#[stable]
11361135
/// Gets a reference to the value in the entry.
1136+
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
11371137
pub fn get(&self) -> &V {
11381138
self.stack.peek()
11391139
}
11401140

1141-
#[stable]
11421141
/// Gets a mutable reference to the value in the entry.
1142+
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
11431143
pub fn get_mut(&mut self) -> &mut V {
11441144
self.stack.peek_mut()
11451145
}
11461146

1147-
#[stable]
11481147
/// Converts the entry into a mutable reference to its value.
1148+
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
11491149
pub fn into_mut(self) -> &'a mut V {
11501150
self.stack.into_top()
11511151
}
11521152

1153-
#[stable]
11541153
/// Sets the value of the entry with the OccupiedEntry's key,
11551154
/// and returns the entry's old value.
1155+
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
11561156
pub fn insert(&mut self, mut value: V) -> V {
11571157
mem::swap(self.stack.peek_mut(), &mut value);
11581158
value
11591159
}
11601160

1161-
#[stable]
11621161
/// Takes the value of the entry out of the map, and returns it.
1162+
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
11631163
pub fn remove(self) -> V {
11641164
self.stack.remove()
11651165
}
@@ -1361,15 +1361,13 @@ impl<K: Ord, V> BTreeMap<K, V> {
13611361
/// assert_eq!(count["a"], 3u);
13621362
/// ```
13631363
/// The key must have the same ordering before or after `.to_owned()` is called.
1364-
#[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-
{
1364+
#[unstable = "precise API still under development"]
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
@@ -5616,7 +5616,7 @@ pub fn lookup_field_type<'tcx>(tcx: &ctxt<'tcx>,
56165616
node_id_to_type(tcx, id.node)
56175617
} else {
56185618
let mut tcache = tcx.tcache.borrow_mut();
5619-
let pty = tcache.entry(&id).get().unwrap_or_else(
5619+
let pty = tcache.entry(id).get().unwrap_or_else(
56205620
|vacant_entry| vacant_entry.insert(csearch::get_field_type(tcx, struct_id, id)));
56215621
pty.ty
56225622
};
@@ -6755,7 +6755,7 @@ pub fn replace_late_bound_regions<'tcx, T, F>(
67556755
debug!("region={}", region.repr(tcx));
67566756
match region {
67576757
ty::ReLateBound(debruijn, br) if debruijn.depth == current_depth => {
6758-
* map.entry(&br).get().unwrap_or_else(
6758+
* map.entry(br).get().unwrap_or_else(
67596759
|vacant_entry| vacant_entry.insert(mapf(br, debruijn)))
67606760
}
67616761
_ => {

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
@@ -1688,7 +1688,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
16881688
let is_public = import_directive.is_public;
16891689

16901690
let mut import_resolutions = module_.import_resolutions.borrow_mut();
1691-
let dest_import_resolution = import_resolutions.entry(&name).get().unwrap_or_else(
1691+
let dest_import_resolution = import_resolutions.entry(name).get().unwrap_or_else(
16921692
|vacant_entry| {
16931693
// Create a new import resolution from this child.
16941694
vacant_entry.insert(ImportResolution::new(id, is_public))
@@ -2626,14 +2626,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
26262626
def = DefUpvar(node_id, function_id, last_proc_body_id);
26272627

26282628
let mut seen = self.freevars_seen.borrow_mut();
2629-
let seen = match seen.entry(&function_id) {
2629+
let seen = match seen.entry(function_id) {
26302630
Occupied(v) => v.into_mut(),
26312631
Vacant(v) => v.insert(NodeSet::new()),
26322632
};
26332633
if seen.contains(&node_id) {
26342634
continue;
26352635
}
2636-
match self.freevars.borrow_mut().entry(&function_id) {
2636+
match self.freevars.borrow_mut().entry(function_id) {
26372637
Occupied(v) => v.into_mut(),
26382638
Vacant(v) => v.insert(vec![]),
26392639
}.push(Freevar { def: prev_def, span: span });
@@ -4710,7 +4710,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
47104710
"Import should only be used for `use` directives");
47114711
self.last_private.insert(node_id, lp);
47124712

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

src/librustc_typeck/check/_match.rs

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

605605
// Typecheck each field.
606606
for &Spanned { node: ref field, span } in fields.iter() {
607-
let field_type = match used_fields.entry(&field.ident.name) {
607+
let field_type = match used_fields.entry(field.ident.name) {
608608
Occupied(occupied) => {
609609
span_err!(tcx.sess, span, E0025,
610610
"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
@@ -317,7 +317,7 @@ fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
317317
}
318318
};
319319
let name = name.to_string();
320-
let locs = externs.entry(&name).get().unwrap_or_else(
320+
let locs = externs.entry(name).get().unwrap_or_else(
321321
|vacant_entry| vacant_entry.insert(Vec::with_capacity(1)));
322322
locs.push(location.to_string());
323323
}

0 commit comments

Comments
 (0)