Skip to content

Commit a35ea4d

Browse files
committed
Auto merge of #26117 - Manishearth:rollup, r=Manishearth
- Successful merges: #25898, #25909, #25948, #25968, #26073, #26078, #26099, #26104, #26105, #26112, #26113 - Failed merges:
2 parents d6c8028 + fd2c76c commit a35ea4d

File tree

14 files changed

+85
-36
lines changed

14 files changed

+85
-36
lines changed

src/doc/reference.md

+14-10
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ be undesired.
10381038

10391039
* Deadlocks
10401040
* Reading data from private fields (`std::repr`)
1041-
* Leaks due to reference count cycles, even in the global heap
1041+
* Leaks of memory and other resources
10421042
* Exiting without calling destructors
10431043
* Sending signals
10441044
* Accessing/modifying the file system
@@ -1418,9 +1418,13 @@ impl<T> Container for Vec<T> {
14181418
```
14191419

14201420
Generic functions may use traits as _bounds_ on their type parameters. This
1421-
will have two effects: only types that have the trait may instantiate the
1422-
parameter, and within the generic function, the methods of the trait can be
1423-
called on values that have the parameter's type. For example:
1421+
will have two effects:
1422+
1423+
- Only types that have the trait may instantiate the parameter.
1424+
- Within the generic function, the methods of the trait can be
1425+
called on values that have the parameter's type.
1426+
1427+
For example:
14241428

14251429
```
14261430
# type Surface = i32;
@@ -2831,13 +2835,13 @@ on the right-hand side.
28312835
An example of an `as` expression:
28322836

28332837
```
2834-
# fn sum(v: &[f64]) -> f64 { 0.0 }
2835-
# fn len(v: &[f64]) -> i32 { 0 }
2838+
# fn sum(values: &[f64]) -> f64 { 0.0 }
2839+
# fn len(values: &[f64]) -> i32 { 0 }
28362840
2837-
fn avg(v: &[f64]) -> f64 {
2838-
let sum: f64 = sum(v);
2839-
let sz: f64 = len(v) as f64;
2840-
return sum / sz;
2841+
fn average(values: &[f64]) -> f64 {
2842+
let sum: f64 = sum(values);
2843+
let size: f64 = len(values) as f64;
2844+
sum / size
28412845
}
28422846
```
28432847

src/doc/trpl/closures.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ let plus_two = |x| {
3333
assert_eq!(4, plus_two(2));
3434
```
3535

36-
You’ll notice a few things about closures that are a bit different than regular
37-
functions defined with `fn`. The first of which is that we did not need to
36+
You’ll notice a few things about closures that are a bit different from regular
37+
functions defined with `fn`. The first is that we did not need to
3838
annotate the types of arguments the closure takes or the values it returns. We
3939
can:
4040

@@ -48,18 +48,18 @@ But we don’t have to. Why is this? Basically, it was chosen for ergonomic reas
4848
While specifying the full type for named functions is helpful with things like
4949
documentation and type inference, the types of closures are rarely documented
5050
since they’re anonymous, and they don’t cause the kinds of error-at-a-distance
51-
that inferring named function types can.
51+
problems that inferring named function types can.
5252

5353
The second is that the syntax is similar, but a bit different. I’ve added spaces
54-
here to make them look a little closer:
54+
here for easier comparison:
5555

5656
```rust
5757
fn plus_one_v1 (x: i32) -> i32 { x + 1 }
5858
let plus_one_v2 = |x: i32| -> i32 { x + 1 };
5959
let plus_one_v3 = |x: i32| x + 1 ;
6060
```
6161

62-
Small differences, but they’re similar in ways.
62+
Small differences, but they’re similar.
6363

6464
# Closures and their environment
6565

@@ -99,7 +99,7 @@ note: previous borrow ends here
9999
fn main() {
100100
let mut num = 5;
101101
let plus_num = |x| x + num;
102-
102+
103103
let y = &mut num;
104104
}
105105
^
@@ -161,7 +161,7 @@ of `num`. So what’s the difference?
161161
```rust
162162
let mut num = 5;
163163

164-
{
164+
{
165165
let mut add_num = |x: i32| num += x;
166166

167167
add_num(5);
@@ -180,7 +180,7 @@ If we change to a `move` closure, it’s different:
180180
```rust
181181
let mut num = 5;
182182

183-
{
183+
{
184184
let mut add_num = move |x: i32| num += x;
185185

186186
add_num(5);

src/doc/trpl/comments.md

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ The other kind of comment is a doc comment. Doc comments use `///` instead of
2929
/// let five = 5;
3030
///
3131
/// assert_eq!(6, add_one(5));
32+
/// # fn add_one(x: i32) -> i32 {
33+
/// # x + 1
34+
/// # }
3235
/// ```
3336
fn add_one(x: i32) -> i32 {
3437
x + 1

src/doc/trpl/dining-philosophers.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,9 @@ an extra annotation, `move`, to indicate that the closure is going to take
432432
ownership of the values it’s capturing. Primarily, the `p` variable of the
433433
`map` function.
434434

435-
Inside the thread, all we do is call `eat()` on `p`.
435+
Inside the thread, all we do is call `eat()` on `p`. Also note that the call to `thread::spawn` lacks a trailing semicolon, making this an expression. This distinction is important, yielding the correct return value. For more details, read [Expressions vs. Statements][es].
436+
437+
[es]: functions.html#expressions-vs.-statements
436438

437439
```rust,ignore
438440
}).collect();

src/doc/trpl/error-handling.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ struct Info {
284284
}
285285

286286
fn write_info(info: &Info) -> io::Result<()> {
287-
let mut file = try!(File::create("my_best_friends.txt"));
287+
let mut file = File::create("my_best_friends.txt").unwrap();
288288

289289
try!(writeln!(&mut file, "name: {}", info.name));
290290
try!(writeln!(&mut file, "age: {}", info.age));

src/doc/trpl/generics.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
% Generics
22

33
Sometimes, when writing a function or data type, we may want it to work for
4-
multiple types of arguments. Luckily, Rust has a feature that gives us a better
5-
way: generics. Generics are called ‘parametric polymorphism’ in type theory,
4+
multiple types of arguments. In Rust, we can do this with generics.
5+
Generics are called ‘parametric polymorphism’ in type theory,
66
which means that they are types or functions that have multiple forms (‘poly’
77
is multiple, ‘morph’ is form) over a given parameter (‘parametric’).
88

src/doc/trpl/hello-cargo.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Note that since we're creating an executable, we used `main.rs`. If we
3636
want to make a library instead, we should use `lib.rs`. This convention is required
3737
for Cargo to successfully compile our projects, but it can be overridden if we wish.
3838
Custom file locations for the entry point can be specified
39-
with a [`[[lib]]` or `[[bin]]`][crates-custom] key in the TOML file described below.
39+
with a [`[lib]` or `[[bin]]`][crates-custom] key in the TOML file.
4040

4141
[crates-custom]: http://doc.crates.io/manifest.html#configuring-a-target
4242

src/doc/trpl/ownership.md

+40
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,46 @@ that, just like a move, when we assign `v` to `v2`, a copy of the data is made.
156156
But, unlike a move, we can still use `v` afterward. This is because an `i32`
157157
has no pointers to data somewhere else, copying it is a full copy.
158158

159+
All primitive types implement the `Copy` trait and their ownership is
160+
therefore not moved like one would assume, following the ´ownership rules´.
161+
To give an example, the two following snippets of code only compile because the
162+
`i32` and `bool` types implement the `Copy` trait.
163+
164+
```rust
165+
fn main() {
166+
let a = 5;
167+
168+
let _y = double(a);
169+
println!("{}", a);
170+
}
171+
172+
fn double(x: i32) -> i32 {
173+
x * 2
174+
}
175+
```
176+
177+
```rust
178+
fn main() {
179+
let a = true;
180+
181+
let _y = change_truth(a);
182+
println!("{}", a);
183+
}
184+
185+
fn change_truth(x: bool) -> bool {
186+
!x
187+
}
188+
```
189+
190+
If we would have used types that do not implement the `Copy` trait,
191+
we would have gotten a compile error because we tried to use a moved value.
192+
193+
```text
194+
error: use of moved value: `a`
195+
println!("{}", a);
196+
^
197+
```
198+
159199
We will discuss how to make your own types `Copy` in the [traits][traits]
160200
section.
161201

src/doc/trpl/trait-objects.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ static Foo_for_String_vtable: FooVtable = FooVtable {
261261
```
262262

263263
The `destructor` field in each vtable points to a function that will clean up
264-
any resources of the vtable’s type, for `u8` it is trivial, but for `String` it
264+
any resources of the vtable’s type: for `u8` it is trivial, but for `String` it
265265
will free the memory. This is necessary for owning trait objects like
266266
`Box<Foo>`, which need to clean-up both the `Box` allocation as well as the
267267
internal type when they go out of scope. The `size` and `align` fields store
@@ -270,7 +270,7 @@ essentially unused at the moment since the information is embedded in the
270270
destructor, but will be used in the future, as trait objects are progressively
271271
made more flexible.
272272

273-
Suppose we’ve got some values that implement `Foo`, then the explicit form of
273+
Suppose we’ve got some values that implement `Foo`. The explicit form of
274274
construction and use of `Foo` trait objects might look a bit like (ignoring the
275275
type mismatches: they’re all just pointers anyway):
276276

src/doc/trpl/traits.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ but we don’t define a body, just a type signature. When we `impl` a trait,
4545
we use `impl Trait for Item`, rather than just `impl Item`.
4646

4747
We can use traits to constrain our generics. Consider this function, which
48-
does not compile, and gives us a similar error:
48+
does not compile:
4949

5050
```rust,ignore
5151
fn print_area<T>(shape: T) {
@@ -56,7 +56,7 @@ fn print_area<T>(shape: T) {
5656
Rust complains:
5757

5858
```text
59-
error: type `T` does not implement any method in scope named `area`
59+
error: no method named `area` found for type `T` in the current scope
6060
```
6161

6262
Because `T` can be any type, we can’t be sure that it implements the `area`
@@ -212,10 +212,10 @@ This will compile without error.
212212
This means that even if someone does something bad like add methods to `i32`,
213213
it won’t affect you, unless you `use` that trait.
214214

215-
There’s one more restriction on implementing traits. Either the trait or the
216-
type you’re writing the `impl` for must be defined by you. So, we could
215+
There’s one more restriction on implementing traits: either the trait, or the
216+
type you’re writing the `impl` for, must be defined by you. So, we could
217217
implement the `HasArea` type for `i32`, because `HasArea` is in our code. But
218-
if we tried to implement `Float`, a trait provided by Rust, for `i32`, we could
218+
if we tried to implement `ToString`, a trait provided by Rust, for `i32`, we could
219219
not, because neither the trait nor the type are in our code.
220220

221221
One last thing about traits: generic functions with a trait bound use

src/librustc/middle/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1663,11 +1663,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16631663
}
16641664

16651665
ty::ty_vec(element_ty, ref len) => {
1666-
// [T, ..n] and [T]
1666+
// [T; n] and [T]
16671667
match bound {
16681668
ty::BoundCopy => {
16691669
match *len {
1670-
// [T, ..n] is copy iff T is copy
1670+
// [T; n] is copy iff T is copy
16711671
Some(_) => ok_if(vec![element_ty]),
16721672

16731673
// [T] is unsized and hence affine

src/librustc_typeck/check/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
234234
}
235235

236236

237-
// &[T, ..n] or &mut [T, ..n] -> &[T]
238-
// or &mut [T, ..n] -> &mut [T]
237+
// &[T; n] or &mut [T; n] -> &[T]
238+
// or &mut [T; n] -> &mut [T]
239239
// or &Concrete -> &Trait, etc.
240240
fn coerce_unsized(&self,
241241
source: Ty<'tcx>,

src/librustc_typeck/check/method/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ into a more explicit UFCS form:
1818
Here `ADJ` is some kind of adjustment, which is typically a series of
1919
autoderefs and then possibly an autoref (e.g., `&**receiver`). However
2020
we sometimes do other adjustments and coercions along the way, in
21-
particular unsizing (e.g., converting from `[T, ..n]` to `[T]`).
21+
particular unsizing (e.g., converting from `[T; n]` to `[T]`).
2222

2323
## The Two Phases
2424

src/librustc_typeck/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2085,7 +2085,7 @@ fn lookup_indexing<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
20852085
return final_mt;
20862086
}
20872087

2088-
// After we have fully autoderef'd, if the resulting type is [T, ..n], then
2088+
// After we have fully autoderef'd, if the resulting type is [T; n], then
20892089
// do a final unsized coercion to yield [T].
20902090
if let ty::ty_vec(element_ty, Some(_)) = ty.sty {
20912091
let adjusted_ty = ty::mk_vec(fcx.tcx(), element_ty, None);

0 commit comments

Comments
 (0)