Skip to content

Commit 9cffbea

Browse files
Merge pull request #1838 from rust-lang/more-edits
More edits
2 parents 8b3ad7f + d83f107 commit 9cffbea

11 files changed

+233
-235
lines changed

ci/dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ libreoffice
247247
libstd
248248
lifecycle
249249
LimitTracker
250+
linter
250251
LLVM
251252
lobally
252253
locators

nostarch/appendices-d-and-e.md

Lines changed: 89 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,37 @@
11
# Appendix D - Useful Development Tools
22

3-
In this appendix, we’ll talk about tools provided by the Rust project that are
4-
useful when developing Rust code.
3+
In this appendix, we talk about some useful development tools that the Rust
4+
project provides. We’ll look at automatic formatting, quick ways to apply
5+
warning fixes, a linter, and integrating with IDEs.
56

67
## Automatic Formatting with `rustfmt`
78

8-
The tool `rustfmt` reformats your code according to the community code style.
9-
Many projects use `rustfmt` to prevent arguments about which style to use when
10-
writing Rust: everyone formats their code with the tool!
9+
The `rustfmt` tool reformats your code according to the community code style.
10+
Many collaborative projects use `rustfmt` to prevent arguments about which
11+
style to use when writing Rust: everyone formats their code using the tool.
1112

12-
The `rustfmt` tool is not yet at the quality of a version 1.0 release, but
13-
a preview is available for you to use in the meantime. Please give it a try and
14-
let us know how it goes!
15-
16-
To install `rustfmt`:
13+
To install `rustfmt`, enter the following:
1714

1815
```
19-
$ rustup component add rustfmt-preview
16+
$ rustup component add rustfmt
2017
```
2118

22-
This will give you both `rustfmt` and `cargo-fmt`, similar to how Rust gives
23-
you both `rustc` and `cargo`. To take any Cargo project and format it:
19+
This command gives you `rustfmt` and `cargo-fmt`, similar to how Rust gives you
20+
both `rustc` and `cargo`. To format any Cargo project, enter the following:
2421

2522
```
2623
$ cargo fmt
2724
```
2825

29-
Running this command will reformat all of the Rust code in the current crate.
30-
This should only change the code style, not the code semantics. For more
31-
information on `rustfmt`, see its documentation at
32-
*https://github.com/rust-lang-nursery/rustfmt*.
26+
Running this command reformats all the Rust code in the current crate. This
27+
should only change the code style, not the code semantics. For more information
28+
on `rustfmt`, see its documentation at *https://github.com/rust-lang/rustfmt/*.
3329

34-
## Fix Up Your Code with `rustfix`
30+
## Fix Your Code with `rustfix`
3531

36-
If you’ve written code in Rust, you’ve probably seen compiler warnings. For
37-
example, consider this code:
32+
The rustfix tool is included with Rust installations and can automatically fix
33+
some compiler warnings. If you’ve written code in Rust, you’ve probably seen
34+
compiler warnings. For example, consider this code:
3835

3936
Filename: src/main.rs
4037

@@ -77,7 +74,7 @@ $ cargo fix
7774
Finished dev [unoptimized + debuginfo] target(s) in 0.59s
7875
```
7976

80-
If we look at *src/main.rs* again, we’ll see that `cargo fix` has changed the
77+
When we look at *src/main.rs* again, we’ll see that `cargo fix` has changed the
8178
code:
8279

8380
Filename: src/main.rs
@@ -92,35 +89,30 @@ fn main() {
9289
}
9390
```
9491

95-
The `for` loop variable is now named `_i`, and the warning will no longer
96-
appear.
97-
98-
The `cargo fix` command can also be used to transition your code between
99-
different editions of Rust. Editions are covered in Appendix E.
92+
The `for` loop variable is now named `_i`, and the warning no longer appears.
10093

101-
## More Lints with `clippy`
94+
You can also use the `cargo fix` command to transition your code between
95+
different Rust editions. Editions are covered in Appendix E.
10296

103-
The `clippy` tool is a collection of lints to catch common mistakes and improve
104-
your Rust code.
97+
## More Lints with Clippy
10598

106-
The `clippy` tool is not yet at the quality of a version 1.0 release, but a
107-
preview is available for you to use in the meantime. Please give it a try and
108-
let us know how it goes!
99+
The Clippy tool is a collection of lints to analyze your code to catch common
100+
mistakes and improve your Rust code.
109101

