Skip to content

Commit 8abc57e

Browse files
committed
---
yaml --- r: 227557 b: refs/heads/try c: 8af39ce h: refs/heads/master i: 227555: 53e6b83 v: v3
1 parent a3b67c8 commit 8abc57e

Some content is hidden

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

45 files changed

+904
-331
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: aca2057ed5fb7af3f8905b2bc01f72fa001c35c8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 85be7c5f75522265aceb1b186d4f6aaa4014904c
4+
refs/heads/try: 8af39cebc547a946b4ae861854c46c9c9a70a923
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/reference.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ apply to the crate as a whole.
638638
```
639639

640640
A crate that contains a `main` function can be compiled to an executable. If a
641-
`main` function is present, its return type must be [`unit`](#primitive-types)
641+
`main` function is present, its return type must be [`unit`](#tuple-types)
642642
and it must take no arguments.
643643

644644
# Items and attributes
@@ -928,21 +928,20 @@ A _generic function_ allows one or more _parameterized types_ to appear in its
928928
signature. Each type parameter must be explicitly declared, in an
929929
angle-bracket-enclosed, comma-separated list following the function name.
930930

931-
```{.ignore}
932-
fn iter<T, F>(seq: &[T], f: F) where T: Copy, F: Fn(T) {
933-
for elt in seq { f(*elt); }
934-
}
935-
fn map<T, U, F>(seq: &[T], f: F) -> Vec<U> where T: Copy, U: Copy, F: Fn(T) -> U {
936-
let mut acc = vec![];
937-
for elt in seq { acc.push(f(*elt)); }
938-
acc
939-
}
931+
```rust,ignore
932+
// foo is generic over A and B
933+
934+
fn foo<A, B>(x: A, y: B) {
940935
```
941936

