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
+42-41Lines changed: 42 additions & 41 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,47 +15,48 @@ r[abi.used]
15
15
r[abi.used.intro]
16
16
The *`used`[attribute]* forces a [`static` item][items.static] to be kept in the output object file (.o, .rlib, etc. excluding final binaries) even if the static is never used, or referenced, by an other item in the crate. However, the linker is still free to remove such an item.
17
17
18
-
Below is an example that shows under what conditions the compiler keeps a `static` item in the output object file.
19
-
20
-
```rust
21
-
// foo.rs
22
-
23
-
// This is kept because of `#[used]`:
24
-
#[used]
25
-
staticFOO:u32=0;
26
-
27
-
// This is removable because it is unused:
28
-
#[allow(dead_code)]
29
-
staticBAR:u32=0;
30
-
31
-
// This is kept because it is publicly reachable:
32
-
pubstaticBAZ:u32=0;
33
-
34
-
// This is kept because it is referenced by a public, reachable function:
35
-
staticQUUX:u32=0;
36
-
37
-
pubfnquux() ->&'staticu32 {
38
-
&QUUX
39
-
}
40
-
41
-
// This is removable because it is referenced by a private, unused (dead) function:
42
-
staticCORGE:u32=0;
43
-
44
-
#[allow(dead_code)]
45
-
fncorge() ->&'staticu32 {
46
-
&CORGE
47
-
}
48
-
```
49
-
50
-
```console
51
-
$ rustc -O --emit=obj --crate-type=rlib foo.rs
52
-
53
-
$ nm -C foo.o
54
-
0000000000000000 R foo::BAZ
55
-
0000000000000000 r foo::FOO
56
-
0000000000000000 R foo::QUUX
57
-
0000000000000000 T foo::quux
58
-
```
18
+
> [!EXAMPLE]
19
+
> This example that shows under what conditions the compiler keeps a `static` item in the output object file.
20
+
>
21
+
> ```rust
22
+
> // foo.rs
23
+
>
24
+
> // This is kept because of `#[used]`:
25
+
> #[used]
26
+
> staticFOO:u32=0;
27
+
>
28
+
> // This is removable because it is unused:
29
+
> #[allow(dead_code)]
30
+
> staticBAR:u32=0;
31
+
>
32
+
> // This is kept because it is publicly reachable:
33
+
> pubstaticBAZ:u32=0;
34
+
>
35
+
> // This is kept because it is referenced by a public, reachable function:
36
+
> staticQUUX:u32=0;
37
+
>
38
+
> pubfnquux() ->&'staticu32 {
39
+
> &QUUX
40
+
> }
41
+
>
42
+
> // This is removable because it is referenced by a private, unused (dead) function:
0 commit comments