Skip to content

Commit 5bbf146

Browse files
committed
Updates for Centril's review.
1 parent fdfcd8b commit 5bbf146

File tree

8 files changed

+78
-77
lines changed

8 files changed

+78
-77
lines changed

src/SUMMARY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
- [Derive](attributes/derive.md)
4545
- [Diagnostics](attributes/diagnostics.md)
4646
- [Code generation](attributes/codegen.md)
47-
- [Compiler settings](attributes/compiler-settings.md)
47+
- [Limits](attributes/limits.md)
4848

4949
- [Statements and expressions](statements-and-expressions.md)
5050
- [Statements](statements.md)

src/attributes.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,13 @@ The following is an index of all built-in attributes.
209209
- [`link_section`] — Specifies the section of an object file to use for a
210210
function or static.
211211
- [`no_mangle`] — Disables symbol name encoding.
212-
- [`used`] - Forces the compiler to keep a static variable in the output
212+
- [`used`] Forces the compiler to keep a static item in the output
213213
object file.
214214
- [`crate_name`] — Specifies the crate name.
215215
- Code generation
216216
- [`inline`] — Hint to inline code.
217217
- [`cold`] — Hint that a function is unlikely to be called.
218218
- [`no_builtins`] — Disables use of certain built-in functions.
219-
- Compiler setting attributes
220-
- `feature` — Used to enable unstable or experimental compiler features. See
221-
[The Unstable Book] for features implemented in `rustc`.
222-
- [`recursion_limit`] — Sets the maximum recursion limit for certain
223-
compile-time operations.
224219
- Documentation
225220
- `doc` — Specifies documentation. See [The Rustdoc Book] for more
226221
information. [Doc comments] are transformed into `doc` attributes.
@@ -229,10 +224,16 @@ The following is an index of all built-in attributes.
229224
- [`no_implicit_prelude`] — Disables prelude lookups within a module.
230225
- Modules
231226
- [`path`] — Specifies the filename for a module.
227+
- Limits
228+
- [`recursion_limit`] — Sets the maximum recursion limit for certain
229+
compile-time operations.
232230
- Runtime
233231
- [`panic_handler`] — Sets the function to handle panics.
234232
- [`global_allocator`] — Sets the global memory allocator.
235233
- [`windows_subsystem`] — Specifies the windows subsystem to link with.
234+
- Features
235+
- `feature` — Used to enable unstable or experimental compiler features. See
236+
[The Unstable Book] for features implemented in `rustc`.
236237

237238
[Doc comments]: comments.html#doc-comments
238239
[ECMA-334]: https://www.ecma-international.org/publications/standards/Ecma-334.htm
@@ -278,7 +279,7 @@ The following is an index of all built-in attributes.
278279
[`proc_macro_attribute`]: procedural-macros.html#attribute-macros
279280
[`proc_macro_derive`]: procedural-macros.html#derive-macros
280281
[`proc_macro`]: procedural-macros.html#function-like-procedural-macros
281-
[`recursion_limit`]: attributes/compiler-settings.html#the-recursion_limit-attribute
282+
[`recursion_limit`]: attributes/limits.html#the-recursion_limit-attribute
282283
[`repr`]: type-layout.html#representations
283284
[`should_panic`]: attributes/testing.html#the-should_panic-attribute
284285
[`test`]: attributes/testing.html#the-test-attribute

src/attributes/codegen.md

+15-14
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ The following [attributes] are used for controlling code generation.
44

55
## Optimization hints
66

7-
The `cold` and `inline` [attributes] give suggestions to the compiler to
8-
compile your code in a way that may be faster than what it would do without
9-
the hint. The attributes are only suggestions, and the compiler may choose to
10-
ignore it.
7+
The `cold` and `inline` [attributes] give suggestions to generate code in a
8+
way that may be faster than what it would do without the hint. The attributes
9+
are only hints, and may be ignored.
1110

