Skip to content

Commit 8d6d1be

Browse files
authored
Merge pull request #2134 from ehuss/unwrap-more
Unwrap more chapters
2 parents e8ba94e + 5c6fe9d commit 8d6d1be

17 files changed

Lines changed: 370 additions & 1052 deletions

src/attributes.md

Lines changed: 29 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ AttrInput ->
1717
```
1818

1919
r[attributes.intro]
20-
An _attribute_ is a general, free-form metadatum that is interpreted according
21-
to name, convention, language, and compiler version. Attributes are modeled
22-
on Attributes in [ECMA-335], with the syntax coming from [ECMA-334] \(C#).
20+
An _attribute_ is a general, free-form metadatum that is interpreted according to name, convention, language, and compiler version. Attributes are modeled on Attributes in [ECMA-335], with the syntax coming from [ECMA-334] \(C#).
2321

2422
r[attributes.inner]
2523
_Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the form that the attribute is declared within.
@@ -62,17 +60,10 @@ _Outer attributes_, written without the bang after the hash, apply to the form t
6260
> ```
6361
6462
r[attributes.input]
65-
The attribute consists of a path to the attribute, followed by an optional
66-
delimited token tree whose interpretation is defined by the attribute.
67-
Attributes other than macro attributes also allow the input to be an equals
68-
sign (`=`) followed by an expression. See the [meta item
69-
syntax](#meta-item-attribute-syntax) below for more details.
63+
The attribute consists of a path to the attribute, followed by an optional delimited token tree whose interpretation is defined by the attribute. Attributes other than macro attributes also allow the input to be an equals sign (`=`) followed by an expression. See the [meta item syntax](#meta-item-attribute-syntax) below for more details.
7064
7165
r[attributes.safety]
72-
An attribute may be unsafe to apply. To avoid undefined behavior when using
73-
these attributes, certain obligations that cannot be checked by the compiler
74-
must be met. To assert these have been, the attribute is wrapped in
75-
`unsafe(..)`, e.g. `#[unsafe(no_mangle)]`.
66+
An attribute may be unsafe to apply. To avoid undefined behavior when using these attributes, certain obligations that cannot be checked by the compiler must be met. To assert these have been, the attribute is wrapped in `unsafe(..)`, e.g. `#[unsafe(no_mangle)]`.
7667
7768
The following attributes are unsafe:
7869
@@ -92,29 +83,21 @@ Attributes can be classified into the following kinds:
9283
r[attributes.allowed-position]
9384
Attributes may be applied to many forms in the language:
9485
95-
* All [item declarations] accept outer attributes while [external blocks],
96-
[functions], [implementations], and [modules] accept inner attributes.
97-
* Most [statements] accept outer attributes (see [Expression Attributes] for
98-
limitations on expression statements).
99-
* [Block expressions] accept outer and inner attributes, but only when they are
100-
the outer expression of an [expression statement] or the final expression of
101-
another block expression.
86+
* All [item declarations] accept outer attributes while [external blocks], [functions], [implementations], and [modules] accept inner attributes.
87+
* Most [statements] accept outer attributes (see [Expression Attributes] for limitations on expression statements).
88+
* [Block expressions] accept outer and inner attributes, but only when they are the outer expression of an [expression statement] or the final expression of another block expression.
10289
* [Enum] variants and [struct] and [union] fields accept outer attributes.
10390
* [Match expression arms][match expressions] accept outer attributes.
10491
* [Generic lifetime or type parameter][generics] accept outer attributes.
105-
* Expressions accept outer attributes in limited situations, see [Expression
106-
Attributes] for details.
107-
* [Function][functions], [closure] and [function pointer]
108-
parameters accept outer attributes. This includes attributes on variadic parameters
109-
denoted with `...` in function pointers and [external blocks][variadic functions].
92+
* Expressions accept outer attributes in limited situations, see [Expression Attributes] for details.
93+
* [Function][functions], [closure] and [function pointer] parameters accept outer attributes. This includes attributes on variadic parameters denoted with `...` in function pointers and [external blocks][variadic functions].
11094
* [Inline assembly] template strings and operands accept outer attributes. Only certain attributes are accepted semantically; for details, see [asm.attributes.supported-attributes].
11195
11296
r[attributes.meta]
11397
## Meta item attribute syntax
11498
11599
r[attributes.meta.intro]
116-
A "meta item" is the syntax used for the [Attr] rule by most [built-in
117-
attributes]. It has the following grammar:
100+
A "meta item" is the syntax used for the [Attr] rule by most [built-in attributes]. It has the following grammar:
118101
119102
r[attributes.meta.syntax]
120103
```grammar,attributes
@@ -132,15 +115,10 @@ MetaItemInner ->
132115
```
133116
134117
r[attributes.meta.literal-expr]
135-
Expressions in meta items must macro-expand to literal expressions, which must not
136-
include integer or float type suffixes. Expressions which are not literal expressions
137-
will be syntactically accepted (and can be passed to proc-macros), but will be rejected after parsing.
118+
Expressions in meta items must macro-expand to literal expressions, which must not include integer or float type suffixes. Expressions which are not literal expressions will be syntactically accepted (and can be passed to proc-macros), but will be rejected after parsing.
138119

139120
r[attributes.meta.order]
140-
Note that if the attribute appears within another macro, it will be expanded
141-
after that outer macro. For example, the following code will expand the
142-
`Serialize` proc-macro first, which must preserve the `include_str!` call in
143-
order for it to be expanded:
121+
Note that if the attribute appears within another macro, it will be expanded after that outer macro. For example, the following code will expand the `Serialize` proc-macro first, which must preserve the `include_str!` call in order for it to be expanded:
144122

145123
```rust ignore
146124
#[derive(Serialize)]
@@ -162,9 +140,7 @@ fn foo() {}
162140
```
163141

164142
r[attributes.meta.builtin]
165-
Various built-in attributes use different subsets of the meta item syntax to
166-
specify their inputs. The following grammar rules show some commonly used
167-
forms:
143+
Various built-in attributes use different subsets of the meta item syntax to specify their inputs. The following grammar rules show some commonly used forms:
168144

169145
r[attributes.meta.builtin.syntax]
170146
```grammar,attributes
@@ -198,30 +174,21 @@ r[attributes.activity]
198174
## Active and inert attributes
199175

200176
r[attributes.activity.intro]
201-
An attribute is either active or inert. During attribute processing, *active
202-
attributes* remove themselves from the form they are on while *inert attributes*
203-
stay on.
177+
An attribute is either active or inert. During attribute processing, *active attributes* remove themselves from the form they are on while *inert attributes* stay on.
204178

205-
The [`cfg`] and [`cfg_attr`] attributes are active.
206-
[Attribute macros] are active. All other attributes are inert.
179+
The [`cfg`] and [`cfg_attr`] attributes are active. [Attribute macros] are active. All other attributes are inert.
207180

208181
r[attributes.tool]
209182
## Tool attributes
210183

211184
r[attributes.tool.intro]
212-
The compiler may allow attributes for external tools where each tool resides
213-
in its own module in the [tool prelude]. The first segment of the attribute
214-
path is the name of the tool, with one or more additional segments whose
215-
interpretation is up to the tool.
185+
The compiler may allow attributes for external tools where each tool resides in its own module in the [tool prelude]. The first segment of the attribute path is the name of the tool, with one or more additional segments whose interpretation is up to the tool.
216186

217187
r[attributes.tool.ignored]
218-
When a tool is not in use, the tool's attributes are accepted without a
219-
warning. When the tool is in use, the tool is responsible for processing and
220-
interpretation of its attributes.
188+
When a tool is not in use, the tool's attributes are accepted without a warning. When the tool is in use, the tool is responsible for processing and interpretation of its attributes.
221189

222190
r[attributes.tool.prelude]
223-
Tool attributes are not available if the [`no_implicit_prelude`] attribute is
224-
used.
191+
Tool attributes are not available if the [`no_implicit_prelude`] attribute is used.
225192

226193
```rust
227194
// Tells the rustfmt tool to not format the following element.
@@ -253,13 +220,11 @@ The following is an index of all built-in attributes.
253220

254221
- Derive
255222
- [`derive`] --- Automatic trait implementations.
256-
- [`automatically_derived`] --- Marker for implementations created by
257-
`derive`.
223+
- [`automatically_derived`] --- Marker for implementations created by `derive`.
258224

259225
- Macros
260226
- [`macro_export`] --- Exports a `macro_rules` macro for cross-crate usage.
261-
- [`macro_use`] --- Expands macro visibility, or imports macros from other
262-
crates.
227+
- [`macro_use`] --- Expands macro visibility, or imports macros from other crates.
263228
- [`proc_macro`] --- Defines a function-like macro.
264229
- [`proc_macro_derive`] --- Defines a derive macro.
265230
- [`proc_macro_attribute`] --- Defines an attribute macro.
@@ -268,27 +233,21 @@ The following is an index of all built-in attributes.
268233
- [`allow`], [`expect`], [`warn`], [`deny`], [`forbid`] --- Alters the default lint level.
269234
- [`deprecated`] --- Generates deprecation notices.
270235
- [`must_use`] --- Generates a lint for unused values.
271-
- [`diagnostic::on_unimplemented`] --- Hints the compiler to emit a certain error
272-
message if a trait is not implemented.
236+
- [`diagnostic::on_unimplemented`] --- Hints the compiler to emit a certain error message if a trait is not implemented.
273237
- [`diagnostic::do_not_recommend`] --- Hints the compiler to not show a certain trait impl in error messages.
274238

275239
- ABI, linking, symbols, and FFI
276240
- [`link`] --- Specifies a native library to link with an `extern` block.
277-
- [`link_name`] --- Specifies the name of the symbol for functions or statics
278-
in an `extern` block.
279-
- [`link_ordinal`] --- Specifies the ordinal of the symbol for functions or
280-
statics in an `extern` block.
241+
- [`link_name`] --- Specifies the name of the symbol for functions or statics in an `extern` block.
242+
- [`link_ordinal`] --- Specifies the ordinal of the symbol for functions or statics in an `extern` block.
281243
- [`no_link`] --- Prevents linking an extern crate.
282244
- [`repr`] --- Controls type layout.
283245
- [`crate_type`] --- Specifies the type of crate (library, executable, etc.).
284246
- [`no_main`] --- Disables emitting the `main` symbol.
285-
- [`export_name`] --- Specifies the exported symbol name for a function or
286-
static.
287-
- [`link_section`] --- Specifies the section of an object file to use for a
288-
function or static.
247+
- [`export_name`] --- Specifies the exported symbol name for a function or static.
248+
- [`link_section`] --- Specifies the section of an object file to use for a function or static.
289249
- [`no_mangle`] --- Disables symbol name encoding.
290-
- [`used`] --- Forces the compiler to keep a static item in the output
291-
object file.
250+
- [`used`] --- Forces the compiler to keep a static item in the output object file.
292251
- [`crate_name`] --- Specifies the crate name.
293252

294253
- Code generation
@@ -301,8 +260,7 @@ The following is an index of all built-in attributes.
301260
- [`instruction_set`] --- Specify the instruction set used to generate a function's code.
302261

303262
- Documentation
304-
- `doc` --- Specifies documentation. See [The Rustdoc Book] for more
305-
information. [Doc comments] are transformed into `doc` attributes.
263+
- `doc` --- Specifies documentation. See [The Rustdoc Book] for more information. [Doc comments] are transformed into `doc` attributes.
306264

307265
- Preludes
308266
- [`no_std`] --- Removes std from the prelude.
@@ -312,8 +270,7 @@ The following is an index of all built-in attributes.
312270
- [`path`] --- Specifies the filename for a module.
313271

314272
- Limits
315-
- [`recursion_limit`] --- Sets the maximum recursion limit for certain
316-
compile-time operations.
273+
- [`recursion_limit`] --- Sets the maximum recursion limit for certain compile-time operations.
317274
- [`type_length_limit`] --- Sets the maximum size of a polymorphic type.
318275

319276
- Runtime
@@ -322,12 +279,10 @@ The following is an index of all built-in attributes.
322279
- [`windows_subsystem`] --- Specifies the windows subsystem to link with.
323280

324281
- Features
325-
- `feature` --- Used to enable unstable or experimental compiler features. See
326-
[The Unstable Book] for features implemented in `rustc`.
282+
- `feature` --- Used to enable unstable or experimental compiler features. See [The Unstable Book] for features implemented in `rustc`.
327283

328284
- Type System
329-
- [`non_exhaustive`] --- Indicate that a type will have more fields/variants
330-
added in future.
285+
- [`non_exhaustive`] --- Indicate that a type will have more fields/variants added in future.
331286

332287
- Debugger
333288
- [`debugger_visualizer`] --- Embeds a file that specifies debugger output for a type.

0 commit comments

Comments
 (0)