Skip to content

Commit 12a8b6f

Browse files
committed
---
yaml --- r: 168827 b: refs/heads/snap-stage3 c: 1f732ef h: refs/heads/master i: 168825: 0d83a96 168823: 4831bb9 v: v3
1 parent bce33f8 commit 12a8b6f

File tree

53 files changed

+386
-175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+386
-175
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5e21e17d9638d14af41e27e5ca9a21c8a1bc0170
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 990a79f097e8e74308bfec6d72dcdbb769a7973b
4+
refs/heads/snap-stage3: 1f732ef53d54ccfc3e7728390ffbcea8a696ecee
55
refs/heads/try: 5204084bd2e46af7cc6e0147430e44dd0d657bbb
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/libcollections/bench.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use prelude::*;
1212
use std::rand;
1313
use std::rand::Rng;
14-
use test::Bencher;
14+
use test::{Bencher, black_box};
1515

1616
pub fn insert_rand_n<M, I, R>(n: uint,
1717
map: &mut M,
@@ -33,7 +33,8 @@ pub fn insert_rand_n<M, I, R>(n: uint,
3333
let k = rng.gen::<uint>() % n;
3434
insert(map, k);
3535
remove(map, k);
36-
})
36+
});
37+
black_box(map);
3738
}
3839

3940
pub fn insert_seq_n<M, I, R>(n: uint,
@@ -55,7 +56,8 @@ pub fn insert_seq_n<M, I, R>(n: uint,
5556
insert(map, i);
5657
remove(map, i);
5758
i = (i + 2) % n;
58-
})
59+
});
60+
black_box(map);
5961
}
6062

