Skip to main content

forge_lint/sol/med/
mapping_deletion.rs

1use super::MappingDeletion;
2use crate::{
3    linter::{LateLintPass, LintContext},
4    sol::{Severity, SolLint},
5};
6use solar::sema::{
7    Gcx,
8    hir::{self, ExprKind},
9};
10
11declare_forge_lint!(
12    MAPPING_DELETION,
13    Severity::Med,
14    "mapping-deletion",
15    "`delete` on a value containing a mapping does not clear the mapping"
16);
17
18impl<'gcx> LateLintPass<'gcx> for MappingDeletion {
19    fn check_expr(&mut self, ctx: &LintContext, gcx: Gcx<'gcx>, expr: &'gcx hir::Expr<'gcx>) {
20        if let ExprKind::Delete(operand) = &expr.kind
21            && let Some(ty) = gcx.type_of_expr(operand.peel_parens().id)
22            && ty.has_mapping(gcx)
23        {
24            ctx.emit(&MAPPING_DELETION, expr.span);
25        }
26    }
27}