Skip to content

Commit fdfcd8b

Browse files
committed
Update for review comments.
- Various fixes. - Move new pages to an `attributes` subdirectory. - Add some introductory text to new pages. - Remove "closure" from `cold` and `inline`, it is not stable. - Remove TODOs. - Added link for `feature`.
1 parent 993393d commit fdfcd8b

21 files changed

+87
-115
lines changed

src/SUMMARY.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@
4040
- [Visibility and Privacy](visibility-and-privacy.md)
4141

4242
- [Attributes](attributes.md)
43-
- [Derive](derive.md)
44-
- [Compiler attributes](compiler-attrs.md)
43+
- [Testing](attributes/testing.md)
44+
- [Derive](attributes/derive.md)
45+
- [Diagnostics](attributes/diagnostics.md)
46+
- [Code generation](attributes/codegen.md)
47+
- [Compiler settings](attributes/compiler-settings.md)
4548

4649
- [Statements and expressions](statements-and-expressions.md)
4750
- [Statements](statements.md)
@@ -117,12 +120,6 @@
117120

118121
- [The Rust runtime](runtime.md)
119122

120-
- [Code generation](codegen.md)
121-
122-
- [Testing](testing.md)
123-
124-
- [Diagnostics](diagnostics.md)
125-
126123
- [Appendices](appendices.md)
127124
- [Macro Follow-Set Ambiguity Formal Specification](macro-ambiguity.md)
128125
- [Influences](influences.md)