942937
Inside the function signature and body, the name of the type parameter can be
943938
used as a type name. [Trait](#traits) bounds can be specified for type parameters
944939
to allow methods with that trait to be called on values of that type. This is
945-
specified using the `where` syntax, as in the above example.
940+
specified using the `where` syntax:
941+
942+
```rust,ignore
943+
fn foo<T>(x: T) where T: Debug {
944+
```
946945

947946
When a generic function is referenced, its type is instantiated based on the
948947
context of the reference. For example, calling the `iter` function defined
@@ -2874,7 +2873,7 @@ The `+`, `-`, `*`, `/`, `%`, `&`, `|`, `^`, `<<`, and `>>` operators may be
28742873
composed with the `=` operator. The expression `lval OP= val` is equivalent to
28752874
`lval = lval OP val`. For example, `x = x + 1` may be written as `x += 1`.
28762875

2877-
Any such expression always has the [`unit`](#primitive-types) type.
2876+
Any such expression always has the [`unit`](#tuple-types) type.
28782877

28792878
#### Operator precedence
28802879

@@ -3316,6 +3315,9 @@ assert!(b != "world");
33163315
assert!(p.0 == 10);
33173316
```
33183317

3318+
For historical reasons and convenience, the tuple type with no elements (`()`)
3319+
is often called ‘unit’ or ‘the unit type’.
3320+
33193321
### Array, and Slice types
33203322

33213323
Rust has two different types for a list of items:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ let y = &mut num;
120120
```
121121

122122
If your closure requires it, however, Rust will take ownership and move
123-
the environment instead:
123+
the environment instead. This doesn’t work:
124124

125125
```rust,ignore
126126
let nums = vec![1, 2, 3];
@@ -130,7 +130,7 @@ let takes_nums = || nums;
130130
println!("{:?}", nums);
131131
```
132132

133-
This gives us:
133+
We get this error:
134134

135135
```text
136136
note: `nums` moved into closure environment here because it has type

branches/try/src/doc/trpl/rust-inside-other-languages.md

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,14 @@ threads = []
6666
5_000_000.times do
6767
count += 1
6868
end
69+
70+
count
6971
end
7072
end
7173

72-
threads.each { |t| t.join }
74+
threads.each do |t|
75+
puts "Thread finished with count=#{t.value}"
76+
end
7377
puts "done!"
7478
```
7579

@@ -103,50 +107,26 @@ use std::thread;
103107
fn process() {
104108
let handles: Vec<_> = (0..10).map(|_| {
105109
thread::spawn(|| {
106-
let mut _x = 0;
110+
let mut x = 0;
107111
for _ in (0..5_000_000) {
108-
_x += 1
112+
x += 1
109113
}
114+
x
110115
})
111116
}).collect();
112117

113118
for h in handles {
114-
h.join().ok().expect("Could not join a thread!");
119+
println!("Thread finished with count={}",
120+
h.join().map_err(|_| "Could not join a thread!").unwrap());
115121
}
122+
println!("done!");
116123
}
117124
```
118125

119126
Some of this should look familiar from previous examples. We spin up ten
120127
threads, collecting them into a `handles` vector. Inside of each thread, we
121-
loop five million times, and add one to `_x` each time. Why the underscore?
122-
Well, if we remove it and compile:
123-
124-
```bash
125-
$ cargo build
126-
Compiling embed v0.1.0 (file:///home/steve/src/embed)
127-
src/lib.rs:3:1: 16:2 warning: function is never used: `process`, #[warn(dead_code)] on by default
128-
src/lib.rs:3 fn process() {
129-
src/lib.rs:4 let handles: Vec<_> = (0..10).map(|_| {
130-
src/lib.rs:5 thread::spawn(|| {
131-
src/lib.rs:6 let mut x = 0;
132-
src/lib.rs:7 for _ in (0..5_000_000) {
133-
src/lib.rs:8 x += 1
134-
...
135-
src/lib.rs:6:17: 6:22 warning: variable `x` is assigned to, but never used, #[warn(unused_variables)] on by default
136-
src/lib.rs:6 let mut x = 0;
137-
^~~~~
138-
```
139-
140-
That first warning is because we are building a library. If we had a test
141-
for this function, the warning would go away. But for now, it’s never
142-
called.
143-
144-
The second is related to `x` versus `_x`. Because we never actually _do_
145-
anything with `x`, we get a warning about it. In our case, that’s perfectly
146-
okay, as we’re just trying to waste CPU cycles. Prefixing `x` with the
147-
underscore removes the warning.
148-
149-
Finally, we join on each thread.
128+
loop five million times, and add one to `x` each time. Finally, we join on
129+
each thread.
150130

151131
Right now, however, this is a Rust library, and it doesn’t expose anything
152132
that’s callable from C. If we tried to hook this up to another language right

branches/try/src/doc/trpl/trait-objects.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,3 @@ let y = TraitObject {
300300
// y.method();
301301
(y.vtable.method)(y.data);
302302
```
303-
304-
If `b` or `y` were owning trait objects (`Box<Foo>`), there would be a
305-
`(b.vtable.destructor)(b.data)` (respectively `y`) call when they went out of
306-
scope.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ fn normal<T: ConvertTo<i64>>(x: &T) -> i64 {
332332
fn inverse<T>() -> T
333333
// this is using ConvertTo as if it were "ConvertFrom<i32>"
334334
where i32: ConvertTo<T> {
335-
1i32.convert()
335+
42.convert()
336336
}
337337
```
338338

branches/try/src/libcollections/vec.rs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,42 +1469,26 @@ impl<T> ops::DerefMut for Vec<T> {
14691469
impl<T> FromIterator<T> for Vec<T> {
14701470
#[inline]
14711471
fn from_iter<I: IntoIterator<Item=T>>(iterable: I) -> Vec<T> {
1472+
// Unroll the first iteration, as the vector is going to be
1473+
// expanded on this iteration in every case when the iterable is not
1474+
// empty, but the loop in extend_desugared() is not going to see the
1475+
// vector being full in the few subsequent loop iterations.
1476+
// So we get better branch prediction and the possibility to
1477+
// construct the vector with initial estimated capacity.
14721478
let mut iterator = iterable.into_iter();
1473-
let (lower, _) = iterator.size_hint();
1474-
let mut vector = Vec::with_capacity(lower);
1475-
1476-
// This function should be the moral equivalent of:
1477-
//
1478-
// for item in iterator {
1479-
// vector.push(item);
1480-
// }
1481-
//
1482-
// This equivalent crucially runs the iterator precisely once. Below we
1483-
// actually in theory run the iterator twice (one without bounds checks
1484-
// and one with). To achieve the "moral equivalent", we use the `if`
1485-
// statement below to break out early.
1486-
//
1487-
// If the first loop has terminated, then we have one of two conditions.
1488-
//
1489-
// 1. The underlying iterator returned `None`. In this case we are
1490-
// guaranteed that less than `vector.capacity()` elements have been
1491-
// returned, so we break out early.
1492-
// 2. The underlying iterator yielded `vector.capacity()` elements and
1493-
// has not yielded `None` yet. In this case we run the iterator to
1494-
// its end below.
1495-
for element in iterator.by_ref().take(vector.capacity()) {
1496-
let len = vector.len();
1497-
unsafe {
1498-
ptr::write(vector.get_unchecked_mut(len), element);
1499-
vector.set_len(len + 1);
1500-
}
1501-
}
1502-
1503-
if vector.len() == vector.capacity() {
1504-
for element in iterator {
1505-
vector.push(element);
1479+
let mut vector = match iterator.next() {
1480+
None => return Vec::new(),
1481+
Some(element) => {
1482+
let (lower, _) = iterator.size_hint();
1483+
let mut vector = Vec::with_capacity(1 + lower);
1484+
unsafe {
1485+
ptr::write(vector.get_unchecked_mut(0), element);
1486+
vector.set_len(1);
1487+
}
1488+
vector
15061489
}
1507-
}
1490+
};
1491+
vector.extend_desugared(iterator);
15081492
vector
15091493
}
15101494
}
@@ -1569,11 +1553,27 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
15691553
impl<T> Extend<T> for Vec<T> {
15701554
#[inline]
15711555
fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
1572-
let iterator = iterable.into_iter();
1573-
let (lower, _) = iterator.size_hint();
1574-
self.reserve(lower);
1575-
for element in iterator {
1576-
self.push(element)
1556+
self.extend_desugared(iterable.into_iter())
1557+
}
1558+
}
1559+
1560+
impl<T> Vec<T> {
1561+
fn extend_desugared<I: Iterator<Item=T>>(&mut self, mut iterator: I) {
1562+
// This function should be the moral equivalent of:
1563+
//
1564+
// for item in iterator {
1565+
// self.push(item);
1566+
// }
1567+
while let Some(element) = iterator.next() {
1568+
let len = self.len();
1569+
if len == self.capacity() {
1570+
let (lower, _) = iterator.size_hint();
1571+
self.reserve(lower + 1);
1572+
}
1573+
unsafe {
1574+
ptr::write(self.get_unchecked_mut(len), element);
1575+
self.set_len(len + 1);
1576+
}
15771577
}
15781578
}
15791579
}

branches/try/src/libcore/char.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,8 @@ pub const MAX: char = '\u{10ffff}';
7474
/// ```
7575
/// use std::char;
7676
///
77-
/// let c = char::from_u32(10084); // produces `Some(❤)`
78-
/// assert_eq!(c, Some('❤'));
79-
/// ```
80-
///
81-
/// An invalid character:
82-
///
83-
/// ```
84-
/// use std::char;
85-
///
86-
/// let none = char::from_u32(1114112);
87-
/// assert_eq!(none, None);
77+
/// assert_eq!(char::from_u32(0x2764), Some('❤'));
78+
/// assert_eq!(char::from_u32(0x110000), None); // invalid character
8879
/// ```
8980
#[inline]
9081
#[stable(feature = "rust1", since = "1.0.0")]

branches/try/src/libcore/str/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,10 +638,10 @@ impl<'a, P: Pattern<'a>> SplitInternal<'a, P> {
638638

639639
generate_pattern_iterators! {
640640
forward:
641-
/// Created with the method `.split()`.
641+
#[doc="Created with the method `.split()`."]
642642
struct Split;
643643
reverse:
644-
/// Created with the method `.rsplit()`.
644+
#[doc="Created with the method `.rsplit()`."]
645645
struct RSplit;
646646
stability:
647647
#[stable(feature = "rust1", since = "1.0.0")]
@@ -652,10 +652,10 @@ generate_pattern_iterators! {
652652

653653
generate_pattern_iterators! {
654654
forward:
655-
/// Created with the method `.split_terminator()`.
655+
#[doc="Created with the method `.split_terminator()`."]
656656
struct SplitTerminator;
657657
reverse:
658-
/// Created with the method `.rsplit_terminator()`.
658+
#[doc="Created with the method `.rsplit_terminator()`."]
659659
struct RSplitTerminator;
660660
stability:
661661
#[stable(feature = "rust1", since = "1.0.0")]
@@ -698,10 +698,10 @@ impl<'a, P: Pattern<'a>> SplitNInternal<'a, P> {
698698

699699
generate_pattern_iterators! {
700700
forward:
701-
/// Created with the method `.splitn()`.
701+
#[doc="Created with the method `.splitn()`."]
702702
struct SplitN;
703703
reverse:
704-
/// Created with the method `.rsplitn()`.
704+
#[doc="Created with the method `.rsplitn()`."]
705705
struct RSplitN;
706706
stability:
707707
#[stable(feature = "rust1", since = "1.0.0")]
@@ -732,10 +732,10 @@ impl<'a, P: Pattern<'a>> MatchIndicesInternal<'a, P> {
732732

733733
generate_pattern_iterators! {
734734
forward:
735-
/// Created with the method `.match_indices()`.
735+
#[doc="Created with the method `.match_indices()`."]
736736
struct MatchIndices;
737737
reverse:
738-
/// Created with the method `.rmatch_indices()`.
738+
#[doc="Created with the method `.rmatch_indices()`."]
739739
struct RMatchIndices;
740740
stability:
741741
#[unstable(feature = "core",
@@ -773,10 +773,10 @@ impl<'a, P: Pattern<'a>> MatchesInternal<'a, P> {
773773

774774
generate_pattern_iterators! {
775775
forward:
776-
/// Created with the method `.matches()`.
776+
#[doc="Created with the method `.matches()`."]
777777
struct Matches;
778778
reverse:
779-
/// Created with the method `.rmatches()`.
779+
#[doc="Created with the method `.rmatches()`."]
780780
struct RMatches;
781781
stability:
782782
#[unstable(feature = "core", reason = "type got recently added")]

0 commit comments

Comments
 (0)