Function check_ptr_transmute_in_const

Source
fn check_ptr_transmute_in_const<'tcx>(
    cx: &LateContext<'tcx>,
    expr: &'tcx Expr<'tcx>,
    body_owner_def_id: LocalDefId,
    const_context: Option<ConstContext>,
    src: Ty<'tcx>,
    dst: Ty<'tcx>,
)
Expand description

Check for transmutes that exhibit undefined behavior. For example, transmuting pointers to integers in a const context.

Why do we consider const functions and associated constants only?

Generally, undefined behavior in const items are handled by the evaluator. But, const functions and associated constants are evaluated only when referenced. This can result in undefined behavior in a library going unnoticed until the function or constant is actually used.

Therefore, we only consider const functions and associated constants here and leave other const items to be handled by the evaluator.