Skip to content

Commit ffbb464

Browse files
committed
---
yaml --- r: 207940 b: refs/heads/snap-stage3 c: 07915ef h: refs/heads/master v: v3
1 parent 8396fe4 commit ffbb464

File tree

27 files changed

+462
-120
lines changed

27 files changed

+462
-120
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: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 78c1ae279175b78b0118a5acfd69f82085b9cfc1
4+
refs/heads/snap-stage3: 07915ef6a1426952ba612c02ecafad003bf971a3
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/doc/trpl/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,5 @@ fn main() {
190190
We created an inner scope with an additional set of curly braces. `y` will go out of
191191
scope before we call `push()`, and so we’re all good.
192192

193-
This concept of ownership isn’t just good for preventing danging pointers, but an
193+
This concept of ownership isn’t just good for preventing dangling pointers, but an
194194
entire set of related problems, like iterator invalidation, concurrency, and more.

branches/snap-stage3/src/doc/trpl/concurrency.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ use std::thread;
116116
fn main() {
117117
let mut data = vec![1u32, 2, 3];
118118
119-
for i in 0..2 {
119+
for i in 0..3 {
120120
thread::spawn(move || {
121121
data[i] += 1;
122122
});
@@ -154,7 +154,7 @@ use std::sync::Mutex;
154154
fn main() {
155155
let mut data = Mutex::new(vec![1u32, 2, 3]);
156156
157-
for i in 0..2 {
157+
for i in 0..3 {
158158
let data = data.lock().unwrap();
159159
thread::spawn(move || {
160160
data[i] += 1;
@@ -196,7 +196,7 @@ use std::thread;
196196
fn main() {
197197
let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
198198
199-
for i in 0..2 {
199+
for i in 0..3 {
200200
let data = data.clone();
201201
thread::spawn(move || {
202202
let mut data = data.lock().unwrap();
@@ -217,7 +217,7 @@ thread more closely:
217217
# use std::thread;
218218
# fn main() {
219219
# let data = Arc::new(Mutex::new(vec![1u32, 2, 3]));
220-
# for i in 0..2 {
220+
# for i in 0..3 {
221221
# let data = data.clone();
222222
thread::spawn(move || {
223223
let mut data = data.lock().unwrap();

branches/snap-stage3/src/doc/trpl/patterns.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ This prints `something else`
7070

7171
# Bindings
7272

73-
If you’re matching multiple things, via a `|` or a `...`, you can bind
74-
the value to a name with `@`:
73+
You can bind values to names with `@`:
7574

7675
```rust
7776
let x = 1;
@@ -82,7 +81,36 @@ match x {
8281
}
8382
```
8483

85-
This prints `got a range element 1`.
84+
This prints `got a range element 1`. This is useful when you want to
85+
do a complicated match of part of a data structure:
86+
87+
```rust
88+
#[derive(Debug)]
89+
struct Person {
90+
name: Option<String>,
91+
}
92+
93+
let name = "Steve".to_string();
94+
let mut x: Option<Person> = Some(Person { name: Some(name) });
95+
match x {
96+
Some(Person { name: ref a @ Some(_), .. }) => println!("{:?}", a),
97+
_ => {}
98+
}
99+
```
100+
101+
This prints `Some("Steve")`: We’ve bound the inner `name` to `a`.
102+
103+
If you use `@` with `|`, you need to make sure the name is bound in each part
104+
of the pattern:
105+
106+
```rust
107+
let x = 5;
108+
109+
match x {
110+
e @ 1 ... 5 | e @ 8 ... 10 => println!("got a range element {}", e),
111+
_ => println!("anything"),
112+
}
113+
```
86114

87115
# Ignoring variants
88116

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

Lines changed: 107 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ use rustc_unicode::str as unicode_str;
2626
use rustc_unicode::str::Utf16Item;
2727

2828
use borrow::{Cow, IntoCow};
29-
use str::{self, FromStr, Utf8Error};
29+
use range::RangeArgument;
30+
use str::{self, FromStr, Utf8Error, Chars};
3031
use vec::{DerefVec, Vec, as_vec};
3132

3233
/// A growable string stored as a UTF-8 encoded buffer.
@@ -695,6 +696,59 @@ impl String {
695696
pub fn clear(&mut self) {
696697
self.vec.clear()
697698
}
699+
700+
/// Create a draining iterator that removes the specified range in the string
701+
/// and yields the removed chars from start to end. The element range is
702+
/// removed even if the iterator is not consumed until the end.
703+
///
704+
/// # Panics
705+
///
706+
/// Panics if the starting point or end point are not on character boundaries,
707+
/// or if they are out of bounds.
708+
///
709+
/// # Examples
710+
///
711+
/// ```
712+
/// # #![feature(collections_drain)]
713+
///
714+
/// let mut s = String::from("α is alpha, β is beta");
715+
/// let beta_offset = s.find('β').unwrap_or(s.len());
716+
///
717+
/// // Remove the range up until the β from the string
718+
/// let t: String = s.drain(..beta_offset).collect();
719+
/// assert_eq!(t, "α is alpha, ");
720+
/// assert_eq!(s, "β is beta");
721+
///
722+
/// // A full range clears the string
723+
/// s.drain(..);
724+
/// assert_eq!(s, "");
725+
/// ```
726+
#[unstable(feature = "collections_drain",
727+
reason = "recently added, matches RFC")]
728+
pub fn drain<R>(&mut self, range: R) -> Drain where R: RangeArgument<usize> {
729+
// Memory safety
730+
//
731+
// The String version of Drain does not have the memory safety issues
732+
// of the vector version. The data is just plain bytes.
733+
// Because the range removal happens in Drop, if the Drain iterator is leaked,
734+
// the removal will not happen.
735+
let len = self.len();
736+
let start = *range.start().unwrap_or(&0);
737+
let end = *range.end().unwrap_or(&len);
738+
739+
// Take out two simultaneous borrows. The &mut String won't be accessed
740+
// until iteration is over, in Drop.
741+
let self_ptr = self as *mut _;
742+
// slicing does the appropriate bounds checks
743+
let chars_iter = self[start..end].chars();
744+
745+
Drain {
746+
start: start,
747+
end: end,
748+
iter: chars_iter,
749+
string: self_ptr,
750+
}
751+
}
698752
}
699753

700754
impl FromUtf8Error {
@@ -1075,3 +1129,55 @@ impl fmt::Write for String {
10751129
Ok(())
10761130
}
10771131
}
1132+
1133+
/// A draining iterator for `String`.
1134+
#[unstable(feature = "collections_drain", reason = "recently added")]
1135+
pub struct Drain<'a> {
1136+
/// Will be used as &'a mut String in the destructor
1137+
string: *mut String,
1138+
/// Start of part to remove
1139+
start: usize,
1140+
/// End of part to remove
1141+
end: usize,
1142+
/// Current remaining range to remove
1143+
iter: Chars<'a>,
1144+
}
1145+
1146+
unsafe impl<'a> Sync for Drain<'a> {}
1147+
unsafe impl<'a> Send for Drain<'a> {}
1148+
1149+
#[unstable(feature = "collections_drain", reason = "recently added")]
1150+
impl<'a> Drop for Drain<'a> {
1151+
fn drop(&mut self) {
1152+
unsafe {
1153+
// Use Vec::drain. "Reaffirm" the bounds checks to avoid
1154+
// panic code being inserted again.
1155+
let self_vec = (*self.string).as_mut_vec();
1156+
if self.start <= self.end && self.end <= self_vec.len() {
1157+
self_vec.drain(self.start..self.end);
1158+
}
1159+
}
1160+
}
1161+
}
1162+
1163+
#[unstable(feature = "collections_drain", reason = "recently added")]
1164+
impl<'a> Iterator for Drain<'a> {
1165+
type Item = char;
1166+
1167+
#[inline]
1168+
fn next(&mut self) -> Option<char> {
1169+
self.iter.next()
1170+
}
1171+
1172+
fn size_hint(&self) -> (usize, Option<usize>) {
1173+
self.iter.size_hint()
1174+
}
1175+
}
1176+
1177+
#[unstable(feature = "collections_drain", reason = "recently added")]
1178+
impl<'a> DoubleEndedIterator for Drain<'a> {
1179+
#[inline]
1180+
fn next_back(&mut self) -> Option<char> {
1181+
self.iter.next_back()
1182+
}
1183+
}

branches/snap-stage3/src/libcollectionstest/string.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,23 @@ fn test_from_iterator() {
348348
assert_eq!(s, d);
349349
}
350350

351+
#[test]
352+
fn test_drain() {
353+
let mut s = String::from("αβγ");
354+
assert_eq!(s.drain(2..4).collect::<String>(), "β");
355+
assert_eq!(s, "αγ");
356+
357+
let mut t = String::from("abcd");
358+
t.drain(..0);
359+
assert_eq!(t, "abcd");
360+
t.drain(..1);
361+
assert_eq!(t, "bcd");
362+
t.drain(3..);
363+
assert_eq!(t, "bcd");
364+
t.drain(..);
365+
assert_eq!(t, "");
366+
}
367+
351368
#[bench]
352369
fn bench_with_capacity(b: &mut Bencher) {
353370
b.iter(|| {

branches/snap-stage3/src/libcore/num/float_macros.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ macro_rules! from_str_radix_float_impl {
3535
}
3636

3737
let (is_positive, src) = match src.slice_shift_char() {
38-
None => return Err(PFE { kind: Empty }),
39-
Some(('-', "")) => return Err(PFE { kind: Empty }),
38+
None => return Err(PFE { __kind: Empty }),
39+
Some(('-', "")) => return Err(PFE { __kind: Empty }),
4040
Some(('-', src)) => (false, src),
4141
Some((_, _)) => (true, src),
4242
};
@@ -88,7 +88,7 @@ macro_rules! from_str_radix_float_impl {
8888
break; // start of fractional part
8989
},
9090
_ => {
91-
return Err(PFE { kind: Invalid });
91+
return Err(PFE { __kind: Invalid });
9292
},
9393
},
9494
}
@@ -122,7 +122,7 @@ macro_rules! from_str_radix_float_impl {
122122
break; // start of exponent
123123
},
124124
_ => {
125-
return Err(PFE { kind: Invalid });
125+
return Err(PFE { __kind: Invalid });
126126
},
127127
},
128128
}
@@ -135,7 +135,7 @@ macro_rules! from_str_radix_float_impl {
135135
let base = match c {
136136
'E' | 'e' if radix == 10 => 10.0,
137137
'P' | 'p' if radix == 16 => 2.0,
138-
_ => return Err(PFE { kind: Invalid }),
138+
_ => return Err(PFE { __kind: Invalid }),
139139
};
140140

141141
// Parse the exponent as decimal integer
@@ -144,13 +144,13 @@ macro_rules! from_str_radix_float_impl {
144144
Some(('-', src)) => (false, src.parse::<usize>()),
145145
Some(('+', src)) => (true, src.parse::<usize>()),
146146
Some((_, _)) => (true, src.parse::<usize>()),
147-
None => return Err(PFE { kind: Invalid }),
147+
None => return Err(PFE { __kind: Invalid }),
148148
};
149149

150150
match (is_positive, exp) {
151151
(true, Ok(exp)) => base.powi(exp as i32),
152152
(false, Ok(exp)) => 1.0 / base.powi(exp as i32),
153-
(_, Err(_)) => return Err(PFE { kind: Invalid }),
153+
(_, Err(_)) => return Err(PFE { __kind: Invalid }),
154154
}
155155
},
156156
None => 1.0, // no exponent

branches/snap-stage3/src/libcore/num/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,11 @@ impl fmt::Display for ParseIntError {
15241524

15251525
/// An error which can be returned when parsing a float.
15261526
#[derive(Debug, Clone, PartialEq)]
1527-
pub struct ParseFloatError { pub kind: FloatErrorKind }
1527+
#[stable(feature = "rust1", since = "1.0.0")]
1528+
pub struct ParseFloatError {
1529+
#[doc(hidden)]
1530+
pub __kind: FloatErrorKind
1531+
}
15281532

15291533
#[derive(Debug, Clone, PartialEq)]
15301534
pub enum FloatErrorKind {
@@ -1533,9 +1537,9 @@ pub enum FloatErrorKind {
15331537
}
15341538

15351539
impl ParseFloatError {
1536-
#[unstable(feature = "core", reason = "available through Error trait")]
1537-
pub fn description(&self) -> &str {
1538-
match self.kind {
1540+
#[doc(hidden)]
1541+
pub fn __description(&self) -> &str {
1542+
match self.__kind {
15391543
FloatErrorKind::Empty => "cannot parse float from empty string",
15401544
FloatErrorKind::Invalid => "invalid float literal",
15411545
}
@@ -1545,6 +1549,6 @@ impl ParseFloatError {
15451549
#[stable(feature = "rust1", since = "1.0.0")]
15461550
impl fmt::Display for ParseFloatError {
15471551
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1548-
self.description().fmt(f)
1552+
self.__description().fmt(f)
15491553
}
15501554
}

branches/snap-stage3/src/liblog/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ macro_rules! info {
136136
}
137137

138138
/// A convenience macro for logging at the debug log level. This macro can also
139-
/// be omitted at compile time by passing `--cfg ndebug` to the compiler. If
139+
/// be omitted at compile time by passing `-C debug-assertions` to the compiler. If
140140
/// this option is not passed, then debug statements will be compiled.
141141
///
142142
/// # Examples

branches/snap-stage3/src/librustc_typeck/check/cast.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ pub fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) {
170170
demand::coerce(fcx, e.span, t_1, &e);
171171
}
172172
}
173-
} else if fcx.type_is_fat_ptr(t_e, span) && !fcx.type_is_fat_ptr(t_1, span) {
173+
} else if fcx.type_is_fat_ptr(t_e, span) != fcx.type_is_fat_ptr(t_1, span) {
174174
fcx.type_error_message(span, |actual| {
175-
format!("illegal cast; cast from fat pointer: `{}` as `{}`",
175+
format!("illegal cast; cast to or from fat pointer: `{}` as `{}` \
176+
involving incompatible type.",
176177
actual, fcx.infcx().ty_to_string(t_1))
177178
}, t_e, None);
178179
} else if !(t_e_is_scalar && t_1_is_trivial) {

branches/snap-stage3/src/libstd/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl Error for num::ParseIntError {
147147
#[stable(feature = "rust1", since = "1.0.0")]
148148
impl Error for num::ParseFloatError {
149149
fn description(&self) -> &str {
150-
self.description()
150+
self.__description()
151151
}
152152
}
153153

branches/snap-stage3/src/libstd/num/f32.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use core::num;
2121
use intrinsics;
2222
use libc::c_int;
2323
use num::{FpCategory, ParseFloatError};
24-
use sys_common::FromInner;
2524

2625
pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON};
2726
pub use core::f32::{MIN_EXP, MAX_EXP, MIN_10_EXP};
@@ -77,7 +76,7 @@ impl f32 {
7776
/// Parses a float as with a given radix
7877
#[unstable(feature = "float_from_str_radix", reason = "recently moved API")]
7978
pub fn from_str_radix(s: &str, radix: u32) -> Result<f32, ParseFloatError> {
80-
num::Float::from_str_radix(s, radix).map_err(FromInner::from_inner)
79+
num::Float::from_str_radix(s, radix)
8180
}
8281

8382
/// Returns `true` if this value is `NaN` and false otherwise.

0 commit comments

Comments
 (0)