Skip to content

Commit 40c598f

Browse files
committed
Rollup merge of rust-lang#25948 - tshepang:misc-doc-improvements, r=steveklabnik
2 parents 0e4a361 + 09c6203 commit 40c598f

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

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/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

0 commit comments

Comments
 (0)