You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/abi.md
+50-47Lines changed: 50 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,57 +9,60 @@ See *[extern functions]* for information on specifying the ABI for exporting
9
9
functions. See *[external blocks]* for information on specifying the ABI for
10
10
linking external libraries.
11
11
12
+
<!-- template:attributes -->
12
13
r[abi.used]
13
14
## The `used` attribute
14
15
15
16
r[abi.used.intro]
16
-
The *`used` attribute* can only be applied to [`static` items]. This [attribute] forces the
17
-
compiler to keep the variable in the output object file (.o, .rlib, etc. excluding final binaries)
18
-
even if the variable is not used, or referenced, by any other item in the crate.
19
-
However, the linker is still free to remove such an item.
17
+
The *`used`[attribute]* forces a [static] to be kept in the output object file (.o, .rlib, etc., excluding final binaries) even if it's never used or referenced by any other item in the crate. The linker, however, is still free to remove it.
18
+
19
+
> [!EXAMPLE]
20
+
> ```rust
21
+
> // lib.rs
22
+
>
23
+
> // This is kept because of `#[used]`.
24
+
> #[used]
25
+
> staticS1:u8=0;
26
+
>
27
+
> // This is removable because it's unused.
28
+
> #[allow(dead_code)]
29
+
> staticS2:u8=0;
30
+
>
31
+
> // This is kept because it's publicly reachable.
32
+
> pubstaticS3:u8=0;
33
+
>
34
+
> // This is kept because it's referenced by a publicly
0 commit comments