Skip to content

Commit 8d56c5d

Browse files
committed
Move attribute examples to earlier in the chapter
1 parent d6b2e6e commit 8d56c5d

File tree

1 file changed

+34
-32
lines changed

1 file changed

+34
-32
lines changed

src/attributes.md

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,43 @@ on Attributes in [ECMA-335], with the syntax coming from [ECMA-334] \(C#).
2525
r[attributes.inner]
2626
_Inner attributes_, written with a bang (`!`) after the hash (`#`), apply to the form that the attribute is declared within.
2727

28+
> [!EXAMPLE]
29+
> ```rust
30+
> // General metadata applied to the enclosing module or crate.
31+
> #![crate_type = "lib"]
32+
>
33+
> // Inner attribute applies to the entire function.
34+
> fn some_unused_variables() {
35+
> #![allow(unused_variables)]
36+
>
37+
> let x = ();
38+
> let y = ();
39+
> let z = ();
40+
> }
41+
> ```
42+
2843
r[attributes.outer]
2944
_Outer attributes_, written without the bang after the hash, apply to the form that follows the attribute.
3045
46+
> [!EXAMPLE]
47+
> ```rust
48+
> // A function marked as a unit test
49+
> #[test]
50+
> fn test_foo() {
51+
> /* ... */
52+
> }
53+
>
54+
> // A conditionally-compiled module
55+
> #[cfg(target_os = "linux")]
56+
> mod bar {
57+
> /* ... */
58+
> }
59+
>
60+
> // A lint attribute used to suppress a warning/error
61+
> #[allow(non_camel_case_types)]
62+
> type int8_t = i8;
63+
> ```
64+
3165
r[attributes.input]
3266
The attribute consists of a path to the attribute, followed by an optional
3367
delimited token tree whose interpretation is defined by the attribute.
@@ -75,38 +109,6 @@ Attributes may be applied to many forms in the language:
75109
parameters accept outer attributes. This includes attributes on variadic parameters
76110
denoted with `...` in function pointers and [external blocks][variadic functions].
77111
78-
Some examples of attributes:
79-
80-
```rust
81-
// General metadata applied to the enclosing module or crate.
82-
#![crate_type = "lib"]
83-
84-
// A function marked as a unit test
85-
#[test]
86-
fn test_foo() {
87-
/* ... */
88-
}
89-
90-
// A conditionally-compiled module
91-
#[cfg(target_os = "linux")]
92-
mod bar {
93-
/* ... */
94-
}
95-
96-
// A lint attribute used to suppress a warning/error
97-
#[allow(non_camel_case_types)]
98-
type int8_t = i8;
99-
100-
// Inner attribute applies to the entire function.
101-
fn some_unused_variables() {
102-
#![allow(unused_variables)]
103-
104-
let x = ();
105-
let y = ();
106-
let z = ();
107-
}
108-
```
109-
110112
r[attributes.meta]
111113
## Meta item attribute syntax
112114

0 commit comments

Comments
 (0)