1211
Both attributes can be used on [functions]. When applied to a function in a
1312
[trait], they apply only to that function when used as a default function for
@@ -16,24 +15,26 @@ have no effect on a trait function without a body.
1615

1716
### The `inline` attribute
1817

19-
The *`inline` [attribute]* suggests to the compiler that it should place a
20-
copy of the attributed function in the caller, rather than generating code to
21-
call the function where it is defined.
18+
The *`inline` [attribute]* suggests that a copy of the attributed function
19+
should be placed in the caller, rather than generating code to call the
20+
function where it is defined.
2221

23-
> ***Note***: The compiler automatically inlines functions based on internal
24-
> heuristics. Incorrectly inlining functions can actually make the program
22+
> ***Note***: The `rustc` compiler automatically inlines functions based on
23+
> internal heuristics. Incorrectly inlining functions can make the program
2524
> slower, so this attribute should be used with care.
2625
2726
There are three ways to use the inline attribute:
2827

29-
* `#[inline]` hints the compiler to perform an inline expansion.
30-
* `#[inline(always)]` asks the compiler to always perform an inline expansion.
31-
* `#[inline(never)]` asks the compiler to never perform an inline expansion.
28+
* `#[inline]` suggests performing an inline expansion.
29+
* `#[inline(always)]` suggests that an inline expansion should always be
30+
performed.
31+
* `#[inline(never)]` suggests that an inline expansion should never be
32+
performed.
3233

3334
### The `cold` attribute
3435

35-
The *`cold` [attribute]* suggests to the compiler that the attributed function
36-
is unlikely to be called.
36+
The *`cold` [attribute]* suggests that the attributed function is unlikely to
37+
be called.
3738

3839
## The `no_builtins` attribute
3940

src/attributes/derive.md

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Derive
22

3-
The *`derive` attribute* allows certain traits to be automatically implemented
4-
for data structures. It uses the [_MetaListPaths_] syntax to specify a list of
5-
traits to implement.
3+
The *`derive` attribute* allows new [items] to be automatically generated for
4+
data structures. It uses the [_MetaListPaths_] syntax to specify a list of
5+
traits to implement or paths to [derive macros] to process.
66

7-
For example, the following will create an `impl` for the
8-
`PartialEq` and `Clone` traits for `Foo`, and the type parameter `T` will be
7+
For example, the following will create an [`impl` item] for the
8+
[`PartialEq`] and [`Clone`] traits for `Foo`, and the type parameter `T` will be
99
given the `PartialEq` or `Clone` constraints for the appropriate `impl`:
1010

