rapx/def_ids/
diagnostic_api.rs1use rustc_hir::def_id::DefId;
13use rustc_middle::ty::TyCtxt;
14use rustc_span::Symbol;
15
16pub fn is_mem_size_or_align_of(tcx: TyCtxt<'_>, did: DefId) -> bool {
18 tcx.is_diagnostic_item(Symbol::intern("mem_size_of"), did)
19 || tcx.is_diagnostic_item(Symbol::intern("mem_align_of"), did)
20}
21
22pub fn is_ptr_read(tcx: TyCtxt<'_>, did: DefId) -> bool {
23 tcx.get_diagnostic_name(did).is_some_and(|name| {
24 matches!(name.as_str(), "ptr_read" | "ptr_read_unaligned" | "ptr_read_volatile")
25 })
26}
27
28pub fn is_ptr_write(tcx: TyCtxt<'_>, did: DefId) -> bool {
29 tcx.get_diagnostic_name(did).is_some_and(|name| {
30 matches!(name.as_str(), "ptr_write" | "ptr_write_unaligned" | "ptr_write_volatile" | "ptr_write_bytes")
31 })
32}
33
34pub fn is_ptr_write_to_uninit(tcx: TyCtxt<'_>, did: DefId) -> bool {
35 tcx.get_diagnostic_name(did)
36 .is_some_and(|name| matches!(name.as_str(), "ptr_write" | "ptr_write_bytes"))
37}
38
39pub fn is_ptr_copy(tcx: TyCtxt<'_>, did: DefId) -> bool {
40 tcx.get_diagnostic_name(did)
41 .is_some_and(|name| matches!(name.as_str(), "ptr_copy" | "ptr_copy_nonoverlapping"))
42}
43
44pub fn is_drop(tcx: TyCtxt<'_>, did: DefId) -> bool {
45 tcx.is_diagnostic_item(Symbol::intern("mem_drop"), did)
46}
47
48pub fn is_drop_in_place(tcx: TyCtxt<'_>, did: DefId) -> bool {
49 tcx.is_diagnostic_item(Symbol::intern("ptr_drop_in_place"), did)
50}