6163
pub fn find_rand_n<M, T, I, F>(n: uint,
@@ -82,7 +84,7 @@ pub fn find_rand_n<M, T, I, F>(n: uint,
8284
b.iter(|| {
8385
let t = find(map, keys[i]);
8486
i = (i + 1) % n;
85-
t
87+
black_box(t);
8688
})
8789
}
8890

@@ -104,6 +106,6 @@ pub fn find_seq_n<M, T, I, F>(n: uint,
104106
b.iter(|| {
105107
let x = find(map, i);
106108
i = (i + 1) % n;
107-
x
109+
black_box(x);
108110
})
109111
}

branches/snap-stage3/src/libcollections/btree/map.rs

Lines changed: 45 additions & 21 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;
22+
use core::borrow::{BorrowFrom, ToOwned};
2323
use core::cmp::Ordering;
2424
use core::default::Default;
2525
use core::fmt::Show;
@@ -128,20 +128,23 @@ 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]
131132
/// A view into a single entry in a map, which may either be vacant or occupied.
132-
pub enum Entry<'a, K:'a, V:'a> {
133+
pub enum Entry<'a, Sized? Q:'a, K:'a, V:'a> {
133134
/// A vacant Entry
134-
Vacant(VacantEntry<'a, K, V>),
135+
Vacant(VacantEntry<'a, Q, K, V>),
135136
/// An occupied Entry
136137
Occupied(OccupiedEntry<'a, K, V>),
137138
}
138139

140+
#[stable]
139141
/// A vacant Entry.
140-
pub struct VacantEntry<'a, K:'a, V:'a> {
141-
key: K,
142+
pub struct VacantEntry<'a, Sized? Q:'a, K:'a, V:'a> {
143+
key: &'a Q,
142144
stack: stack::SearchStack<'a, K, V, node::handle::Edge, node::handle::Leaf>,
143145
}
144146

147+
#[stable]
145148
/// An occupied Entry.
146149
pub struct OccupiedEntry<'a, K:'a, V:'a> {
147150
stack: stack::SearchStack<'a, K, V, node::handle::KV, node::handle::LeafOrInternal>,
@@ -1132,40 +1135,56 @@ impl<'a, K, V> DoubleEndedIterator for Values<'a, K, V> {
11321135
#[stable]
11331136
impl<'a, K, V> ExactSizeIterator for Values<'a, K, V> {}
11341137

1138+
impl<'a, Sized? Q, K: Ord, V> Entry<'a, Q, K, V> {
1139+
#[unstable = "matches collection reform v2 specification, waiting for dust to settle"]
1140+
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
1141+
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, Q, K, V>> {
1142+
match self {
1143+
Occupied(entry) => Ok(entry.into_mut()),
1144+
Vacant(entry) => Err(entry),
1145+
}
1146+
}
1147+
}
11351148

1136-
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
1149+
impl<'a, Sized? Q: ToOwned<K>, K: Ord, V> VacantEntry<'a, Q, K, V> {
1150+
#[stable]
11371151
/// Sets the value of the entry with the VacantEntry's key,
11381152
/// and returns a mutable reference to it.
1139-
pub fn set(self, value: V) -> &'a mut V {
1140-
self.stack.insert(self.key, value)
1153+
pub fn insert(self, value: V) -> &'a mut V {
1154+
self.stack.insert(self.key.to_owned(), value)
11411155
}
11421156
}
11431157

11441158
impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
1159+
#[stable]
11451160
/// Gets a reference to the value in the entry.
11461161
pub fn get(&self) -> &V {
11471162
self.stack.peek()
11481163
}
11491164

1165+
#[stable]
11501166
/// Gets a mutable reference to the value in the entry.
11511167
pub fn get_mut(&mut self) -> &mut V {
11521168
self.stack.peek_mut()
11531169
}
11541170

1171+
#[stable]
11551172
/// Converts the entry into a mutable reference to its value.
11561173
pub fn into_mut(self) -> &'a mut V {
11571174
self.stack.into_top()
11581175
}
11591176

1177+
#[stable]
11601178
/// Sets the value of the entry with the OccupiedEntry's key,
11611179
/// and returns the entry's old value.
1162-
pub fn set(&mut self, mut value: V) -> V {
1180+
pub fn insert(&mut self, mut value: V) -> V {
11631181
mem::swap(self.stack.peek_mut(), &mut value);
11641182
value
11651183
}
11661184

1185+
#[stable]
11671186
/// Takes the value of the entry out of the map, and returns it.
1168-
pub fn take(self) -> V {
1187+
pub fn remove(self) -> V {
11691188
self.stack.remove()
11701189
}
11711190
}
@@ -1352,9 +1371,9 @@ impl<K: Ord, V> BTreeMap<K, V> {
13521371
///
13531372
/// // count the number of occurrences of letters in the vec
13541373
/// for x in vec!["a","b","a","c","a","b"].iter() {
1355-
/// match count.entry(*x) {
1374+
/// match count.entry(x) {
13561375
/// Entry::Vacant(view) => {
1357-
/// view.set(1);
1376+
/// view.insert(1);
13581377
/// },
13591378
/// Entry::Occupied(mut view) => {
13601379
/// let v = view.get_mut();
@@ -1365,12 +1384,16 @@ impl<K: Ord, V> BTreeMap<K, V> {
13651384
///
13661385
/// assert_eq!(count["a"], 3u);
13671386
/// ```
1368-
pub fn entry<'a>(&'a mut self, mut key: K) -> Entry<'a, K, V> {
1387+
/// The key must have the same ordering before or after `.to_owned()` is called.
1388+
#[stable]
1389+
pub fn entry<'a, Sized? Q>(&'a mut self, mut key: &'a Q) -> Entry<'a, Q, K, V>
1390+
where Q: Ord + ToOwned<K>
1391+
{
13691392
// same basic logic of `swap` and `pop`, blended together
13701393
let mut stack = stack::PartialSearchStack::new(self);
13711394
loop {
13721395
let result = stack.with(move |pusher, node| {
1373-
return match Node::search(node, &key) {
1396+
return match Node::search(node, key) {
13741397
Found(handle) => {
13751398
// Perfect match
13761399
Finished(Occupied(OccupiedEntry {
@@ -1413,6 +1436,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
14131436
#[cfg(test)]
14141437
mod test {
14151438
use prelude::*;
1439+
use std::borrow::{ToOwned, BorrowFrom};
14161440

14171441
use super::{BTreeMap, Occupied, Vacant};
14181442

@@ -1562,19 +1586,19 @@ mod test {
15621586
let mut map: BTreeMap<int, int> = xs.iter().map(|&x| x).collect();
15631587

15641588
// Existing key (insert)
1565-
match map.entry(1) {
1589+
match map.entry(&1) {
15661590
Vacant(_) => unreachable!(),
15671591
Occupied(mut view) => {
15681592
assert_eq!(view.get(), &10);
1569-
assert_eq!(view.set(100), 10);
1593+
assert_eq!(view.insert(100), 10);
15701594
}
15711595
}
15721596
assert_eq!(map.get(&1).unwrap(), &100);
15731597
assert_eq!(map.len(), 6);
15741598

15751599

15761600
// Existing key (update)
1577-
match map.entry(2) {
1601+
match map.entry(&2) {
15781602
Vacant(_) => unreachable!(),
15791603
Occupied(mut view) => {
15801604
let v = view.get_mut();
@@ -1585,21 +1609,21 @@ mod test {
15851609
assert_eq!(map.len(), 6);
15861610

15871611
// Existing key (take)
1588-
match map.entry(3) {
1612+
match map.entry(&3) {
15891613
Vacant(_) => unreachable!(),
15901614
Occupied(view) => {
1591-
assert_eq!(view.take(), 30);
1615+
assert_eq!(view.remove(), 30);
15921616
}
15931617
}
15941618
assert_eq!(map.get(&3), None);
15951619
assert_eq!(map.len(), 5);
15961620

15971621

15981622
// Inexistent key (insert)
1599-
match map.entry(10) {
1623+
match map.entry(&10) {
16001624
Occupied(_) => unreachable!(),
16011625
Vacant(view) => {
1602-
assert_eq!(*view.set(1000), 1000);
1626+
assert_eq!(*view.insert(1000), 1000);
16031627
}
16041628
}
16051629
assert_eq!(map.get(&10).unwrap(), &1000);

branches/snap-stage3/src/librustc/lint/builtin.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,8 +1329,8 @@ impl UnusedMut {
13291329
let ident = path1.node;
13301330
if let ast::BindByValue(ast::MutMutable) = mode {
13311331
if !token::get_ident(ident).get().starts_with("_") {
1332-
match mutables.entry(ident.name.uint()) {
1333-
Vacant(entry) => { entry.set(vec![id]); },
1332+
match mutables.entry(&ident.name.uint()) {
1333+
Vacant(entry) => { entry.insert(vec![id]); },
13341334
Occupied(mut entry) => { entry.get_mut().push(id); },
13351335
}
13361336
}
@@ -1762,7 +1762,7 @@ impl LintPass for Stability {
17621762
}
17631763
}
17641764
}
1765-
ast::ItemImpl(_, _, Some(ref t), _, _) => {
1765+
ast::ItemImpl(_, _, _, Some(ref t), _, _) => {
17661766
let id = ty::trait_ref_to_def_id(cx.tcx, t);
17671767
self.lint(cx, id, t.path.span);
17681768
}

branches/snap-stage3/src/librustc/metadata/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,5 @@ pub const tag_unsafety: uint = 0xb1;
259259

260260
pub const tag_associated_type_names: uint = 0xb2;
261261
pub const tag_associated_type_name: uint = 0xb3;
262+
263+
pub const tag_polarity: uint = 0xb4;

branches/snap-stage3/src/librustc/metadata/creader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ fn dump_crates(cstore: &CStore) {
8787
fn warn_if_multiple_versions(diag: &SpanHandler, cstore: &CStore) {
8888
let mut map = FnvHashMap::new();
8989
cstore.iter_crate_data(|cnum, data| {
90-
match map.entry(data.name()) {
91-
Vacant(entry) => { entry.set(vec![cnum]); },
90+
match map.entry(&data.name()) {
91+
Vacant(entry) => { entry.insert(vec![cnum]); },
9292
Occupied(mut entry) => { entry.get_mut().push(cnum); },
9393
}
9494
});

branches/snap-stage3/src/librustc/metadata/encoder.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12071207
None => {}
12081208
}
12091209
}
1210-
ast::ItemImpl(unsafety, _, ref opt_trait, ref ty, ref ast_items) => {
1210+
ast::ItemImpl(unsafety, polarity, _, ref opt_trait, ref ty, ref ast_items) => {
12111211
// We need to encode information about the default methods we
12121212
// have inherited, so we drive this based on the impl structure.
12131213
let impl_items = tcx.impl_items.borrow();
@@ -1221,6 +1221,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12211221
encode_name(rbml_w, item.ident.name);
12221222
encode_attributes(rbml_w, item.attrs[]);
12231223
encode_unsafety(rbml_w, unsafety);
1224+
encode_polarity(rbml_w, polarity);
12241225
match ty.node {
12251226
ast::TyPath(ref path, _) if path.segments.len() == 1 => {
12261227
let ident = path.segments.last().unwrap().identifier;
@@ -1704,6 +1705,14 @@ fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) {
17041705
rbml_w.end_tag();
17051706
}
17061707

1708+
fn encode_polarity(rbml_w: &mut Encoder, polarity: ast::ImplPolarity) {
1709+
let byte: u8 = match polarity {
1710+
ast::ImplPolarity::Positive => 0,
1711+
ast::ImplPolarity::Negative => 1,
1712+
};
1713+
rbml_w.wr_tagged_u8(tag_polarity, byte);
1714+
}
1715+
17071716
fn encode_crate_deps(rbml_w: &mut Encoder, cstore: &cstore::CStore) {
17081717
fn get_ordered_deps(cstore: &cstore::CStore) -> Vec<decoder::CrateDep> {
17091718
// Pull the cnums and name,vers,hash out of cstore
@@ -1885,7 +1894,7 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
18851894

18861895
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
18871896
fn visit_item(&mut self, item: &ast::Item) {
1888-
if let ast::ItemImpl(_, _, Some(ref trait_ref), _, _) = item.node {
1897+
if let ast::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
18891898
let def_map = &self.ecx.tcx.def_map;
18901899
let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
18911900
let def_id = trait_def.def_id();

branches/snap-stage3/src/librustc/metadata/loader.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,6 @@ use util::fs;
228228

229229
use std::c_str::ToCStr;
230230
use std::cmp;
231-
use std::collections::hash_map::Entry::{Occupied, Vacant};
232231
use std::collections::{HashMap, HashSet};
233232
use std::io::fs::PathExtensions;
234233
use std::io;
@@ -400,10 +399,9 @@ impl<'a> Context<'a> {
400399
};
401400
info!("lib candidate: {}", path.display());
402401

403-
let slot = match candidates.entry(hash.to_string()) {
404-
Occupied(entry) => entry.into_mut(),
405-
Vacant(entry) => entry.set((HashSet::new(), HashSet::new())),
406-
};
402+
let hash_str = hash.to_string();
403+
let slot = candidates.entry(&hash_str).get().unwrap_or_else(
404+
|vacant_entry| vacant_entry.insert((HashSet::new(), HashSet::new())));
407405
let (ref mut rlibs, ref mut dylibs) = *slot;
408406
if rlib {
409407
rlibs.insert(fs::realpath(path).unwrap());

branches/snap-stage3/src/librustc/middle/const_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ 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) {
315-
entry.set(def);
314+
if let Vacant(entry) = tcx.def_map.borrow_mut().entry(&expr.id) {
315+
entry.insert(def);
316316
}
317317
let path = match def {
318318
def::DefStruct(def_id) => def_to_path(tcx, def_id),

branches/snap-stage3/src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
355355
ast::ItemEnum(ref enum_def, _) if allow_dead_code => {
356356
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.node.id));
357357
}
358-
ast::ItemImpl(_, _, Some(ref _trait_ref), _, ref impl_items) => {
358+
ast::ItemImpl(_, _, _, Some(ref _trait_ref), _, ref impl_items) => {
359359
for impl_item in impl_items.iter() {
360360
match *impl_item {
361361
ast::MethodImplItem(ref method) => {

branches/snap-stage3/src/librustc/middle/infer/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
17121712
match tcx.map.find(parent) {
17131713
Some(node) => match node {
17141714
ast_map::NodeItem(item) => match item.node {
1715-
ast::ItemImpl(_, ref gen, _, _, _) => {
1715+
ast::ItemImpl(_, _, ref gen, _, _, _) => {
17161716
taken.push_all(gen.lifetimes.as_slice());
17171717
}
17181718
_ => ()

branches/snap-stage3/src/librustc/middle/infer/freshen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ 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;
7373
self.freshen_count += 1;
7474
let t = ty::mk_infer(self.infcx.tcx, freshener(index));
75-
entry.set(t);
75+
entry.insert(t);
7676
t
7777
}
7878
}

branches/snap-stage3/src/librustc/middle/infer/region_inference/graphviz.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ 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) {
141-
e.set(i);
140+
if let Vacant(e) = node_ids.entry(&node) {
141+
e.insert(i);
142142
i += 1;
143143
}
144144
};

0 commit comments

Comments
 (0)