/// Whether the expression pointed at by `hir_id` belongs to a `const` evaluation context.
/// Used exclusively for diagnostics, to avoid suggestion function calls.
- pub fn is_const_context(&self, hir_id: HirId) -> bool {
+ pub fn is_inside_const_context(&self, hir_id: HirId) -> bool {
self.body_const_context(self.local_def_id(self.enclosing_body_owner(hir_id))).is_some()
}
if let hir::ExprKind::Lit(lit) = &expr.kind { lit.node.is_suffixed() } else { false }
};
- let is_const_context = self.tcx.hir().is_const_context(expr.hir_id);
+ let in_const_context = self.tcx.hir().is_inside_const_context(expr.hir_id);
let suggest_to_change_suffix_or_into =
|err: &mut DiagnosticBuilder<'_>, is_fallible: bool| {
let msg = if literal_is_ty_suffixed(expr) {
&lit_msg
- } else if is_const_context {
+ } else if in_const_context {
// Do not recommend `into` or `try_into` in const contexts.
return;
} else if is_fallible {
expected: Ty<'tcx>,
found: Ty<'tcx>,
) {
- if self.tcx.hir().is_const_context(expr.hir_id) {
+ if self.tcx.hir().is_inside_const_context(expr.hir_id) {
// Do not suggest `Box::new` in const context.
return;
}
) -> bool {
// Handle #68197.
- if self.tcx.hir().is_const_context(expr.hir_id) {
+ if self.tcx.hir().is_inside_const_context(expr.hir_id) {
// Do not suggest `Box::new` in const context.
return false;
}