Skip to content

Commit 78c712d

Browse files
committed
Explicitly specify syntax forms for each attribute
1 parent e0a0414 commit 78c712d

File tree

5 files changed

+61
-11
lines changed

5 files changed

+61
-11
lines changed

src/attributes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ An attribute is either active or inert. During attribute processing, *active
197197
attributes* remove themselves from the thing they are on while *inert attributes*
198198
stay on.
199199

200+
r[attributes.activity.builtin]
200201
The [`cfg`] and [`cfg_attr`] attributes are active. The [`test`] attribute is
201202
inert when compiling for tests and active otherwise. [Attribute macros] are
202203
active. All other attributes are inert.

src/attributes/codegen.md

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ function where it is defined.
3232
> internal heuristics. Incorrectly inlining functions can make the program
3333
> slower, so this attribute should be used with care.
3434
35+
r[attributes.codegen.inline.syntax]
36+
The `inline` attribute uses either [_MetaWord_] syntax (for the default form), or [_MetaListIdents_] syntax.
37+
When using [_MetaListIdents_] form, only a single ident is permitted.
38+
3539
r[attributes.codegen.inline.modes]
3640
There are three ways to use the inline attribute:
3741

@@ -48,25 +52,46 @@ There are three ways to use the inline attribute:
4852

4953
r[attributes.codegen.cold]
5054

55+
r[attributes.codegen.cold.intro]
5156
The *`cold` [attribute]* suggests that the attributed function is unlikely to
5257
be called.
5358

59+
> [!NOTE]
60+
> In particular, it indicates that branches that lead to such a call are unlikely to be taken.
61+
62+
r[attributes.codegen.cold.syntax]
63+
The `cold` attribute uses the [_MetaWord_] syntax.
64+
5465
## The `no_builtins` attribute
5566

5667
r[attributes.codegen.no_builtins]
5768

69+
r[attributes.codegen.no_builtins.intro]
5870
The *`no_builtins` [attribute]* may be applied at the crate level to disable
5971
optimizing certain code patterns to invocations of library functions that are
6072
assumed to exist.
6173

74+
> [!NOTE]
75+
> Such library functions may include, but are not limited to, C routines such as `memcpy` or `memset`.
76+
77+
> [!WARN]
78+
> A crate using `no_builtins` does not guarantee that the crate will be free from calls to such functions, even if it does not call the routines explicit.
79+
> For example, the standard library implementation may still call such functions.
80+
81+
r[attributes.codegen.no_builtins.syntax]
82+
The `no_builtins` attribute uses the [_MetaWord_] syntax.
83+
6284
## The `target_feature` attribute
6385

6486
r[attributes.codegen.target_feature]
6587

6688
r[attributes.codegen.target_feature.intro]
6789
The *`target_feature` [attribute]* may be applied to a function to
6890
enable code generation of that function for specific platform architecture
69-
features. It uses the [_MetaListNameValueStr_] syntax with a single key of
91+
features.
92+
93+
r[attributes.codegen.target_feature.syntax]
94+
The `target_feature` attribute uses the [_MetaListNameValueStr_] syntax with a single key of
7095
`enable` whose value is a string of comma-separated feature names to enable.
7196

7297
```rust
@@ -182,7 +207,6 @@ Reference Manual], or elsewhere on [developer.arm.com].
182207
> or disabled together if used:
183208
> - `paca` and `pacg`, which LLVM currently implements as one feature.
184209
185-
186210
Feature | Implicitly Enables | Feature Name
187211
---------------|--------------------|-------------------
188212
`aes` | `neon` | FEAT_AES & FEAT_PMULL --- Advanced <abbr title="Single Instruction Multiple Data">SIMD</abbr> AES & PMULL instructions
@@ -354,6 +378,9 @@ r[attributes.codegen.track_caller.allowed-positions]
354378
The `track_caller` attribute may be applied to any function with [`"Rust"` ABI][rust-abi]
355379
with the exception of the entry point `fn main`.
356380

381+
r[attributes.codegen.track_caller.syntax]
382+
The `track_caller` attribute uses the [_MetaWord_] syntax.
383+
357384
r[attributes.codegen.track_caller.traits]
358385
When applied to functions and methods in trait declarations, the attribute applies to all implementations. If the trait provides a
359386
default implementation with the attribute, then the attribute also applies to override implementations.
@@ -364,8 +391,6 @@ implementations, otherwise undefined behavior results. When applied to a functio
364391
available to an `extern` block, the declaration in the `extern` block must also have the attribute,
365392
otherwise undefined behavior results.
366393

367-
### Behavior
368-
369394
r[attributes.codegen.track_caller.behavior]
370395
Applying the attribute to a function `f` allows code within `f` to get a hint of the [`Location`] of
371396
the "topmost" tracked call that led to `f`'s invocation. At the point of observation, an
@@ -385,7 +410,7 @@ fn f() {
385410
> Note: because the resulting `Location` is a hint, an implementation may halt its walk up the stack
386411
> early. See [Limitations](#limitations) for important caveats.
387412
388-
#### Examples
413+
### Examples
389414

390415
When `f` is called directly by `calls_f`, code in `f` observes its callsite within `calls_f`:
391416

@@ -464,7 +489,6 @@ trait object whose methods are attributed.
464489
> creation of a shim hides the implicit parameter from callers of the function pointer, preserving
465490
> soundness.
466491
467-
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
468492
[`-C target-cpu`]: ../../rustc/codegen-options/index.html#target-cpu
469493
[`-C target-feature`]: ../../rustc/codegen-options/index.html#target-feature
470494
[`is_x86_feature_detected`]: ../../std/arch/macro.is_x86_feature_detected.html
@@ -493,8 +517,6 @@ This allows mixing more than one instruction set in a single program on CPU arch
493517
r[attributes.codegen.instruction_set.syntax]
494518
It uses the [_MetaListPath_] syntax, and a path comprised of the architecture family name and instruction set name.
495519

496-
[_MetaListPath_]: ../attributes.md#meta-item-attribute-syntax
497-
498520
r[attributes.codegen.instruction_set.target-limits]
499521
It is a compilation error to use the `instruction_set` attribute on a target that does not support it.
500522

@@ -519,3 +541,8 @@ Using the `instruction_set` attribute has the following effects:
519541

520542
* If the address of the function is taken as a function pointer, the low bit of the address will be set to 0 (arm) or 1 (thumb) depending on the instruction set.
521543
* Any inline assembly in the function must use the specified instruction set instead of the target default.
544+
545+
[_MetaWord_]: ../attributes.md#meta-item-attribute-syntax
546+
[_MetaListIdents_]: ../attributes.md#meta-item-attribute-syntax
547+
[_MetaListPath_]: ../attributes.md#meta-item-attribute-syntax
548+
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax

src/attributes/derive.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,17 @@ You can implement `derive` for your own traits through [procedural macros].
3939
## The `automatically_derived` attribute
4040

4141
r[attributes.derive.automatically_derived]
42+
43+
r[attributes.derive.automatically_derived.intro]
4244
The *`automatically_derived` attribute* is automatically added to
4345
[implementations] created by the `derive` attribute for built-in traits. It
4446
has no direct effect, but it may be used by tools and diagnostic lints to
4547
detect these automatically generated implementations.
4648

49+
r[attributes.derive.automatically_derived.syntax]
50+
The `automatically_derived` attribute uses the [_MetaWord_] syntax
51+
52+
[_MetaWord_]: ../attributes.md#meta-item-attribute-syntax
4753
[_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax
4854
[`impl` item]: ../items/implementations.md
4955
[items]: ../items.md

src/attributes/diagnostics.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ pub mod m2 {
8787
}
8888
```
8989