110-
To install `clippy`:
102+
To install Clippy, enter the following:
111103

112104
```
113-
$ rustup component add clippy-preview
105+
$ rustup component add clippy
114106
```
115107

116-
To take any Cargo project and run clippy’s lints on it:
108+
To run Clippy’s lints on any Cargo project, enter the following:
117109

118110
```
119111
$ cargo clippy
120112
```
121113

122-
For example, if you write a program that uses an approximation of a
123-
mathematical constant such as pi, as this program does:
114+
For example, say you write a program that uses an approximation of a
115+
mathematical constant, such as pi, as this program does:
124116

125117
Filename: src/main.rs
126118

@@ -132,22 +124,24 @@ fn main() {
132124
}
133125
```
134126

135-
Running `cargo clippy` on this project will result in this error:
127+
Running `cargo clippy` on this project results in this error:
136128

137129
```
138-
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it directly
130+
error: approximate value of `f{32, 64}::consts::PI` found. Consider using it
131+
directly
139132
--> src/main.rs:2:13
140133
|
141134
2 | let x = 3.1415;
142135
| ^^^^^^
143136
|
144137
= note: #[deny(clippy::approx_constant)] on by default
145-
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#approx_constant
138+
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/master/index.html#approx_constant
146139
```
147140

148-
This lets you know that Rust has this constant defined more precisely, and that
149-
your program would be more correct if you used the constant instead. This code
150-
doesn’t result in any errors or warnings from `clippy`:
141+
This error lets you know that Rust has this constant defined more precisely,
142+
and that your program would be more correct if you used the constant instead.
143+
You would then change your code to use the `PI` constant. The following code
144+
doesn’t result in any errors or warnings from Clippy:
151145

152146
Filename: src/main.rs
153147

@@ -159,73 +153,70 @@ fn main() {
159153
}
160154
```
161155

162-
For more information on `clippy`, see its documentation at
163-
*https://github.com/rust-lang-nursery/rust-clippy*.
156+
For more information on Clippy, see its documentation at
157+
*https://github.com/rust-lang/rust-clippy/*.
164158

165159
## IDE Integration Using the Rust Language Server
166160

167-
To help IDE integration, the Rust project distributes the `rls`, which stands
168-
for the Rust Language Server. This tool speaks the Language Server Protocol
169-
described at *http://langserver.org/*, which is a specification for IDEs and
170-
programming languages to communicate with each other. The `rls` can be used by
171-
different clients, such as the Rust plugin for Visual Studio: Code at
172-
*https://marketplace.visualstudio.com/items?itemName=rust-lang.rust*.
161+
To help IDE integration, the Rust project distributes the *Rust Language
162+
Server* (`rls`). This tool speaks the Language Server Protocol described at
163+
*http://langserver.org/*, which is a specification for IDEs and programming
164+
languages to communicate with each other. Different clients can use the `rls`,
165+
such as the Rust plug-in for Visual Studio Code available from
166+
*https://marketplace.visualstudio.com/items?itemName=rust-lang.rust/*.
173167

174-
The `rls` is not yet at the quality of a version 1.0 release, but a preview is
175-
available for you to use in the meantime. Please give it a try and let us know
176-
how it goes!
177-
178-
To install the `rls`:
168+
To install the `rls`, enter the following:
179169

180170
```
181-
$ rustup component add rls-preview
171+
$ rustup component add rls
182172
```
183173

184-
Then install the language server support in your particular IDE, and you will
185-
gain abilities such as autocompletion, jump to definition, and inline errors.
174+
Then install the language server support in your particular IDE; you’ll gain
175+
abilities such as autocompletion, jump to definition, and inline errors.
186176

187177
For more information on the `rls`, see its documentation at
188-
*https://github.com/rust-lang-nursery/rls*.
178+
*https://github.com/rust-lang/rls/*.
189179

190180
# Appendix E - Editions
191181

192-
Way back in Chapter 1, we saw that `cargo new` adds a bit of metadata to your
193-
*Cargo.toml* about an `edition`. This appendix talks about what that means!
182+
In Chapter 1, you saw that `cargo new` adds a bit of metadata to your
183+
*Cargo.toml* file about an edition. This appendix talks about what that means!
194184

