Skip to content

Commit 8e58af4

Browse files
committedMar 23, 2015
Fallout in stdlib, rustdoc, rustc, etc. For most maps, converted uses of
`[]` on maps to `get` in rustc, since stage0 and stage1+ disagree about how to use `[]`.
1 parent b4d4daf commit 8e58af4

Some content is hidden

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

57 files changed

+245
-159
lines changed
 

‎src/libcollections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
264264
/// Some(x) => *x = "b",
265265
/// None => (),
266266
/// }
267-
/// assert_eq!(map[1], "b");
267+
/// assert_eq!(map[&1], "b");
268268
/// ```
269269
// See `get` for implementation notes, this is basically a copy-paste with mut's added
270270
#[stable(feature = "rust1", since = "1.0.0")]
@@ -326,7 +326,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
326326
///
327327
/// map.insert(37, "b");
328328
/// assert_eq!(map.insert(37, "c"), Some("b"));
329-
/// assert_eq!(map[37], "c");
329+
/// assert_eq!(map[&37], "c");
330330
/// ```
331331
#[stable(feature = "rust1", since = "1.0.0")]
332332
pub fn insert(&mut self, mut key: K, mut value: V) -> Option<V> {

‎src/libcollections/btree/node.rs

+61
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,7 @@ macro_rules! node_slice_impl {
15221522
}
15231523

15241524
/// Returns a sub-slice with elements starting with `min_key`.
1525+
#[cfg(stage0)]
15251526
pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> {
15261527
// _______________
15271528
// |_1_|_3_|_5_|_7_|
@@ -1549,7 +1550,37 @@ macro_rules! node_slice_impl {
15491550
}
15501551
}
15511552

1553+
/// Returns a sub-slice with elements starting with `min_key`.
1554+
#[cfg(not(stage0))]
1555+
pub fn slice_from(self, min_key: &K) -> $NodeSlice<'a, K, V> {
1556+
// _______________
1557+
// |_1_|_3_|_5_|_7_|
1558+
// | | | | |
1559+
// 0 0 1 1 2 2 3 3 4 index
1560+
// | | | | |
1561+
// \___|___|___|___/ slice_from(&0); pos = 0
1562+
// \___|___|___/ slice_from(&2); pos = 1
1563+
// |___|___|___/ slice_from(&3); pos = 1; result.head_is_edge = false
1564+
// \___|___/ slice_from(&4); pos = 2
1565+
// \___/ slice_from(&6); pos = 3
1566+
// \|/ slice_from(&999); pos = 4
1567+
let (pos, pos_is_kv) = self.search_linear(min_key);
1568+
$NodeSlice {
1569+
has_edges: self.has_edges,
1570+
edges: if !self.has_edges {
1571+
self.edges
1572+
} else {
1573+
self.edges.$index(pos ..)
1574+
},
1575+
keys: &self.keys[pos ..],
1576+
vals: self.vals.$index(pos ..),
1577+
head_is_edge: !pos_is_kv,
1578+
tail_is_edge: self.tail_is_edge,
1579+
}
1580+
}
1581+
15521582
/// Returns a sub-slice with elements up to and including `max_key`.
1583+
#[cfg(stage0)]
15531584
pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
15541585
// _______________
15551586
// |_1_|_3_|_5_|_7_|
@@ -1577,6 +1608,36 @@ macro_rules! node_slice_impl {
15771608
tail_is_edge: !pos_is_kv,
15781609
}
15791610
}
1611+
1612+
/// Returns a sub-slice with elements up to and including `max_key`.
1613+
#[cfg(not(stage0))]
1614+
pub fn slice_to(self, max_key: &K) -> $NodeSlice<'a, K, V> {
1615+
// _______________
1616+
// |_1_|_3_|_5_|_7_|
1617+
// | | | | |
1618+
// 0 0 1 1 2 2 3 3 4 index
1619+
// | | | | |
1620+
//\|/ | | | | slice_to(&0); pos = 0
1621+
// \___/ | | | slice_to(&2); pos = 1
1622+
// \___|___| | | slice_to(&3); pos = 1; result.tail_is_edge = false
1623+
// \___|___/ | | slice_to(&4); pos = 2
1624+
// \___|___|___/ | slice_to(&6); pos = 3
1625+
// \___|___|___|___/ slice_to(&999); pos = 4
1626+
let (pos, pos_is_kv) = self.search_linear(max_key);
1627+
let pos = pos + if pos_is_kv { 1 } else { 0 };
1628+
$NodeSlice {
1629+
has_edges: self.has_edges,
1630+
edges: if !self.has_edges {
1631+
self.edges
1632+
} else {
1633+
self.edges.$index(.. (pos + 1))
1634+
},
1635+
keys: &self.keys[..pos],
1636+
vals: self.vals.$index(.. pos),
1637+
head_is_edge: self.head_is_edge,
1638+
tail_is_edge: !pos_is_kv,
1639+
}
1640+
}
15801641
}
15811642

15821643
impl<'a, K: 'a, V: 'a> $NodeSlice<'a, K, V> {

0 commit comments

Comments
 (0)