rapx 0.7.39

A static analysis platform for Rust program analysis and verification
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
//! Standard-library API call classification helpers.
//!
//! Each classifier answers "what kind of operation is this call?" (pointer
//! arithmetic, raw memory access, ownership transfer, …). Callers — the VM,
//! the alias/hazard scanner, and the call-summary registry — use these to pick
//! a modelling strategy or discharge a safety obligation.
//!
//! # Matching mechanism
//!
//! Every classifier takes a `DefId` — `fn(Option<DefId>) -> bool` for callee
//! matching, or `fn(DefId) -> bool` for ADT *type* matching — and answers via
//! exact set membership in [`crate::def_id`] rather than substring-matching a
//! `def_path_str`. [`crate::def_id`] resolves the well-known `std`/`core`/`alloc`
//! items (by lang/diagnostic item, explicit path, or — for the open-ended
//! groups and the std-challenge suites' local re-implementations — by
//! name-scanning `fn_defs()` at init), so a call site is matched by identity
//! without the false positives of per-call-site name matching.

use rustc_hir::def_id::DefId;

/// Whether `callee` is `Some` and matches any item in the (Option<DefId>) list.
fn any_of(callee: Option<DefId>, items: &[Option<DefId>]) -> bool {
    callee.is_some_and(|c| items.contains(&Some(c)))
}

/// Whether `callee` is `Some` and matches any resolved DefId in the slice.
fn any_fn(callee: Option<DefId>, fns: &[DefId]) -> bool {
    callee.is_some_and(|c| fns.contains(&c))
}

// ── Ownership reconstruction ──────────────────────────────────────

/// Whether `callee` reconstructs an owned value, taking ownership of the
/// pointed-to memory: from a single raw pointer (`Box::from_raw`,
/// `CString::from_raw`, `Arc::from_raw`, `Rc::from_raw`) or from a `Vec<u8>`
/// (`CString::from_vec_with_nul_unchecked`). Distinct from
/// [`is_from_raw_parts`], which builds a slice/`Vec` from `(ptr, len[, cap])`.
pub fn is_ownership_reconstruction(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::box_from_raw(),
            crate::def_id::cstring_from_raw(),
            crate::def_id::arc_from_raw(),
            crate::def_id::rc_from_raw(),
            crate::def_id::box_from_raw_in(),
            crate::def_id::arc_from_raw_in(),
            crate::def_id::rc_from_raw_in(),
            crate::def_id::cstring_from_vec_with_nul_unchecked(),
        ],
    )
}

// ── Pointer extraction / cast ─────────────────────────────────────

/// Whether `callee` produces a raw pointer (or `NonNull`) alias of its first
/// argument: `as_ptr`/`as_mut_ptr`, `into_raw`, and pointer `cast` (incl.
/// `cast_mut`/`cast_const`). `as_ptr_range`/`as_mut_ptr_range` are excluded
/// because they return a `Range` of two pointers rather than a single pointer;
/// `NonNull::new_unchecked`/`as_ref`/`as_mut` are excluded because they do not
/// produce a raw pointer (and `new_unchecked` must not mark its result
/// non-null, or it would hide `new_unchecked(null)` unsoundness).
pub fn is_as_ptr(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::slice_as_ptr(),
            crate::def_id::slice_as_mut_ptr(),
            crate::def_id::str_as_ptr(),
            crate::def_id::str_as_mut_ptr(),
            crate::def_id::vec_as_ptr(),
            crate::def_id::vec_as_mut_ptr(),
            crate::def_id::cstr_as_ptr(),
            crate::def_id::nonnull_as_ptr(),
            crate::def_id::const_ptr_slice_as_ptr(),
            crate::def_id::mut_ptr_slice_as_mut_ptr(),
            crate::def_id::nonnull_slice_as_mut_ptr(),
            crate::def_id::box_as_ptr(),
            crate::def_id::box_as_mut_ptr(),
            crate::def_id::maybe_uninit_as_ptr(),
            crate::def_id::maybe_uninit_as_mut_ptr(),
            crate::def_id::arc_as_ptr(),
            crate::def_id::rc_as_ptr(),
            crate::def_id::const_ptr_cast(),
            crate::def_id::const_ptr_cast_mut(),
            crate::def_id::mut_ptr_cast(),
            crate::def_id::mut_ptr_cast_const(),
            crate::def_id::nonnull_cast(),
            crate::def_id::box_into_raw(),
            crate::def_id::cstring_into_raw(),
            crate::def_id::arc_into_raw(),
            crate::def_id::rc_into_raw(),
        ],
    )
}

