Skip to main content

Module def_id

Module def_id 

Source
Expand description

Resolution of well-known core/std/alloc function paths to their internal [DefId]s.

This module is the single home for “which standard-library item is this DefId?”, used by crate::verify::api_classify and the alias checker to match APIs exactly instead of substring-matching a def_path_str. It is deliberately placed at the crate root (next to crate::compat) rather than under helpers/, because it owns global state and a one-time init(tcx) hook in the compiler callback.

§How a lookup works

  1. The [intrinsics!] macro declares a path table: each identifier maps to one or more candidate fn_def.name() strings (typically the std:: re-export plus the core::/alloc:: canonical form, for #![no_std] crates) and generates a {id}() -> Option<DefId> accessor.
  2. init runs once from [crate::RapCallback::after_analysis], iterates every fn_def of the core/std/alloc crates via rustc_public, and caches the path -> DefId map in a OnceLock.
  3. contains tests whether a call-site DefId is in a set of resolved ids; is_drop_fn is a convenience wrapper over the drop family.

§Path format

rustc_public::CrateDef::name() is def_path_str with crate-name resolution and untrimmed paths, so a re-exported item appears under its std:: name and generics are kept: std::mem::MaybeUninit::<T>::write, std::result::Result::<T, E>::unwrap, std::vec::Vec::<T, A>::push, std::ptr::mut_ptr::<impl *mut T>::copy_from.

§Limitations

  • In #![no_std] builds some intrinsics are absent; init only warns (rap_warn!) instead of panicking, so an entry with no matching path simply yields None.

Macros§

intrinsics 🔒

Structs§

Intrinsics 🔒
Methods 🔒
Types 🔒
Resolved DefIds of well-known std types (ADTs), used by the ADT type-name classifiers (crate::verify::api_classify::is_std_box, crate::verify::api_classify::is_std_vec, …). Each entry collects the std type’s DefId (via lang/diagnostic item, or — for NonNull, which has neither — by name-scanning the std crates’ adts()) and any same-named re-implementations in the local crate (the std-challenge suites re-implement Vec/NonNull under the same names).

Constants§

INTRINSICS 🔒
NEGATIVE_TYPE_NAMES 🔒
Short names of the std !Send/!Sync negative types resolved by name scan (those without a lang/diagnostic item). UnsafeCell is resolved via its #[lang = "unsafe_cell"] item instead.

Statics§

INIT 🔒
METHODS 🔒
Resolved DefIds of std methods that are matched by generic name rather than a fixed intrinsics! path (e.g. len, capacity, ::abs, ::checked_add, ::split_at, Iterator::position, …). Each group collects every fn_def — from the std crates and the local crate (the std-challenge suites re-implement Vec/slice-like types and their methods) — whose name matches the group’s pattern. Callers match a call-site DefId against these sets via contains.
TYPES 🔒

Functions§

abs_fns
align_to_local_fns
arc_as_ptr
arc_from_raw
arc_from_raw_in
arc_into_raw
ascii_char_types
core::ascii::Char (AsciiChar, the u8 newtype; and any local re-implementation).
assume_init_read
bit_preserving_nz_fns
box_alloc_ctors
Box::new / new_in / new_uninit / new_uninit_in (and try_ variants).
box_as_mut_ptr
box_as_ptr
box_assume_init_into_vec_unsafe
box_from_raw
box_from_raw_in
box_into_raw
box_types
alloc::boxed::Box (and any local Box re-implementation).
call_mut
capacity_fns
capacity query methods (Vec::capacity and local re-implementations).
checked_add_fns
checked_mul_fns
checked_next_pow2_fns
checked_nonzero_iff_fns
clamp_fns
clone
const_ptr_add
const_ptr_addr
const_ptr_align_offset
const_ptr_byte_add
const_ptr_byte_offset
const_ptr_byte_sub
const_ptr_cast
const_ptr_cast_array
const_ptr_cast_mut
const_ptr_is_null
const_ptr_offset
const_ptr_slice_as_ptr
const_ptr_slice_is_empty
const_ptr_slice_len
const_ptr_sub
const_ptr_wrapping_add
const_ptr_wrapping_byte_add
const_ptr_wrapping_byte_offset
const_ptr_wrapping_byte_sub
const_ptr_wrapping_offset
const_ptr_wrapping_sub
contains
Is the targe DefId in the given array.
copy_from
copy_from_nonoverlapping
copy_to
copy_to_nonoverlapping
cstr_as_ptr
cstr_from_bytes_with_nul_unchecked
cstr_from_ptr
cstr_is_empty
cstring_from_raw
cstring_from_vec_with_nul_unchecked
cstring_into_raw
cstring_types
alloc::ffi::CString (and any local CString re-implementation).
dealloc
drop
drop_in_place
exchange_malloc
alloc::alloc::exchange_malloc, if present on this toolchain.
from_raw_parts_fns
from_raw_parts constructors (slice/str/ptr/NonNull/Vec/String and local re-implementations).
from_raw_parts_mut_fns
from_raw_parts_mut constructors (slice/ptr/NonNull and local re-implementations).
hint_select_unpredictable
init
init_inner 🔒
init_methods 🔒
init_types 🔒
intrinsics_align_of
intrinsics_copy
intrinsics_copy_nonoverlapping
intrinsics_size_of
is_drop_fn
Find any drop fn. Any of these drop fns can be missing, e.g. for crates like no_std without using alloc, dealloc doesn’t exist.
is_sync_primitive_short_name 🔒
Whether a type’s short name denotes a synchronization primitive that guards its interior mutability (Mutex/RwLock/OnceLock/OnceCell/Atomic*).
iter_position_fns
iter_types
core::slice::Iter / core::slice::IterMut (the two-field ptr/end slice iterators, plus any local re-implementation).
layout_align_fns
len_fns
len query methods (slice::len, str::len, Vec::len, String::len, pointer-slice len, and any local re-implementation).
manually_drop
max_fns
maybe_uninit_as_mut_ptr
maybe_uninit_as_ptr
maybe_uninit_assume_init
maybe_uninit_assume_init_mut
maybe_uninit_assume_init_ref
maybe_uninit_types
core::mem::MaybeUninit (and any local re-implementation).
maybe_uninit_uninit
maybe_uninit_write
mem_align_of
mem_size_of
min_like_fns
mut_ptr_add
mut_ptr_addr
mut_ptr_align_offset
mut_ptr_byte_add
mut_ptr_byte_offset
mut_ptr_byte_sub
mut_ptr_cast
mut_ptr_cast_array
mut_ptr_cast_const
mut_ptr_is_null
mut_ptr_offset
mut_ptr_slice_as_mut_ptr
mut_ptr_slice_is_empty
mut_ptr_slice_len
mut_ptr_sub
mut_ptr_wrapping_add
mut_ptr_wrapping_byte_add
mut_ptr_wrapping_byte_offset
mut_ptr_wrapping_byte_sub
mut_ptr_wrapping_offset
mut_ptr_wrapping_sub
neg_fns
negative_type_defs
Resolve a negative-type name (as written in std-trait-ensures.json) to its resolved DefId set. Unknown names resolve to an empty set (the checker then reports Unknown).
negative_type_name 🔒
The negative-type name for a short type name, if it is one of the std !Send/!Sync negative types.
nonnull_add
nonnull_addr
nonnull_align_offset
nonnull_as_mut
nonnull_as_ptr
nonnull_as_ref
nonnull_byte_add
nonnull_byte_offset
nonnull_byte_sub
nonnull_cast
nonnull_new
nonnull_new_unchecked
nonnull_offset
nonnull_slice_as_mut_ptr
nonnull_slice_is_empty
nonnull_slice_len
nonnull_sub
nonnull_types
core::ptr::NonNull (and any local NonNull re-implementation).
option_expect
option_unwrap
option_unwrap_unchecked
ordering_types
core::cmp::Ordering.
overflowing_nz_fns
ptr_align_offset
ptr_read
ptr_read_unaligned
ptr_read_volatile
ptr_write
ptr_write_bytes
ptr_write_unaligned
ptr_write_volatile
rc_as_ptr
rc_from_raw
rc_from_raw_in
rc_into_raw
rc_types
alloc::rc::Rc (and any local Rc re-implementation) — the non-atomic reference-counted smart pointer, a !Send/!Sync negative type.
replace
result_expect
result_expect_err
result_unwrap
result_unwrap_err
result_unwrap_unchecked
sat_unchecked_add_fns
sat_unchecked_mul_fns
select_unpredictable
slice_as_mut_ptr
slice_as_ptr
slice_get_unchecked_fns
slice_into_vec
slice_is_empty
slice_len
slice_range_fns
slice_to_vec
sliceindex_get_unchecked_fns
split_at_fns
str_as_bytes
str_as_mut_ptr
str_as_ptr
str_is_empty
str_len
string_is_empty
string_len
strlen_fns
sync_primitive_types
Synchronization primitives (Mutex/RwLock/OnceLock/OnceCell/Atomic*, plus any local re-implementation) that guard their interior mutability, used to discharge the RefSend auto-trait obligation.
take
to_internal
rustc_public DefId to internal DefId
vec_as_mut_ptr
vec_as_ptr
vec_clear
vec_from_elem
vec_insert
vec_into_boxed_slice
vec_is_empty
vec_len
vec_ownership_transfer_fns
Vec::from_raw_parts / Vec::from_parts (ownership transfer into a Vec).
vec_push
vec_remove
vec_reserve
vec_reserve_exact
vec_set_len
vec_shrink_to
vec_shrink_to_fit
vec_truncate
vec_types
alloc::vec::Vec (and any local Vec re-implementation).
with_capacity_fns
Vec::with_capacity (and local re-implementations).