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
Safety-critical software requires consistent and predictable behavior across all build
41
-
configurations. Explicit handling of potential overflow conditions improves code clarity,
41
+
Safety-critical software requires consistent and predictable behavior across all build configurations.
42
+
Explicit handling of potential overflow conditions improves code clarity,
42
43
maintainability, and reduces the risk of numerical errors in production.
43
44
44
45
.. non_compliant_example::
@@ -73,9 +74,15 @@ Types and Traits
73
74
:scope: system
74
75
:tags: surprising-behavior
75
76
76
-
Do not rely on the equality or stable identity of function pointers originating from different crates or that may be inlined, duplicated, or instantiated differently across compilation units, codegen units, or optimization profiles.
77
+
Do not rely on the equality or stable identity of function pointers originating from different crates or that may be inlined,
78
+
duplicated, or instantiated differently across compilation units, codegen units, or optimization profiles.
77
79
78
-
Avoid assumptions about low-level metadata (such as symbol addresses) unless explicitly guaranteed by the Ferrocene Language Specification (FLS). Function address identity is not guaranteed by Rust and must not be treated as stable. Rust’s fn type is a zero-sized function item promoted to a function pointer, whose address is determined by the compiler backend. When a function resides in a different crate, or when optimizations such as inlining, link-time optimization, or codegen-unit partitioning are enabled, the compiler may generate multiple distinct code instances for the same function or alter the address at which it is emitted.
80
+
Avoid assumptions about low-level metadata (such as symbol addresses) unless explicitly guaranteed by the Ferrocene Language Specification (FLS).
81
+
Function address identity is not guaranteed by Rust and must not be treated as stable.
82
+
Rust’s ``fn`` type is a zero-sized function item promoted to a function pointer, whose address is determined by the compiler backend.
83
+
When a function resides in a different crate, or when optimizations such as inlining,
84
+
link-time optimization, or codegen-unit partitioning are enabled,
85
+
the compiler may generate multiple distinct code instances for the same function or alter the address at which it is emitted.
79
86
80
87
Consequently, the following operations are not reliable:
81
88
@@ -90,33 +97,36 @@ Types and Traits
90
97
:id: rat_xcVE5Hfnbb2u
91
98
:status: draft
92
99
93
-
Compiler optimizations may cause function pointers originating from different crates to lose stable identity. Observed behaviors include:
100
+
Compiler optimizations may cause function pointers originating from different crates to lose stable identity.
- Nondeterministic behavior: correctness depending on build flags or incremental state.
109
-
- Test-only correctness: function pointer equality passing in debug builds but failing in release/LTO builds.
118
+
- Test-only correctness: function pointer equality passing in debug builds but failing in release/link-time optimization builds.
110
119
111
-
In short, dependence on function address stability introduces non-portable, build-profile-dependent behavior, which is incompatible with high-integrity Rust.
120
+
In short, dependence on function address stability introduces non-portable, build-profile-dependent behavior,
121
+
which is incompatible with high-integrity Rust.
112
122
113
123
.. non_compliant_example::
114
124
:id: non_compl_ex_MkAkFxjRTijx
115
125
:status: draft
116
126
117
127
Due to cross-crate inlining or codegen-unit partitioning,
118
-
the address of ``handler_a`` in crate ``B`` may differ from its address in crate A,
119
-
causing comparisons to fail as shown in this noncompliant code example:
128
+
the address of ``handler_a`` in crate ``B`` may differ from its address in crate A,
129
+
causing comparisons to fail as shown in this noncompliant code example:
120
130
121
131
.. code-block:: rust
122
132
@@ -187,15 +197,15 @@ Types and Traits
187
197
188
198
let f = op_mul;
189
199
190
-
// ❌ Lookup may fail if `op_mul` has multiple emitted instances.
200
+
// Error: Lookup may fail if `op_mul` has multiple emitted instances.
191
201
assert_eq!(registry.get(&f), Some(&"double"));
192
202
193
203
.. compliant_example::
194
204
:id: compl_ex_oiqSSclTXmIj
195
205
:status: draft
196
206
197
207
This compliant example uses a stable identity wrappers as identity keys.
198
-
The ``id`` is a stable, programmer-defined identity, immune to compiler optimizations.
208
+
The ``id`` is a stable, programmer-defined identity, immune to compiler optimizations.
199
209
The function pointer is preserved for behavior (``func``) but never used as the identity key.
200
210
201
211
.. code-block:: rust
@@ -254,7 +264,7 @@ Types and Traits
254
264
}
255
265
}
256
266
257
-
register(handler); // Error: ❌ may be inserted twice under some builds
267
+
register(handler); // Error: may be inserted twice under some builds
0 commit comments