/// Whether `callee` is a raw-pointer `cast`/`cast_mut`/`cast_const`. These only
/// *reinterpret* the address — they preserve null-ness and provenance, but do
/// not establish that the result is non-null, aligned, or points at initialized
/// memory. Distinguished from [`is_as_ptr`] so [`is_as_ptr_valid`] can keep
/// them on the MIR-inlining path rather than the `ReturnPointerFromArg` model
/// (which asserts those facts).
pub(crate) fn is_raw_ptr_cast(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::const_ptr_cast(),
            crate::def_id::const_ptr_cast_mut(),
            crate::def_id::mut_ptr_cast(),
            crate::def_id::mut_ptr_cast_const(),
        ],
    )
}

/// [`is_as_ptr`] restricted to the *pointer-validity-establishing* subset:
/// `as_ptr`/`as_mut_ptr`, `into_raw`, and `NonNull::cast` — which expose a
/// non-null, aligned, initialized backing pointer. Raw-pointer `cast`/
/// `cast_mut`/`cast_const` are excluded because they only reinterpret the
/// address (preserving null-ness) and are left to MIR inlining.
pub fn is_as_ptr_valid(callee: Option<DefId>) -> bool {
    is_as_ptr(callee) && !is_raw_ptr_cast(callee)
}

/// `str::as_bytes`: reinterprets `&str` as `&[u8]` — same data pointer and
/// byte length, so the result aliases the argument.
pub fn is_str_as_bytes(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::str_as_bytes()])
}

// ── Pointer arithmetic ────────────────────────────────────────────
// Direction (`add` vs `sub`) and granularity (`element` vs `byte`) are two
// orthogonal axes. Each of the four combinations is a first-class classifier
// below; the aggregate predicates at the end are unions over a single axis,
// for callers that only care about one dimension.

/// Element-strided `add`/`wrapping_add` and signed `offset`/`wrapping_offset`
/// (stride = `size_of::<T>()`). `offset_from`/`offset_from_unsigned` are *not*
/// matched (they subtract two pointers into an `isize`).
pub(crate) fn is_element_ptr_add(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::const_ptr_add(),
            crate::def_id::const_ptr_wrapping_add(),
            crate::def_id::const_ptr_offset(),
            crate::def_id::const_ptr_wrapping_offset(),
            crate::def_id::mut_ptr_add(),
            crate::def_id::mut_ptr_wrapping_add(),
            crate::def_id::mut_ptr_offset(),
            crate::def_id::mut_ptr_wrapping_offset(),
            crate::def_id::nonnull_add(),
            crate::def_id::nonnull_offset(),
        ],
    )
}

/// Element-strided `sub`/`wrapping_sub` (stride = `size_of::<T>()`).
pub(crate) fn is_element_ptr_sub(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::const_ptr_sub(),
            crate::def_id::const_ptr_wrapping_sub(),
            crate::def_id::mut_ptr_sub(),
            crate::def_id::mut_ptr_wrapping_sub(),
            crate::def_id::nonnull_sub(),
        ],
    )
}

/// Byte-granular `byte_add`/`wrapping_byte_add` and signed
/// `byte_offset`/`wrapping_byte_offset` (stride 1).
pub(crate) fn is_byte_ptr_add(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::const_ptr_byte_add(),
            crate::def_id::const_ptr_wrapping_byte_add(),
            crate::def_id::const_ptr_byte_offset(),
            crate::def_id::const_ptr_wrapping_byte_offset(),
            crate::def_id::mut_ptr_byte_add(),
            crate::def_id::mut_ptr_wrapping_byte_add(),
            crate::def_id::mut_ptr_byte_offset(),
            crate::def_id::mut_ptr_wrapping_byte_offset(),
            crate::def_id::nonnull_byte_add(),
            crate::def_id::nonnull_byte_offset(),
        ],
    )
}