195-
The Rust language and compiler have a six-week release cycle. This means users
196-
get a constant stream of new features. Other programming languages release
197-
larger changes less often; Rust chooses to release smaller updates more
198-
frequently. After a while, all of those tiny changes add up. But from release
199-
to release, it can be hard to look back and say “Wow, between Rust 1.10 and
200-
Rust 1.31, Rust has changed a lot!”
185+
The Rust language and compiler have a six-week release cycle, meaning users get
186+
a constant stream of new features. Other programming languages release larger
187+
changes less often; Rust releases smaller updates more frequently. After a
188+
while, all of these tiny changes add up. But from release to release, it can be
189+
difficult to look back and say, “Wow, between Rust 1.10 and Rust 1.31, Rust has
190+
changed a lot!”
201191

202-
Every two or three years, the Rust team produces a new *edition* of Rust.
203-
Each edition brings together the features that have landed into a clear
204-
package with fully updated documentation and tooling. New editions ship
205-
as part of the usual six-week release process.
192+
Every two or three years, the Rust team produces a new Rust *edition*. Each
193+
edition brings together the features that have landed into a clear package with
194+
fully updated documentation and tooling. New editions ship as part of the usual
195+
six-week release process.
206196

207-
This serves different purposes for different people:
197+
Editions serve different purposes for different people:
208198

209-
* For active Rust users, it brings together incremental changes into an
210-
easy-to-understand package.
211-
* For non-users, it signals that some major advancements have landed, which
212-
might make Rust worth another look.
213-
* For those developing Rust itself, it provides a rallying point for the
199+
* For active Rust users, a new edition brings together incremental changes into
200+
an easy-to-understand package.
201+
* For non-users, a new edition signals that some major advancements have
202+
landed, which might make Rust worth another look.
203+
* For those developing Rust, a new edition provides a rallying point for the
214204
project as a whole.
215205

216-
At the time of writing, there are two editions: Rust 2015 and Rust 2018.
217-
This book is written using Rust 2018 edition idioms.
206+
At the time of this writing, two Rust editions are available: Rust 2015 and
207+
Rust 2018. This book is written using Rust 2018 edition idioms.
208+
209+
The `edition` key in *Cargo.toml* indicates which edition the compiler should
210+
use for your code. If the key doesn’t exist, Rust uses `2015` as the edition
211+
value for backward compatibility reasons.
218212

219-
The `edition` key in *Cargo.toml* indicates which edition your code should be
220-
compiled under. If the key does not exist, it defaults to `2015` for backwards
221-
compatibility reasons.
213+
Each project can opt in to an edition other than the default 2015 edition.
214+
Editions can contain incompatible changes, such as including a new keyword that
215+
conflicts with identifiers in code. However, unless you opt in to those
216+
changes, your code will continue to compile even as you upgrade the Rust
217+
compiler version you use.
222218

223-
Each project can choose to opt in to an edition other than the default 2015
224-
edition. By doing so, editions can contain incompatible changes, such as adding
225-
a new keyword that might conflict with identifiers in code or turning warnings
226-
into errors. But unless you opt in to those changes, your code will continue to
227-
compile even as you upgrade the version of the Rust compiler that you use. All
228-
Rust compiler versions support any edition that existed prior to that
219+
All Rust compiler versions support any edition that existed prior to that
229220
compiler’s release, and they can link crates of any supported editions
230221
together. Edition changes only affect the way the compiler initially parses
231222
code. Therefore, if you’re using Rust 2015 and one of your dependencies uses
@@ -234,12 +225,12 @@ opposite situation, where your project uses Rust 2018 and a dependency uses
234225
Rust 2015, works as well.
235226

236227
To be clear: most features will be available on all editions. Developers using
237-
any edition of Rust will continue to see improvements as new stable releases
238-
are made. In some cases, however, mainly when new keywords are added, there may
239-
be new features that are only available in later editions. You only need to
240-
switch editions if you want to take advantage of such features.
241-
242-
For more details, the Edition
243-
Guide at *https://rust-lang-nursery.github.io/edition-guide/* is a complete
244-
book about editions, including how to automatically upgrade your code to
245-
a new edition via `cargo fix`.
228+
any Rust edition will continue to see improvements as new stable releases are
229+
made. However, in some cases, mainly when new keywords are added, some new
230+
features might only be available in later editions. You will need to switch
231+
editions if you want to take advantage of such features.
232+
233+
For more details, the *Edition Guide* at
234+
*https://doc.rust-lang.org/stable/edition-guide/* is a complete book about
235+
editions that enumerates the differences between editions and explains how to
236+
automatically upgrade your code to a new edition via `cargo fix`.