1111
```rust
@@ -34,4 +34,9 @@ impl<T: PartialEq> PartialEq for Foo<T> {
3434
You can implement `derive` for your own traits through [procedural macros].
3535

3636
[_MetaListPaths_]: attributes.html#meta-item-attribute-syntax
37-
[procedural macros]: procedural-macros.html
37+
[`Clone`]: ../std/clone/trait.Clone.html
38+
[`PartialEq`]: ../std/cmp/trait.PartialEq.html
39+
[`impl` item]: items/implementations.html
40+
[items]: items.html
41+
[derive macros]: procedural-macros.html#derive-macros
42+
[procedural macros]: procedural-macros.html#derive-macros

src/attributes/diagnostics.md

+33-37
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ For any lint check `C`:
1515

1616
* `allow(C)` overrides the check for `C` so that violations will go
1717
unreported,
18+
* `warn(C)` warns about violations of `C` but continues compilation.
1819
* `deny(C)` signals an error after encountering a violation of `C`,
1920
* `forbid(C)` is the same as `deny(C)`, but also forbids changing the lint
2021
level afterwards,
21-
* `warn(C)` warns about violations of `C` but continues compilation.
2222

23-
The lint checks supported by the compiler can be found via `rustc -W help`,
24-
along with their default settings and are documented in the [rustc book].
25-
[Compiler plugins] can provide additional lint checks.
23+
> Note: The lint checks supported by `rustc` can be found via `rustc -W help`,
24+
> along with their default settings and are documented in the [rustc book].
2625
2726
```rust
2827
pub mod m1 {
@@ -77,8 +76,8 @@ pub mod m3 {
7776

7877
### Tool lint attributes
7978

80-
Tool lints let you use scoped lints, to `allow`, `warn`, `deny` or `forbid` lints of
81-
certain tools.
79+
Tool lints allows using scoped lints, to `allow`, `warn`, `deny` or `forbid`
80+
lints of certain tools.
8281

8382
Currently `clippy` is the only available lint tool.
8483

@@ -146,11 +145,11 @@ The [RFC][1270-deprecation.md] contains motivations and more details.
146145

147146
[1270-deprecation.md]: https://github.com/rust-lang/rfcs/blob/master/text/1270-deprecation.md
148147

149-
150148
## The `must_use` attribute
151149

152150
The *`must_use` attribute* can be used on user-defined composite types
153-
([`struct`s][struct], [`enum`s][enum], and [`union`s][union]) and [functions].
151+
([`struct`s][struct], [`enum`s][enum], and [`union`s][union]), [functions],
152+
and [traits].
154153

155154
When used on user-defined composite types, if the [expression] of an
156155
[expression statement] has that type, then the `unused_must_use` lint is
@@ -159,32 +158,30 @@ violated.
159158
```rust
160159
#[must_use]
161160
struct MustUse {
162-
// some fields
161+
// some fields
163162
}
164163

165164
# impl MustUse {
166165
# fn new() -> MustUse { MustUse {} }
167166
# }
168167
#
169168
fn main() {
170-
// Violates the `unused_must_use` lint.
171-
MustUse::new();
169+
// Violates the `unused_must_use` lint.
170+
MustUse::new();
172171
}
173172
```
174173

175-
When used on a function, if the [expression] of an
176-
[expression statement] is a [call expression] to that function, then the
177-
`unused_must_use` lint is violated. The exceptions to this is if the return type
178-
of the function is `()`, `!`, or a [zero-variant enum], in which case the
179-
attribute does nothing.
174+
When used on a function, if the [expression] of an [expression statement] is a
175+
[call expression] to that function, then the `unused_must_use` lint is
176+
violated.
180177

181178
```rust
182179
#[must_use]
183180
fn five() -> i32 { 5i32 }
184181

185182
fn main() {
186-
// Violates the unused_must_use lint.
187-
five();
183+
// Violates the unused_must_use lint.
184+
five();
188185
}
189186
```
190187

@@ -193,21 +190,21 @@ when the call expression is a function from an implementation of the trait.
193190

194191
```rust
195192
trait Trait {
196-
#[must_use]
197-
fn use_me(&self) -> i32;
193+
#[must_use]
194+
fn use_me(&self) -> i32;
198195
}
199196

200197
impl Trait for i32 {
201-
fn use_me(&self) -> i32 { 0i32 }
198+
fn use_me(&self) -> i32 { 0i32 }
202199
}
203200

204201
fn main() {
205-
// Violates the `unused_must_use` lint.
206-
5i32.use_me();
202+
// Violates the `unused_must_use` lint.
203+
5i32.use_me();
207204
}
208205
```
209206

210-
When used on a function in an implementation, the attribute does nothing.
207+
When used on a function in a trait implementation, the attribute does nothing.
211208

212209
> Note: Trivial no-op expressions containing the value will not violate the
213210
> lint. Examples include wrapping the value in a type that does not implement
@@ -219,14 +216,14 @@ When used on a function in an implementation, the attribute does nothing.
219216
> fn five() -> i32 { 5i32 }
220217
>
221218
> fn main() {
222-
> // None of these violate the unused_must_use lint.
223-
> (five(),);
224-
> Some(five());
225-
> { five() };
226-
> if true { five() } else { 0i32 };
227-
> match true {
228-
> _ => five()
229-
> };
219+
> // None of these violate the unused_must_use lint.
220+
> (five(),);
221+
> Some(five());
222+
> { five() };
223+
> if true { five() } else { 0i32 };
224+
> match true {
225+
> _ => five()
226+
> };
230227
> }
231228
> ```
232229
@@ -238,17 +235,16 @@ When used on a function in an implementation, the attribute does nothing.
238235
> fn five() -> i32 { 5i32 }
239236
>
240237
> fn main() {
241-
> // Does not violate the unused_must_use lint.
242-
> let _ = five();
238+
> // Does not violate the unused_must_use lint.
239+
> let _ = five();
243240
> }
244241
> ```
245242
246-
The `must_use` attribute may also include a message by using the
243+
The `must_use` attribute may include a message by using the
247244
[_MetaNameValueStr_] syntax such as `#[must_use = "example message"]`. The
248245
message will be given alongside the warning.
249246
250247
[Clippy]: https://github.com/rust-lang/rust-clippy
251-
[Compiler plugins]: ../unstable-book/language-features/plugin.html#lint-plugins
252248
[_MetaListNameValueStr_]: attributes.html#meta-item-attribute-syntax
253249
[_MetaListPaths_]: attributes.html#meta-item-attribute-syntax
254250
[_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax
@@ -271,5 +267,5 @@ message will be given alongside the warning.
271267
[struct]: items/structs.html
272268
[trait implementation items]: items/implementations.html#trait-implementations
273269
[trait item]: items/traits.html
270+
[traits]: items/traits.html
274271
[union]: items/unions.html
275-
[zero-variant enum]: items/enumerations.html#zero-variant-enums

src/attributes/compiler-settings.md renamed to src/attributes/limits.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Compiler setting attributes
1+
# Limits
22

3-
The following [attributes] affect internal settings of the compiler.
3+
The following [attributes] affect compile-time limits.
44

55
## The `recursion_limit` attribute
66

src/attributes/testing.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ enables the [`test` conditional compilation option].
77

88
## The `test` attribute
99

10-
The *`test` attribute* marks a function to be executed as a test when the
11-
crate is compiled in test mode. These functions are only compiled when
12-
compiling in test mode. Test functions must take no arguments, must not
13-
declare any [trait or lifetime bounds], must not have any [where clauses], and
14-
its return type must be one of the following:
10+
The *`test` attribute* marks a function to be executed as a test. These
11+
functions are only compiled when in test mode. Test functions must be free,
12+
monomorphic functions that take no arguments, and the return type must be one
13+
of the following:
1514

1615
* `()`
1716
* `Result<(), E> where E: Error`
@@ -28,8 +27,8 @@ its return type must be one of the following:
2827
> or using `cargo test`.
2928
3029
Tests that return `()` pass as long as they terminate and do not panic. Tests
31-
that return a `Result` pass as long as they return `Ok(())`. Tests that do not
32-
terminate neither pass nor fail.
30+
that return a `Result<(), E>` pass as long as they return `Ok(())`. Tests that
31+
do not terminate neither pass nor fail.
3332

3433
```rust
3534
# use std::io;
@@ -47,8 +46,7 @@ fn test_the_thing() -> io::Result<()> {
4746

4847
A function annotated with the `test` attribute can also be annotated with the
4948
`ignore` attribute. The *`ignore` attribute* tells the test harness to not
50-
execute that function as a test. It will still only be compiled when compiling
51-
with the test harness.
49+
execute that function as a test. It will still be compiled when in test mode.
5250

5351
The `ignore` attribute may optionally be written with the [_MetaNameValueStr_]
5452
syntax to specify a reason why the test is ignored.

src/items/extern-crates.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ by using an underscore with the form `extern crate foo as _`. This may be
9393
useful for crates that only need to be linked, but are never referenced, and
9494
will avoid being reported as unused.
9595
96-
The [`macro_use` attribute] will work as usual and import the macro names
96+
The [`macro_use` attribute] works as usual and import the macro names
9797
into the macro-use prelude.
9898
9999
## The `no_link` attribute

0 commit comments

Comments
 (0)