1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//! The platform `f32::max`/`f32::min`, generated into each module allowed to call them.
//!
//! `f32::max`/`f32::min` do not specify which of two equal-magnitude,
//! opposite-signed zeros they return, and `aarch64`/`x86_64` disagree on it —
//! [`crate::det_math::max`]/[`min`] (the Law form) is what production code
//! calls. The handful of modules below are provably safe despite calling the
//! platform function directly (a constant nonzero operand, both operands
//! already `.abs()`-derived, or the result cast to an integer immediately
//! after, each erasing the sign distinction before it could matter) — see
//! `scripts/raw_minmax_manifest.toml` for the exact modules and their
//! individual justification.
//!
//! ## Why a macro that generates private items, not shared `pub(crate)` fns
//!
//! An earlier version of this file was three `pub(crate) fn`s, with
//! `scripts/raw_minmax_manifest.py` counting call sites by scanning source
//! text for the bare function name. That is defeatable without changing
//! what runs: `use raw_max_f32 as x;` then calling `x(a, b)` hides under a
//! different name, and `.fold(0.0, raw_max_f32)` passes the function itself
//! as a value, never writing a textually-matchable call at all. Requiring a
//! [`Reason`] argument closed the second hole (a bare function reference no
//! longer type-checks against a 2-argument fold/map), but the first — an
//! alias simply isn't the text the manifest looks for — survives any
//! text-based scheme, no matter how the function signature is shaped.
//!
//! `raw_minmax_here!()` closes it with ordinary Rust item privacy instead
//! of a scan: invoking it defines `raw_max_f32`/`raw_min_f32`/`raw_max_f64`
//! as **private items of the invoking module** — not re-exported,
//! forwardable, or nameable from anywhere else, so there is no shared item
//! anywhere in the crate for an alias to rename. "Which modules may call
//! the raw platform max/min" is instead enforced by
//! `clippy::disallowed_macros` (`disallowed-macros` in `clippy.toml`,
//! naming this macro's own definition path): invoking the macro from a
//! module that does not carry a reasoned
//! `#![allow(clippy::disallowed_macros, reason = "...")]` is a clippy
//! error. Clippy resolves `disallowed_macros` by the macro's **definition**
//! path, not the spelling used to invoke it, so `use raw_minmax_here as x;
//! x!();` is caught exactly the same as calling it by its own name —
//! verified against a minimal standalone crate before relying on it here
//! (clippy reported `use of a disallowed macro
//! "alice_lol::raw_minmax::raw_minmax_here"` for the aliased invocation).
//!
//! `scripts/raw_minmax_manifest.py` now tracks the list of modules carrying
//! that allow (not a per-call count): a module invoking the macro without
//! the allow fails clippy directly (no separate script needed to catch
//! that); the script's job is the opposite direction — a module listed as
//! allowed that no longer actually invokes the macro is a stale entry to
//! remove, and a module invoking the macro that is not yet listed is a new
//! site to review and add.
/// The specific, named safety class a caller is asserting for one call to
/// the generated `raw_max_f32`/`raw_min_f32`/`raw_max_f64` — required as an
/// argument (not load-bearing to the computed value) so the call cannot be
/// spelled without naming it. Variant names match
/// `scripts/disallowed_methods_allow_reasons.py`'s `nonzero-const:`/
/// `both-abs:`/`int-cast:` prefixes one-for-one.
pub
// The ONE real implementation of each operation, each with its own
// disallowed_methods exemption attribute — kept OUTSIDE the macro body
// below deliberately: putting that same exemption inside a macro's
// expansion was found (empirically, against a standalone repro) to make
// clippy stop honouring an INVOKING module's own disallowed_macros
// exemption, flagging every invocation of raw_minmax_here!() as disallowed
// regardless of that allow. Moving the disallowed_methods exemption onto a
// plain (non-macro-generated) function here, with the macro only
// generating a thin wrapper that calls through, avoids the interaction:
// the macro's own expansion carries no lint-level attribute of its own to
// conflict with the invoking module's.
pub const
pub const
pub const
/// Defines the named subset of `raw_max_f32`/`raw_min_f32`/`raw_max_f64` as
/// private items of the invoking module — see the module doc above for why
/// this is a macro rather than shared `pub(crate)` functions. Invoke once
/// per module, at module scope (not inside a function), naming only the
/// helper(s) that module actually calls (`raw_minmax_here!(max_f32);` or
/// `raw_minmax_here!(max_f32, min_f32);`), alongside a reasoned
/// `#![allow(clippy::disallowed_macros, reason = "...")]` at the top of
/// that same module — `clippy.toml`'s `disallowed-macros` entry for this
/// macro's path is what enforces that every OTHER module is refused.
///
/// Naming only what is used, rather than always generating all three and
/// relying on `#[allow(dead_code)]` for the unused ones, is deliberate, not
/// just tidiness: an `#[allow(...)]` of ANY kind on the macro-generated
/// item (`dead_code` included, tried first) was found — empirically, against
/// a standalone repro — to make clippy stop honouring the invoking
/// module's own `#![allow(clippy::disallowed_macros, ...)]`, flagging every
/// invocation as disallowed regardless of that allow. A module that never
/// has an unused generated helper never needs that attribute, sidestepping
/// the interaction entirely.
///
/// Each generated function is a thin wrapper over the real `impl_*`
/// function above (see the comment there for the matching reason the
/// `disallowed_methods` allow lives there and not in this macro body).
pub use raw_minmax_here;