/// Byte-granular `byte_sub`/`wrapping_byte_sub` (stride 1).
pub(crate) fn is_byte_ptr_sub(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::const_ptr_byte_sub(),
            crate::def_id::const_ptr_wrapping_byte_sub(),
            crate::def_id::mut_ptr_byte_sub(),
            crate::def_id::mut_ptr_wrapping_byte_sub(),
            crate::def_id::nonnull_byte_sub(),
        ],
    )
}

/// Any pointer `add` (element or byte). `offset`/`byte_offset` take a signed
/// `isize`, so a negative offset is still classified here (the sign lives in
/// the argument); see [`is_pointer_sub`] for the positive-count `sub` family.
pub fn is_pointer_add(callee: Option<DefId>) -> bool {
    is_element_ptr_add(callee) || is_byte_ptr_add(callee)
}

/// Any pointer `sub` (element or byte): a positive count, `base - count * stride`.
pub fn is_pointer_sub(callee: Option<DefId>) -> bool {
    is_element_ptr_sub(callee) || is_byte_ptr_sub(callee)
}

/// Any byte-granular pointer arithmetic (stride 1), regardless of direction.
pub fn is_byte_ptr_arith(callee: Option<DefId>) -> bool {
    is_byte_ptr_add(callee) || is_byte_ptr_sub(callee)
}

// ── Layout constants ──────────────────────────────────────────────

/// Whether `callee` is the compile-time layout constant `size_of::<T>()` or
/// `align_of::<T>()`. The runtime intrinsics (`size_of_val`, `align_of_val`,
/// `pref_align_of`, `*_val_raw`, …) are *not* classified here.
pub fn is_layout_constant(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::mem_size_of(),
            crate::def_id::mem_align_of(),
            crate::def_id::intrinsics_size_of(),
            crate::def_id::intrinsics_align_of(),
        ],
    )
}

/// Whether `callee` is `ptr::align_offset` / `NonNull::align_offset` /
/// `*const T::align_offset` / `*mut T::align_offset`.
pub fn is_align_offset(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::ptr_align_offset(),
            crate::def_id::nonnull_align_offset(),
            crate::def_id::const_ptr_align_offset(),
            crate::def_id::mut_ptr_align_offset(),
        ],
    )
}

// ── Raw pointer read / write ──────────────────────────────────────

/// Whether `callee` writes through a raw pointer to its first argument
/// (`ptr::write`, `write_bytes`, `write_unaligned`, `write_volatile`).
pub fn is_ptr_write(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::ptr_write(),
            crate::def_id::ptr_write_unaligned(),
            crate::def_id::ptr_write_volatile(),
            crate::def_id::ptr_write_bytes(),
        ],
    )
}

/// Whether `callee` reads through a raw pointer or copies memory
/// (`ptr::read`/`read_unaligned`/`read_volatile`, `copy_to`/`copy_from`,
/// `MaybeUninit::assume_init_read`, and intrinsics `copy`/`copy_nonoverlapping`).
pub fn is_ptr_read(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::ptr_read(),
            crate::def_id::ptr_read_unaligned(),
            crate::def_id::ptr_read_volatile(),
            crate::def_id::copy_to(),
            crate::def_id::copy_to_nonoverlapping(),
            crate::def_id::copy_from(),
            crate::def_id::copy_from_nonoverlapping(),
            crate::def_id::assume_init_read(),
            crate::def_id::intrinsics_copy(),
            crate::def_id::intrinsics_copy_nonoverlapping(),
        ],
    )
}

// ── MaybeUninit ───────────────────────────────────────────────────

/// Whether `callee` is `MaybeUninit::write`, which initializes the slot (unlike
/// raw `ptr::write`, handled by [`is_mem_copy_or_write`]).
pub fn is_maybe_uninit_write(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::maybe_uninit_write()])
}

/// Whether `callee` is `MaybeUninit::uninit` (a new uninitialized slot).
pub fn is_maybe_uninit_uninit(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::maybe_uninit_uninit()])
}