src/attributes-redirect.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44
"#cold-attribute": "codegen.html#the-cold-attribute",
55
"#conditional-compilation": "conditional-compilation.html",
66
"#deprecation": "diagnostics.html#the-deprecated-attribute",
7-
"#derive": "derive.html",
7+
"#derive": "attributes/derive.html",
88
"#documentation": "../rustdoc/the-doc-attribute.html",
9-
"#ffi-attributes": "attributes.html#built-in-attributes",
9+
"#ffi-attributes": "attributes.html#built-in-attributes-index",
1010
"#inline-attribute": "codegen.html#the-inline-attribute",
1111
"#lint-check-attributes": "diagnostics.html#lint-check-attributes",
12-
"#macro-related-attributes": "attributes.html#built-in-attributes",
13-
"#miscellaneous-attributes": "attributes.html#built-in-attributes",
12+
"#macro-related-attributes": "attributes.html#built-in-attributes-index",
13+
"#miscellaneous-attributes": "attributes.html#built-in-attributes-index",
1414
"#must_use": "diagnostics.html#the-must_use-attribute",
1515
"#optimization-hints": "codegen.html#optimization-hints",
1616
"#path": "items/modules.html#the-path-attribute",
1717
"#preludes": "crates-and-source-files.html#preludes-and-no_std",
1818
"#testing": "testing.html",
1919
"#tool-lint-attributes": "diagnostics.html#tool-lint-attributes",
20-
"#crate-only-attributes": "attributes.html#built-in-attributes",
20+
"#crate-only-attributes": "attributes.html#built-in-attributes-index",
2121
};
2222
var target = fragments[window.location.hash];
2323
if (target) {

src/attributes.md

+23-24
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ pub fn f() {}
172172

173173
> Note: `rustc` currently recognizes the tools "clippy" and "rustfmt".
174174
175-
## Built-in attributes
175+
## Built-in attributes index
176176

177177
The following is an index of all built-in attributes.
178178

179-
- Conditional Compilation
179+
- Conditional compilation
180180
- [`cfg`] — Controls conditional compilation.
181181
- [`cfg_attr`] — Conditionally includes attributes.
182182
- Testing
@@ -185,7 +185,6 @@ The following is an index of all built-in attributes.
185185
- [`should_panic`] — Indicates a test should generate a panic.
186186
- Derive
187187
- [`derive`] — Automatic trait implementations.
188-
<!-- automatically_derived -->
189188
- Macros
190189
- [`macro_export`] — Exports a `macro_rules` macro for cross-crate usage.
191190
- [`macro_use`] — Expands macro visibility, or imports macros from other
@@ -197,7 +196,7 @@ The following is an index of all built-in attributes.
197196
- [`allow`], [`warn`], [`deny`], [`forbid`] — Alters the default lint level.
198197
- [`deprecated`] — Generates deprecation notices.
199198
- [`must_use`] — Generates a lint for unused values.
200-
- ABI, Linking, Symbols, and FFI
199+
- ABI, linking, symbols, and FFI
201200
- [`link`] — Specifies a native library to link with an `extern` block.
202201
- [`link_name`] — Specifies the name of the symbol for functions or statics
203202
in an `extern` block.
@@ -213,16 +212,15 @@ The following is an index of all built-in attributes.
213212
- [`used`] - Forces the compiler to keep a static variable in the output
214213
object file.
215214
- [`crate_name`] — Specifies the crate name.
216-
- Code Generation
215+
- Code generation
217216
- [`inline`] — Hint to inline code.
218217
- [`cold`] — Hint that a function is unlikely to be called.
219218
- [`no_builtins`] — Disables use of certain built-in functions.
220-
<!-- target_feature -->
221-
- Compiler Settings
219+
- Compiler setting attributes
220+
- `feature` — Used to enable unstable or experimental compiler features. See
221+
[The Unstable Book] for features implemented in `rustc`.
222222
- [`recursion_limit`] — Sets the maximum recursion limit for certain
223223
compile-time operations.
224-
<!-- feature -->
225-
<!--type_length_limit -->
226224
- Documentation
227225
- `doc` — Specifies documentation. See [The Rustdoc Book] for more
228226
information. [Doc comments] are transformed into `doc` attributes.
@@ -244,31 +242,32 @@ The following is an index of all built-in attributes.
244242
[RAW_STRING_LITERAL]: tokens.html#raw-string-literals
245243
[STRING_LITERAL]: tokens.html#string-literals
246244
[The Rustdoc Book]: ../rustdoc/the-doc-attribute.html
245+
[The Unstable Book]: ../unstable-book/index.html
247246
[_DelimTokenTree_]: macros.html
248247
[_LiteralExpression_]: expressions/literal-expr.html
249248
[_SimplePath_]: paths.html#simple-paths
250-
[`allow`]: diagnostics.html#lint-check-attributes
249+
[`allow`]: attributes/diagnostics.html#lint-check-attributes
251250
[`cfg_attr`]: conditional-compilation.html#the-cfg_attr-attribute
252251
[`cfg`]: conditional-compilation.html#the-cfg-attribute
253-
[`cold`]: codegen.html#the-cold-attribute
252+
[`cold`]: attributes/codegen.html#the-cold-attribute
254253
[`crate_name`]: crates-and-source-files.html#the-crate_name-attribute
255254
[`crate_type`]: linkage.html
256-
[`deny`]: diagnostics.html#lint-check-attributes
257-
[`deprecated`]: diagnostics.html#the-deprecated-attribute
258-
[`derive`]: derive.html
255+
[`deny`]: attributes/diagnostics.html#lint-check-attributes
256+
[`deprecated`]: attributes/diagnostics.html#the-deprecated-attribute
257+
[`derive`]: attributes/derive.html
259258
[`export_name`]: abi.html#the-export_name-attribute
260-
[`forbid`]: diagnostics.html#lint-check-attributes
259+
[`forbid`]: attributes/diagnostics.html#lint-check-attributes
261260
[`global_allocator`]: runtime.html#the-global_allocator-attribute
262-
[`ignore`]: testing.html#the-ignore-attribute
263-
[`inline`]: codegen.html#the-inline-attribute
261+
[`ignore`]: attributes/testing.html#the-ignore-attribute
262+
[`inline`]: attributes/codegen.html#the-inline-attribute
264263
[`link_name`]: items/external-blocks.html#the-link_name-attribute
265264
[`link_section`]: abi.html#the-link_section-attribute
266265
[`link`]: items/external-blocks.html#the-link-attribute
267266
[`macro_export`]: macros-by-example.html#path-based-scope
268267
[`macro_use`]: macros-by-example.html#the-macro_use-attribute
269268
[`meta` macro fragment specifier]: macros-by-example.html
270-
[`must_use`]: diagnostics.html#the-must_use-attribute
271-
[`no_builtins`]: codegen.html#the-no_builtins-attribute
269+
[`must_use`]: attributes/diagnostics.html#the-must_use-attribute
270+
[`no_builtins`]: attributes/codegen.html#the-no_builtins-attribute
272271
[`no_implicit_prelude`]: items/modules.html#prelude-items
273272
[`no_link`]: items/extern-crates.html#the-no_link-attribute
274273
[`no_main`]: crates-and-source-files.html#the-no_main-attribute
@@ -279,16 +278,16 @@ The following is an index of all built-in attributes.
279278
[`proc_macro_attribute`]: procedural-macros.html#attribute-macros
280279
[`proc_macro_derive`]: procedural-macros.html#derive-macros
281280
[`proc_macro`]: procedural-macros.html#function-like-procedural-macros
282-
[`recursion_limit`]: compiler-attrs.html#the-recursion_limit-attribute
281+
[`recursion_limit`]: attributes/compiler-settings.html#the-recursion_limit-attribute
283282
[`repr`]: type-layout.html#representations
284-
[`should_panic`]: testing.html#the-should_panic-attribute
285-
[`test`]: testing.html#the-test-attribute
283+
[`should_panic`]: attributes/testing.html#the-should_panic-attribute
284+
[`test`]: attributes/testing.html#the-test-attribute
286285
[`used`]: abi.html#the-used-attribute
287-
[`warn`]: diagnostics.html#lint-check-attributes
286+
[`warn`]: attributes/diagnostics.html#lint-check-attributes
288287
[`windows_subsystem`]: runtime.html#the-windows_subsystem-attribute
289288
[attribute macros]: procedural-macros.html#attribute-macros
290289
[block expressions]: expressions/block-expr.html
291-
[built-in attributes]: #built-in-attributes
290+
[built-in attributes]: #built-in-attributes-index
292291
[derive macro helper attributes]: procedural-macros.html#derive-macro-helper-attributes
293292
[enum]: items/enumerations.html
294293
[expression statement]: statements.html#expression-statements

src/codegen.md renamed to src/attributes/codegen.md

+8-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Code generation
1+
# Code generation attributes
22

3-
<!-- TODO: target_feature -->
3+
The following [attributes] are used for controlling code generation.
44

55
## Optimization hints
66

@@ -9,14 +9,10 @@ compile your code in a way that may be faster than what it would do without
99
the hint. The attributes are only suggestions, and the compiler may choose to
1010
ignore it.
1111

12-
Both attributes can be used on closures and [functions]. When applied to a
13-
function in a [trait], they apply only to that function when used as a default
14-
function for a trait implementation and not to all trait implementations. The
15-
attributes have no effect on a trait function without a body.
16-
17-
<!-- TODO: I believe it is currently not possible to use these on closures
18-
because attributes are not allowed on expressions. May want to consider
19-
removing "closure" here until it is stabilized. -->
12+
Both attributes can be used on [functions]. When applied to a function in a
13+
[trait], they apply only to that function when used as a default function for
14+
a trait implementation and not to all trait implementations. The attributes
15+
have no effect on a trait function without a body.
2016

2117
### The `inline` attribute
2218

@@ -36,28 +32,15 @@ There are three ways to use the inline attribute:
3632

3733
### The `cold` attribute
3834

39-
The *`cold` [attribute]* suggests to the compiler that the attributed function or
40-
closure is unlikely to be called.
41-
<!-- TODO: Expand this section.
42-
Should the exact semantics be documented here, or in rustc book?
43-
rustc:
44-
- Reduces threshold for being inlined.
45-
- "This calling convention attempts to make code in the caller as
46-
efficient as possible under the assumption that the call is not commonly
47-
executed. As such, these calls often preserve all registers so that the
48-
call does not break any live ranges in the caller side."
49-
-->
35+
The *`cold` [attribute]* suggests to the compiler that the attributed function
36+
is unlikely to be called.
5037

5138
## The `no_builtins` attribute
5239

5340
The *`no_builtins` [attribute]* may be applied at the crate level to disable
5441
optimizing certain code patterns to invocations of library functions that are
5542
assumed to exist.
5643

57-
<!-- TODO: This needs more information.
58-
This disables LTO, should that be mentioned, or in rustc book?
59-
-->
60-
6144
[attribute]: attributes.html
6245
[attributes]: attributes.html
6346
[functions]: items/functions.html
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
# Compiler attributes
1+
# Compiler setting attributes
22

33
The following [attributes] affect internal settings of the compiler.
44

5-
<!-- TODO: feature -->
6-
75
## The `recursion_limit` attribute
86

97
The *`recursion_limit` attribute* may be applied at the crate level to set the
@@ -12,7 +10,5 @@ like auto-dereference or macro expansion. It uses the [_MetaNameValueStr_]
1210
syntax to specify the recursion depth. The default is
1311
`#![recursion_limit="64"]`.
1412

15-
<!-- TODO: type_length_limit -->
16-
1713
[attributes]: attributes.html
1814
[_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax

src/derive.md renamed to src/attributes/derive.md

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

3-
<!-- TODO: Maybe link to https://doc.rust-lang.org/book/appendix-03-derivable-traits.html ?
4-
Should the reference say more about which traits are derivable?
5-
-->
6-
73
The *`derive` attribute* allows certain traits to be automatically implemented
84
for data structures. It uses the [_MetaListPaths_] syntax to specify a list of
95
traits to implement.
@@ -37,7 +33,5 @@ impl<T: PartialEq> PartialEq for Foo<T> {
3733

3834
You can implement `derive` for your own traits through [procedural macros].
3935

40-
<!-- TODO: automatically_derived -->
41-
4236
[_MetaListPaths_]: attributes.html#meta-item-attribute-syntax
4337
[procedural macros]: procedural-macros.html

src/diagnostics.md renamed to src/attributes/diagnostics.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# Diagnostics
1+
# Diagnostic attributes
2+
3+
The following [attributes] are used for controlling or generating diagnostic
4+
messages during compilation.
25

36
## Lint check attributes
47

@@ -250,6 +253,7 @@ message will be given alongside the warning.
250253
[_MetaListPaths_]: attributes.html#meta-item-attribute-syntax
251254
[_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax
252255
[`Drop`]: special-types-and-traits.html#drop
256+
[attributes]: attributes.html
253257
[block expression]: expressions/block-expr.html
254258
[call expression]: expressions/call-expr.html
255259
[enum variant]: items/enumerations.html

src/testing.md renamed to src/attributes/testing.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# Testing
1+
# Testing attributes
2+
3+
The following [attributes] are used for specifying functions for performing
4+
tests. Compiling a crate in "test" mode enables building the test functions
5+
along with a test harness for executing the tests. Enabling the test mode also
6+
enables the [`test` conditional compilation option].
27

38
## The `test` attribute
49

5-
The compiler comes with a default test framework. It works by attributing
6-
functions with the `test` attribute. These functions are only compiled when
7-
compiling with the test harness. Like [main], functions annotated with this
8-
attribute must take no arguments, must not declare any
9-
[trait or lifetime bounds], must not have any [where clauses], and its return
10-
type must be one of the following:
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:
1115

1216
* `()`
1317
* `Result<(), E> where E: Error`
@@ -20,8 +24,8 @@ type must be one of the following:
2024
<!-- If the previous section needs updating (from "must take no arguments"
2125
onwards, also update it in the crates-and-source-files.md file -->
2226

23-
> Note: The test harness is ran by passing the `--test` argument to `rustc` or
24-
> using `cargo test`.
27+
> Note: The test mode is enabled by passing the `--test` argument to `rustc`
28+
> or using `cargo test`.
2529
2630
Tests that return `()` pass as long as they terminate and do not panic. Tests
2731
that return a `Result` pass as long as they return `Ok(())`. Tests that do not
@@ -83,6 +87,7 @@ fn mytest() {
8387
[_MetaListNameValueStr_]: attributes.html#meta-item-attribute-syntax
8488
[_MetaNameValueStr_]: attributes.html#meta-item-attribute-syntax
8589
[`Termination`]: ../std/process/trait.Termination.html
86-
[main]: crates-and-source-files.html
90+
[`test` conditional compilation option]: conditional-compilation.html#test
91+
[attributes]: attributes.html
8792
[trait or lifetime bounds]: trait-bounds.html
8893
[where clauses]: items/generics.html#where-clauses

src/conditional-compilation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ println!("I'm running on a {} machine!", machine_kind);
297297
[IDENTIFIER]: identifiers.html
298298
[RAW_STRING_LITERAL]: tokens.html#raw-string-literals
299299
[STRING_LITERAL]: tokens.html#string-literals
300-
[Testing]: testing.html
300+
[Testing]: attributes/testing.html
301301
[_Attr_]: attributes.html
302302
[`--cfg`]: ../rustc/command-line-arguments.html#a--cfg-configure-the-compilation-environment
303303
[`--test`]: ../rustc/command-line-arguments.html#a--test-build-a-test-harness

src/crates-and-source-files.md

-3
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,6 @@ name of the crate with the [_MetaNameValueStr_] syntax.
143143
The crate name must not be empty, and must only contain [Unicode alphanumeric]
144144
or `-` (U+002D) characters.
145145

146-
<!-- TODO: I feel like this should say more about what the crate name is and
147-
what it is used for. -->
148-
149146
[^phase-distinction]: This distinction would also exist in an interpreter.
150147
Static checks like syntactic analysis, type checking, and lints should
151148
happen before the program is executed regardless of when it is executed.

src/expressions/block-expr.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn is_unix_platform() -> bool {
148148
[statement]: statements.html
149149
[statements]: statements.html
150150
[struct]: expressions/struct-expr.html
151-
[the lint check attributes]: diagnostics.html#lint-check-attributes
151+
[the lint check attributes]: attributes/diagnostics.html#lint-check-attributes
152152
[tuple expressions]: expressions/tuple-expr.html
153153
[unsafe operations]: unsafety.html
154154
[value expressions]: expressions.html#place-expressions-and-value-expressions

src/expressions/match-expr.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ expressions].
141141
[_InnerAttribute_]: attributes.html
142142
[_OuterAttribute_]: attributes.html
143143
[`cfg`]: conditional-compilation.html
144-
[`cold`]: codegen.html#the-cold-attribute
145-
[lint check attributes]: diagnostics.html#lint-check-attributes
144+
[`cold`]: attributes/codegen.html#the-cold-attribute
145+
[lint check attributes]: attributes/diagnostics.html#lint-check-attributes
146146
[Range Expression]: expressions/range-expr.html
147147
148148
[_Pattern_]: patterns.html

src/items/external-blocks.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Finally, there are some rustc-specific ABI strings:
9292
* `extern "platform-intrinsic"` -- Specific platform intrinsics -- like, for
9393
example, `sqrt` -- have this ABI. You should never have to deal with it.
9494

95-
## Variadic Functions
95+
## Variadic functions
9696

9797
Functions within external blocks may be variadic by specifying `...` after one
9898
or more named arguments in the argument list:
@@ -121,8 +121,6 @@ the following possible values:
121121
- `framework` — Indicates a macOS framework. This is only valid for macOS
122122
targets.
123123

124-
<!-- TODO: Document wasm_import_module, see https://github.com/rust-lang/rust/pull/52445 -->
125-
126124
```rust,ignore
127125
#[link(name = "crypto")]
128126
extern {

0 commit comments

Comments
 (0)