Skip to content

Commit cde1671

Browse files
committed
---
yaml --- r: 232811 b: refs/heads/try c: f9b63d3 h: refs/heads/master i: 232809: 3c29d7a 232807: 0bd1d17 v: v3
1 parent 874f67a commit cde1671

File tree

55 files changed

+543
-706
lines changed

Some content is hidden

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

55 files changed

+543
-706
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: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 3c100de75ac94ef33ecafe64810ef4c8113c1579
4+
refs/heads/try: f9b63d39730740e002cc31a38a7a8a3a18d3f46d
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/doc/trpl/ffi.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,9 @@ strings are not terminated with `\0`. If you need a NUL-terminated string for
496496
interoperability with C, you should use the `CString` type in the `std::ffi`
497497
module.
498498

499-
The [`libc` crate on crates.io][libc] includes type aliases and function
500-
definitions for the C standard library in the `libc` module, and Rust links
501-
against `libc` and `libm` by default.
502-
503-
[libc]: https://crates.io/crates/libc
499+
The standard library includes type aliases and function definitions for the C
500+
standard library in the `libc` module, and Rust links against `libc` and `libm`
501+
by default.
504502

505503
# The "nullable pointer optimization"
506504

branches/try/src/doc/trpl/testing.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,26 +120,13 @@ And that's reflected in the summary line:
120120
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
121121
```
122122

123-
We also get a non-zero status code. We can use `$?` on OS X and Linux:
123+
We also get a non-zero status code:
124124

125125
```bash
126126
$ echo $?
127127
101
128128
```
129129

130-
On Windows, if you’re using `cmd`:
131-
132-
```bash
133-
> echo %ERRORLEVEL%
134-
```
135-
136-
And if you’re using PowerShell:
137-
138-
```bash
139-
> echo $LASTEXITCODE # the code itself
140-
> echo $? # a boolean, fail or succeed
141-
```
142-
143130
This is useful if you want to integrate `cargo test` into other tooling.
144131

145132
We can invert our test's failure with another attribute: `should_panic`:

branches/try/src/libcollections/btree/map.rs

Lines changed: 92 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
459459
}
460460
});
461461
match result {
462-
Finished(ret) => return ret,
462+
Finished(ret) => return ret.map(|(_, v)| v),
463463
Continue(new_stack) => stack = new_stack
464464
}
465465
}
@@ -693,16 +693,16 @@ mod stack {
693693
impl<'a, K, V> SearchStack<'a, K, V, handle::KV, handle::Leaf> {
694694
/// Removes the key and value in the top element of the stack, then handles underflows as
695695
/// described in BTree's pop function.
696-
fn remove_leaf(mut self) -> V {
696+
fn remove_leaf(mut self) -> (K, V) {
697697
self.map.length -= 1;
698698

699699
// Remove the key-value pair from the leaf that this search stack points to.
700700
// Then, note if the leaf is underfull, and promptly forget the leaf and its ptr
701701
// to avoid ownership issues.
702-
let (value, mut underflow) = unsafe {
703-
let (_, value) = self.top.from_raw_mut().remove_as_leaf();
702+
let (key_val, mut underflow) = unsafe {
703+
let key_val = self.top.from_raw_mut().remove_as_leaf();
704704
let underflow = self.top.from_raw().node().is_underfull();
705-
(value, underflow)
705+
(key_val, underflow)
706706
};
707707

708708
loop {
@@ -717,7 +717,7 @@ mod stack {
717717
self.map.depth -= 1;
718718
self.map.root.hoist_lone_child();
719719
}
720-
return value;
720+
return key_val;
721721
}
722722
Some(mut handle) => {
723723
if underflow {
@@ -728,7 +728,7 @@ mod stack {
728728
}
729729
} else {
730730
// All done!
731-
return value;
731+
return key_val;
732732
}
733733
}
734734
}
@@ -739,7 +739,7 @@ mod stack {
739739
impl<'a, K, V> SearchStack<'a, K, V, handle::KV, handle::LeafOrInternal> {
740740
/// Removes the key and value in the top element of the stack, then handles underflows as
741741
/// described in BTree's pop function.
742-
pub fn remove(self) -> V {
742+
pub fn remove(self) -> (K, V) {
743743
// Ensure that the search stack goes to a leaf. This is necessary to perform deletion
744744
// in a BTree. Note that this may put the tree in an inconsistent state (further
745745
// described in into_leaf's comments), but this is immediately fixed by the
@@ -1208,7 +1208,7 @@ impl<'a, K: Ord, V> OccupiedEntry<'a, K, V> {
12081208
/// Takes the value of the entry out of the map, and returns it.
12091209
#[stable(feature = "rust1", since = "1.0.0")]
12101210
pub fn remove(self) -> V {
1211-
self.stack.remove()
1211+
self.stack.remove().1
12121212
}
12131213
}
12141214

@@ -1609,3 +1609,86 @@ impl<K: Ord, V> BTreeMap<K, V> {
16091609
}
16101610
}
16111611
}
1612+
1613+
impl<K, Q: ?Sized> super::Recover<Q> for BTreeMap<K, ()> where K: Borrow<Q> + Ord, Q: Ord {
1614+
type Key = K;
1615+
1616+
fn get(&self, key: &Q) -> Option<&K> {
1617+
let mut cur_node = &self.root;
1618+
loop {
1619+
match Node::search(cur_node, key) {
1620+
Found(handle) => return Some(handle.into_kv().0),
1621+
GoDown(handle) => match handle.force() {
1622+
Leaf(_) => return None,
1623+
Internal(internal_handle) => {
1624+
cur_node = internal_handle.into_edge();
1625+
continue;
1626+
}
1627+
}
1628+
}
1629+
}
1630+
}
1631+
1632+
fn take(&mut self, key: &Q) -> Option<K> {
1633+
// See `remove` for an explanation of this.
1634+
1635+
let mut stack = stack::PartialSearchStack::new(self);
1636+
loop {
1637+
let result = stack.with(move |pusher, node| {
1638+
match Node::search(node, key) {
1639+
Found(handle) => {
1640+
// Perfect match. Terminate the stack here, and remove the entry
1641+
Finished(Some(pusher.seal(handle).remove()))
1642+
},
1643+
GoDown(handle) => {
1644+
// We need to keep searching, try to go down the next edge
1645+
match handle.force() {
1646+
// We're at a leaf; the key isn't in here
1647+
Leaf(_) => Finished(None),
1648+
Internal(internal_handle) => Continue(pusher.push(internal_handle))
1649+
}
1650+
}
1651+
}
1652+
});
1653+
match result {
1654+
Finished(ret) => return ret.map(|(k, _)| k),
1655+
Continue(new_stack) => stack = new_stack
1656+
}
1657+
}
1658+
}
1659+
1660+
fn replace(&mut self, mut key: K) -> Option<K> {
1661+
// See `insert` for an explanation of this.
1662+
1663+
let mut stack = stack::PartialSearchStack::new(self);
1664+
1665+
loop {
1666+
let result = stack.with(move |pusher, node| {
1667+
match Node::search::<K, _>(node, &key) {
1668+
Found(mut handle) => {
1669+
mem::swap(handle.key_mut(), &mut key);
1670+
Finished(Some(key))
1671+
},
1672+
GoDown(handle) => {
1673+
match handle.force() {
1674+
Leaf(leaf_handle) => {
1675+
pusher.seal(leaf_handle).insert(key, ());
1676+
Finished(None)
1677+
}
1678+
Internal(internal_handle) => {
1679+
Continue((pusher.push(internal_handle), key, ()))
1680+
}
1681+
}
1682+
}
1683+
}
1684+
});
1685+
match result {
1686+
Finished(ret) => return ret,
1687+
Continue((new_stack, renewed_key, _)) => {
1688+
stack = new_stack;
1689+
key = renewed_key;
1690+
}
1691+
}
1692+
}
1693+
}
1694+
}

branches/try/src/libcollections/btree/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@
1111
mod node;
1212
pub mod map;
1313
pub mod set;
14+
15+
trait Recover<Q: ?Sized> {
16+
type Key;
17+
18+
fn get(&self, key: &Q) -> Option<&Self::Key>;
19+
fn take(&mut self, key: &Q) -> Option<Self::Key>;
20+
fn replace(&mut self, key: Self::Key) -> Option<Self::Key>;
21+
}

branches/try/src/libcollections/btree/set.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use core::ops::{BitOr, BitAnd, BitXor, Sub};
1919

2020
use borrow::Borrow;
2121
use btree_map::{BTreeMap, Keys};
22+
use super::Recover;
2223
use Bound;
2324

2425
// FIXME(conventions): implement bounded iterators
@@ -329,6 +330,16 @@ impl<T: Ord> BTreeSet<T> {
329330
self.map.contains_key(value)
330331
}
331332

333+
/// Returns a reference to the value in the set, if any, that is equal to the given value.
334+
///
335+
/// The value may be any borrowed form of the set's value type,
336+
/// but the ordering on the borrowed form *must* match the
337+
/// ordering on the value type.
338+
#[unstable(feature = "set_recovery", issue = "28050")]
339+
pub fn get<Q: ?Sized>(&self, value: &Q) -> Option<&T> where T: Borrow<Q>, Q: Ord {
340+
Recover::get(&self.map, value)
341+
}
342+
332343
/// Returns `true` if the set has no elements in common with `other`.
333344
/// This is equivalent to checking for an empty intersection.
334345
///
@@ -436,6 +447,13 @@ impl<T: Ord> BTreeSet<T> {
436447
self.map.insert(value, ()).is_none()
437448
}
438449

450+
/// Adds a value to the set, replacing the existing value, if any, that is equal to the given
451+
/// one. Returns the replaced value.
452+
#[unstable(feature = "set_recovery", issue = "28050")]
453+
pub fn replace(&mut self, value: T) -> Option<T> {
454+
Recover::replace(&mut self.map, value)
455+
}
456+
439457
/// Removes a value from the set. Returns `true` if the value was
440458
/// present in the set.
441459
///
@@ -458,6 +476,16 @@ impl<T: Ord> BTreeSet<T> {
458476
pub fn remove<Q: ?Sized>(&mut self, value: &Q) -> bool where T: Borrow<Q>, Q: Ord {
459477
self.map.remove(value).is_some()
460478
}
479+
480+
/// Removes and returns the value in the set, if any, that is equal to the given one.
481+
///
482+
/// The value may be any borrowed form of the set's value type,
483+
/// but the ordering on the borrowed form *must* match the
484+
/// ordering on the value type.
485+
#[unstable(feature = "set_recovery", issue = "28050")]
486+
pub fn take<Q: ?Sized>(&mut self, value: &Q) -> Option<T> where T: Borrow<Q>, Q: Ord {
487+
Recover::take(&mut self.map, value)
488+
}
461489
}
462490

463491
#[stable(feature = "rust1", since = "1.0.0")]

branches/try/src/libcollections/fmt.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,6 @@ pub use core::fmt::{LowerHex, UpperHex, Pointer};
481481
pub use core::fmt::{LowerExp, UpperExp};
482482
pub use core::fmt::Error;
483483
pub use core::fmt::{ArgumentV1, Arguments, write, radix, Radix, RadixFmt};
484-
pub use core::fmt::{DebugList, DebugMap, DebugSet, DebugStruct, DebugTuple};
485484

486485
use string;
487486

branches/try/src/libcollections/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ mod std {
113113
}
114114

115115
/// An endpoint of a range of keys.
116-
#[unstable(feature = "collections_bound", issue = "27787")]
116+
#[unstable(feature = "collections_bound", issue = "27711")]
117117
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
118118
pub enum Bound<T> {
119119
/// An inclusive bound.

branches/try/src/libcollections/string.rs

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,7 @@ impl String {
734734
///
735735
/// Note that this will drop any excess capacity.
736736
#[unstable(feature = "box_str",
737-
reason = "recently added, matches RFC",
738-
issue = "27785")]
737+
reason = "recently added, matches RFC")]
739738
#[deprecated(since = "1.4.0", reason = "renamed to `into_boxed_str`")]
740739
pub fn into_boxed_slice(self) -> Box<str> {
741740
self.into_boxed_str()
@@ -769,27 +768,18 @@ impl fmt::Display for FromUtf16Error {
769768

770769
#[stable(feature = "rust1", since = "1.0.0")]
771770
impl FromIterator<char> for String {
772-
fn from_iter<I: IntoIterator<Item=char>>(iterable: I) -> String {
771+
fn from_iter<I: IntoIterator<Item=char>>(iter: I) -> String {
773772
let mut buf = String::new();
774-
buf.extend(iterable);
773+
buf.extend(iter);
775774
buf
776775
}
777776
}
778777

779778
#[stable(feature = "rust1", since = "1.0.0")]
780779
impl<'a> FromIterator<&'a str> for String {
781-
fn from_iter<I: IntoIterator<Item=&'a str>>(iterable: I) -> String {
782-
let mut buf = String::new();
783-
buf.extend(iterable);
784-
buf
785-
}
786-
}
787-
788-
#[stable(feature = "extend_string", since = "1.4.0")]
789-
impl FromIterator<String> for String {
790-
fn from_iter<I: IntoIterator<Item=String>>(iterable: I) -> String {
780+
fn from_iter<I: IntoIterator<Item=&'a str>>(iter: I) -> String {
791781
let mut buf = String::new();
792-
buf.extend(iterable);
782+
buf.extend(iter);
793783
buf
794784
}
795785
}
@@ -808,8 +798,8 @@ impl Extend<char> for String {
808798

809799
#[stable(feature = "extend_ref", since = "1.2.0")]
810800
impl<'a> Extend<&'a char> for String {
811-
fn extend<I: IntoIterator<Item=&'a char>>(&mut self, iterable: I) {
812-
self.extend(iterable.into_iter().cloned());
801+
fn extend<I: IntoIterator<Item=&'a char>>(&mut self, iter: I) {
802+
self.extend(iter.into_iter().cloned());
813803
}
814804
}
815805

@@ -822,15 +812,6 @@ impl<'a> Extend<&'a str> for String {
822812
}
823813
}
824814

825-
#[stable(feature = "extend_string", since = "1.4.0")]
826-
impl Extend<String> for String {
827-
fn extend<I: IntoIterator<Item=String>>(&mut self, iterable: I) {
828-
for s in iterable {
829-
self.push_str(&s)
830-
}
831-
}
832-
}
833-
834815
/// A convenience impl that delegates to the impl for `&str`
835816
impl<'a, 'b> Pattern<'a> for &'b String {
836817
type Searcher = <&'b str as Pattern<'a>>::Searcher;

0 commit comments

Comments
 (0)