nostarch/appendix-a-new-section.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
This is a new section to appear at the end of Appendix A, after the "Keywords Reserved for Future Use" section.
1+
This is a new section to appear at the end of Appendix A, after the “Keywords
2+
Reserved for Future Use” section.
23

34
### Raw Identifiers
45

5-
*Raw identifiers* let you use keywords where they would not normally be allowed
6-
by prefixing them with `r#`.
6+
*Raw identifiers* are the syntax that lets you use keywords where they wouldn’t
7+
normally be allowed. You use a raw identifier by prefixing a keyword with `r#`.
78

8-
For example, `match` is a keyword. If you try to compile this function that
9-
uses `match` as its name:
9+
For example, `match` is a keyword. If you try to compile the following function
10+
that uses `match` as its name:
1011

1112
Filename: src/main.rs
1213

@@ -26,8 +27,9 @@ error: expected identifier, found keyword `match`
2627
| ^^^^^ expected identifier, found keyword
2728
```
2829

29-
The error says that you can't use the keyword `match` as the function
30-
identifier. You can use `match` as a function name by using a raw identifier:
30+
The error shows that you can’t use the keyword `match` as the function
31+
identifier. To use `match` as a function name, you need to use the raw
32+
identifier syntax, like this:
3133

3234
Filename: src/main.rs
3335

@@ -41,15 +43,15 @@ fn main() {
4143
}
4244
```
4345

44-
This code will compile without any errors. Note the `r#` prefix on both the
45-
function name in its definition as well as where the function is called in
46-
`main`.
46+
This code will compile without any errors. Note the `r#` prefix on the function
47+
name in its definition as well as where the function is called in `main`.
4748

4849
Raw identifiers allow you to use any word you choose as an identifier, even if
4950
that word happens to be a reserved keyword. In addition, raw identifiers allow
5051
you to use libraries written in a different Rust edition than your crate uses.
51-
For example, `try` is not a keyword in the 2015 edition but is in the 2018
52-
edition. If you depend on a library that is written using the 2015 edition and
53-
has a `try` function, to call that function from your 2018 edition code, you’ll
54-
need to use the raw identifier syntax, `r#try` in this case. See Appendix
55-
E for more information on editions.
52+
For example, `try` isn’t a keyword in the 2015 edition but is in the 2018
53+
edition. If you depend on a library that’s written using the 2015 edition and
54+
has a `try` function, you’ll need to use the raw identifier syntax, `r#try` in
55+
this case, to call that function from your 2018 edition code. See Appendix E
56+
for more information on editions.
57+

nostarch/chapter19-new-function-pointer-text.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ page 448.
44

55
---
66

7-
Another useful pattern exploits an implementation detail of tuple structs and
8-
tuple-struct enum variants. These items use `()` as initializer syntax, which
9-
looks like a function call. The initializers are actually implemented as
10-
functions returning an instance constructed from their arguments. These
11-
initializer functions can also be used as a function pointer that implements
12-
the closure traits, so they can also be specified as arguments for methods that
13-
take closures:
7+
We have another useful pattern that exploits an implementation detail of tuple
8+
structs and tuple-struct enum variants. These types use `()` as initializer
9+
syntax, which looks like a function call. The initializers are actually
10+
implemented as functions returning an instance that’s constructed from their
11+
arguments. We can use these initializer functions as function pointers that
12+
implement the closure traits, which means we can specify the initializer
13+
functions as arguments for methods that take closures, like so:
1414

1515
```
1616
enum Status {
@@ -24,7 +24,8 @@ let list_of_statuses: Vec<Status> =
2424
.collect();
2525
```
2626

27-
This code creates `Status::Value` instances using each `u32` value in the range
27+
Here we create `Status::Value` instances using each `u32` value in the range
2828
that `map` is called on by using the initializer function of `Status::Value`.
29-
Some people prefer this style, and some people prefer to use closures. They end
30-
up compiling to the same code, so use whichever style is clearer to you.
29+
Some people prefer this style, and some people prefer to use closures. They
30+
compile to the same code, so use whichever style is clearer to you.
31+
44.1 KB
Binary file not shown.
31.6 KB
Binary file not shown.
25.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)