/// Whether `callee` is a `MaybeUninit` "assume initialized" accessor
/// (`assume_init`, `assume_init_read`, `assume_init_ref`, `assume_init_mut`).
pub fn is_maybe_uninit_assume_init(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::maybe_uninit_assume_init(),
            crate::def_id::assume_init_read(),
            crate::def_id::maybe_uninit_assume_init_ref(),
            crate::def_id::maybe_uninit_assume_init_mut(),
        ],
    )
}

/// Memory copy/write intrinsics that legitimately write through a raw pointer
/// without requiring the target bytes to be pre-initialized (e.g. `ptr::write`,
/// `write_bytes`, `copy_nonoverlapping`, `ptr::copy`). Used by the checker to
/// discharge `Init`/`Typed` obligations on `MaybeUninit` targets.
pub fn is_mem_copy_or_write(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::intrinsics_copy(),
            crate::def_id::intrinsics_copy_nonoverlapping(),
            crate::def_id::copy_from_nonoverlapping(),
            crate::def_id::copy_to_nonoverlapping(),
            crate::def_id::ptr_write(),
            crate::def_id::ptr_write_bytes(),
        ],
    )
}

// ── Queries and unwrap ────────────────────────────────────────────

/// Whether `callee` is a `len` query method. Matched by `DefId` via
/// [`crate::def_id::len_fns`], which resolves every `::len` `fn_def` in the std
/// crates *and* the local crate — so the std-challenge suites' re-implemented
/// `len` methods are modelled too, without substring-matching a `def_path_str`.
pub fn is_len(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::len_fns())
}

/// Whether `callee` is a `capacity` query method.
pub fn is_capacity(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::capacity_fns())
}

pub fn is_unwrap(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::option_unwrap(),
            crate::def_id::option_expect(),
            crate::def_id::option_unwrap_unchecked(),
            crate::def_id::result_unwrap(),
            crate::def_id::result_unwrap_err(),
            crate::def_id::result_expect(),
            crate::def_id::result_expect_err(),
            crate::def_id::result_unwrap_unchecked(),
        ],
    )
}

// ── Slice / C-string ──────────────────────────────────────────────

/// Whether `callee` is a `from_raw_parts` constructor (`slice`/`str`/`ptr`/
/// `String`/`Vec`/`NonNull`). Matched by `DefId` via
/// [`crate::def_id::from_raw_parts_fns`] (resolved from `fn_defs()`, including
/// local re-implementations), instead of substring-matching `def_path_str`.
pub fn is_from_raw_parts(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::from_raw_parts_fns())
}

/// Whether `callee` is a `from_raw_parts_mut` constructor.
pub fn is_from_raw_parts_mut(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::from_raw_parts_mut_fns())
}

pub fn is_cstr_from_ptr(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::cstr_from_ptr()])
}

/// `_unchecked` C-string constructors whose caller must guarantee NUL
/// termination (`CStr::from_bytes_with_nul_unchecked`,
/// `CString::from_vec_with_nul_unchecked`).
pub fn is_cstr_unchecked_constructor(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::cstr_from_bytes_with_nul_unchecked(),
            crate::def_id::cstring_from_vec_with_nul_unchecked(),
        ],
    )
}

// ── Vec constructors / methods ────────────────────────────────────

pub fn is_vec_push_or_reserve(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::vec_push(),
            crate::def_id::vec_reserve(),
            crate::def_id::vec_reserve_exact(),
        ],
    )
}
pub fn is_vec_alloc_constructor(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::vec_from_elem()])
}
pub fn is_vec_from_box(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::slice_into_vec(),
            crate::def_id::box_assume_init_into_vec_unsafe(),
        ],
    )
}
/// `Vec::with_capacity` — matched by `DefId` via
/// [`crate::def_id::with_capacity_fns`].
pub fn is_vec_with_capacity(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::with_capacity_fns())
}
pub fn is_into_boxed_slice(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::vec_into_boxed_slice()])
}

// ── Alias-hazard classification ───────────────────────────────────
// These are the single home for "what does this raw-pointer API do" used by the
// alias/hazard scanner. `is_ownership_transfer` is the raw-pointer subset of
// [`is_ownership_reconstruction`]: it excludes `from_vec_with_nul_unchecked`
// (which consumes a `Vec<u8>` rather than a raw pointer). `Vec::from_raw_parts`
// / `from_parts` ownership transfer is matched separately by
// [`is_vec_ownership_transfer`].

