Function clippy_utils::is_in_const_context
source · pub fn is_in_const_context(cx: &LateContext<'_>) -> bool
Expand description
Checks if we are currently in a const context (e.g. const fn
, static
/const
initializer).
The current context is determined based on the current body which is set before calling a lint’s
entry point (any function on LateLintPass
). If you need to check in a different context use
tcx.hir().is_inside_const_context(_)
.
Do not call this unless the LateContext
has an enclosing body. For release build this case
will safely return false
, but debug builds will ICE. Note that check_expr
, check_block
,
check_pat
and a few other entry points will always have an enclosing body. Some entry points
like check_path
or check_ty
may or may not have one.