90+
r[attributes.diagnostics.lint.override-forbid]
91+
It is an error to specify a lint level attribute weaker than `deny` that overrides a `forbid` in effect for that item.
92+
9093
This example shows how one can use `forbid` to disallow uses of `allow` or
9194
`expect` for that lint check:
9295

@@ -358,6 +361,9 @@ r[attributes.diagnostics.must_use.intro]
358361
The *`must_use` attribute* is used to issue a diagnostic warning when a value
359362
is not "used".
360363

364+
r[attributes.diagnostics.must_use.syntax]
365+
The `must_use` attribute uses either the [_MetaWord_] syntax, or the [_MetaNameValueStr_] syntax.
366+
361367
r[attributes.diagnostics.must_use.allowed-positions]
362368
The `must_use` attribute can be applied to user-defined composite types
363369
([`struct`s][struct], [`enum`s][enum], and [`union`s][union]), [functions],
@@ -561,6 +567,7 @@ error[E0277]: My Message for `ImportantTrait<i32>` implemented for `String`
561567
```
562568

563569
[Clippy]: https://github.com/rust-lang/rust-clippy
570+
[_MetaWord_]: ../attributes.md#meta-item-attribute-syntax
564571
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
565572
[_MetaListPaths_]: ../attributes.md#meta-item-attribute-syntax
566573
[_MetaNameValueStr_]: ../attributes.md#meta-item-attribute-syntax

src/attributes/testing.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ r[attributes.testing.test]
1414
r[attributes.testing.test.intro]
1515
The *`test` attribute* marks a function to be executed as a test.
1616

17+
r[attributes.testing.test.syntax]
18+
The `test` attribute uses the [_MetaWord_] syntax.
19+
1720
r[attributes.testing.test.enabled]
1821
These functions are only compiled when in test mode.
1922

@@ -60,8 +63,10 @@ A function annotated with the `test` attribute can also be annotated with the
6063
execute that function as a test. It will still be compiled when in test mode.
6164

6265
r[attributes.testing.ignore.syntax]
63-
The `ignore` attribute may optionally be written with the [_MetaNameValueStr_]
64-
syntax to specify a reason why the test is ignored.
66+
The `ignore` attribute uses either the [_MetaWord_] syntax or the [_MetaNameValueStr_] syntax.
67+
68+
r[attributes.testing.ignore.reason]
69+
The value in the case of using the [_MetaNameValueStr_] syntax is a reason for the test being ignored.
6570

6671
```rust
6772
#[test]
@@ -82,11 +87,14 @@ r[attributes.testing.should_panic.intro]
8287
A function annotated with the `test` attribute that returns `()` can also be
8388
annotated with the `should_panic` attribute.
8489

90+
r[attributes.testing.should_panic.syntax]
91+
The `should_panic` attribute uses the [_MetaWord_] syntax, [_MetaNameValueStr_] syntax, or the [_MetaListNameValueStr_] syntax.
92+
8593
r[attributes.testing.should_panic.behavior]
8694
The *`should_panic` attribute*
8795
makes the test only pass if it actually panics.
8896

89-
r[attributes.testing.should_panic.syntax]
97+
r[attributes.testing.should_panic.expected]
9098
The `should_panic` attribute may optionally take an input string that must
9199
appear within the panic message. If the string is not found in the message,
92100
then the test will fail. The string may be passed using the
@@ -101,6 +109,7 @@ fn mytest() {
101109
}
102110
```
103111

112+
[_MetaWord_]: ../attributes.md#meta-item-attribute-syntax
104113
[_MetaListNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
105114
[_MetaNameValueStr_]: ../attributes.md#meta-item-attribute-syntax
106115
[`Termination`]: std::process::Termination

0 commit comments

Comments
 (0)