pub fn is_ownership_transfer(callee: Option<DefId>) -> bool {
    let Some(callee) = callee else { return false };
    is_ownership_reconstruction(Some(callee))
        && !crate::def_id::contains(
            &[crate::def_id::cstring_from_vec_with_nul_unchecked()],
            callee,
        )
}

pub fn is_vec_ownership_transfer(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::vec_ownership_transfer_fns())
}

/// Whether `callee` is `NonNull::new` (the null-checked constructor).
pub(crate) fn is_nonnull_checked_new(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::nonnull_new()])
}

/// Whether `callee` is `NonNull::as_ref` or `NonNull::as_mut`.
pub fn is_nonnull_as_ref_as_mut(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::nonnull_as_ref(),
            crate::def_id::nonnull_as_mut(),
        ],
    )
}

/// Whether `callee` is a `Vec` method that may reallocate (invalidating any
/// outstanding raw pointers derived from it).
pub fn is_vec_invalidating_method(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::vec_push(),
            crate::def_id::vec_reserve(),
            crate::def_id::vec_reserve_exact(),
            crate::def_id::vec_shrink_to_fit(),
            crate::def_id::vec_shrink_to(),
            crate::def_id::vec_insert(),
            crate::def_id::vec_remove(),
            crate::def_id::vec_clear(),
            crate::def_id::vec_truncate(),
            crate::def_id::vec_set_len(),
        ],
    )
}

/// Whether `callee` returns ownership of an allocation as a raw pointer
/// (`Box::into_raw`, `CString::into_raw`, `Arc::into_raw`, `Rc::into_raw`, ...).
pub fn is_ownership_return(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::box_into_raw(),
            crate::def_id::cstring_into_raw(),
            crate::def_id::arc_into_raw(),
            crate::def_id::rc_into_raw(),
        ],
    )
}

/// Whether `callee` is a benign, read-only use of a raw-pointer origin
/// (`len`, `is_empty`, `is_null`, `addr`, `as_ptr`/`as_mut_ptr`, `cast`).
pub fn is_benign_origin_use(callee: Option<DefId>) -> bool {
    any_of(
        callee,
        &[
            crate::def_id::const_ptr_is_null(),
            crate::def_id::const_ptr_addr(),
            crate::def_id::const_ptr_cast(),
            crate::def_id::const_ptr_cast_mut(),
            crate::def_id::const_ptr_slice_is_empty(),
            crate::def_id::const_ptr_slice_len(),
            crate::def_id::const_ptr_slice_as_ptr(),
            crate::def_id::mut_ptr_is_null(),
            crate::def_id::mut_ptr_addr(),
            crate::def_id::mut_ptr_cast(),
            crate::def_id::mut_ptr_cast_const(),
            crate::def_id::mut_ptr_slice_is_empty(),
            crate::def_id::mut_ptr_slice_len(),
            crate::def_id::mut_ptr_slice_as_mut_ptr(),
            crate::def_id::nonnull_addr(),
            crate::def_id::nonnull_cast(),
            crate::def_id::nonnull_as_ptr(),
            crate::def_id::nonnull_slice_is_empty(),
            crate::def_id::nonnull_slice_len(),
            crate::def_id::nonnull_slice_as_mut_ptr(),
            crate::def_id::slice_len(),
            crate::def_id::slice_is_empty(),
            crate::def_id::slice_as_ptr(),
            crate::def_id::slice_as_mut_ptr(),
            crate::def_id::str_len(),
            crate::def_id::str_is_empty(),
            crate::def_id::str_as_ptr(),
            crate::def_id::str_as_mut_ptr(),
            crate::def_id::vec_len(),
            crate::def_id::vec_is_empty(),
            crate::def_id::vec_as_ptr(),
            crate::def_id::vec_as_mut_ptr(),
            crate::def_id::string_len(),
            crate::def_id::string_is_empty(),
            crate::def_id::cstr_as_ptr(),
            crate::def_id::cstr_is_empty(),
        ],
    )
}

// ── ADT type-name classifiers ─────────────────────────────────────
// *Shape* recognizers used by the VM to model repr(transparent) wrappers and
// fixed field layouts (`Vec` = ptr/cap/len, `slice::Iter` = ptr/end, …).
// Matched by `DefId` (resolved in [`crate::def_id`]).

pub fn is_std_vec(def_id: DefId) -> bool {
    crate::def_id::vec_types().contains(&def_id)
}
pub fn is_std_box(def_id: DefId) -> bool {
    crate::def_id::box_types().contains(&def_id)
}
pub fn is_std_cstring(def_id: DefId) -> bool {
    crate::def_id::cstring_types().contains(&def_id)
}
pub fn is_std_nonnull(def_id: DefId) -> bool {
    crate::def_id::nonnull_types().contains(&def_id)
}
pub fn is_maybe_uninit_type(def_id: DefId) -> bool {
    crate::def_id::maybe_uninit_types().contains(&def_id)
}
pub fn is_std_iter_or_itermut(def_id: DefId) -> bool {
    crate::def_id::iter_types().contains(&def_id)
}
pub fn is_std_ordering(def_id: DefId) -> bool {
    crate::def_id::ordering_types().contains(&def_id)
}

// ── Arithmetic / collection-operation classifiers ─────────────────
// Matched by `DefId` via [`crate::def_id::OP_FNS`] (resolved from `fn_defs()`).
// These were previously name-based in the call-summary registry; see
// [`crate::def_id`] for the exact method-name patterns each group collects.

pub fn is_min_like(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::min_like_fns())
}
pub fn is_max(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::max_fns())
}
pub fn is_clamp(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::clamp_fns())
}
pub fn is_abs(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::abs_fns())
}
pub fn is_neg(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::neg_fns())
}
pub fn is_sat_unchecked_add(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::sat_unchecked_add_fns())
}
pub fn is_sat_unchecked_mul(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::sat_unchecked_mul_fns())
}
pub fn is_checked_add(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::checked_add_fns())
}
pub fn is_checked_mul(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::checked_mul_fns())
}
pub fn is_overflowing_abs_neg(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::overflowing_nz_fns())
}
pub fn is_bit_preserving_nz(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::bit_preserving_nz_fns())
}
pub fn is_checked_nonzero_iff(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::checked_nonzero_iff_fns())
}
pub fn is_checked_next_pow2(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::checked_next_pow2_fns())
}
pub fn is_layout_align(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::layout_align_fns())
}
pub fn is_split_at(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::split_at_fns())
}

// ── Open-ended operation classifiers ──────────────────────────────
// These match the std-challenge suites' local `_ext` re-implementations and
// generic trait-method patterns. They cannot be tied to a *closed* hard-coded
// set, so they are resolved by name-scanning `fn_defs()` in [`crate::def_id`]
// (which also collects the local crate's re-implementations) and matched by
// `DefId` like the other classifiers.

pub fn is_align_to_local(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::align_to_local_fns())
}
pub fn is_iter_position(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::iter_position_fns())
}
pub fn is_strlen(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::strlen_fns())
}
pub fn is_slice_get_unchecked(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::slice_get_unchecked_fns())
}

/// Whether `callee` is `SliceIndex::get_unchecked`/`get_unchecked_mut` (the
/// trait method, whose receiver is the *index* and whose first argument is the
/// slice pointer). Distinct from [`is_slice_get_unchecked`] (the slice-side
/// methods whose receiver is the slice): the result aliases argument 1, not
/// argument 0.
pub fn is_sliceindex_get_unchecked(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::sliceindex_get_unchecked_fns())
}

/// Whether `callee` is `slice::range(range, bounds)` — the range normalizer that
/// returns `Range { start, end }` with `0 <= start <= end <= bounds.end`.
pub fn is_slice_range(callee: Option<DefId>) -> bool {
    any_fn(callee, crate::def_id::slice_range_fns())
}

/// Whether `callee` is `mem::replace(dest, src)` — returns `*dest` (the old
/// value), so the summary must deref the reference argument.
pub fn is_mem_replace(callee: Option<DefId>) -> bool {
    any_of(callee, &[crate::def_id::replace()])
}