From 27e64ed0c2dfe778a4937ffdd13b216c4f0452cb Mon Sep 17 00:00:00 2001 From: Facundo Lerena Date: Thu, 7 Dec 2023 11:28:29 -0300 Subject: [PATCH] detector fix --- detectors/unsafe-block/src/lib.rs | 27 +++++++++++---------------- scout-audit-internal/src/detector.rs | 2 +- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/detectors/unsafe-block/src/lib.rs b/detectors/unsafe-block/src/lib.rs index 2cde0603..14137c5d 100644 --- a/detectors/unsafe-block/src/lib.rs +++ b/detectors/unsafe-block/src/lib.rs @@ -9,7 +9,7 @@ use rustc_hir::{ Expr, ExprKind, }; use rustc_lint::LateLintPass; -use rustc_span::{Span, Symbol}; +use rustc_span::Span; use scout_audit_internal::Detector; dylint_linting::declare_late_lint! { @@ -69,18 +69,18 @@ impl<'tcx> LateLintPass<'tcx> for AvoidUnsafeBlock { impl<'tcx> Visitor<'tcx> for UnsafeBlockVisitor { fn visit_expr(&mut self, expr: &'tcx Expr<'_>) { - match expr.kind { - ExprKind::Block(ref block, _) => { - if block.rules == rustc_hir::BlockCheckMode::AvoidUnsafeBlock( + if let ExprKind::Block(block, _) = expr.kind { + if block.rules + == rustc_hir::BlockCheckMode::UnsafeBlock( rustc_hir::UnsafeSource::UserProvided, - ) { - self.unsafe_blocks.push(Some(expr.span)); - } else { - self.unsafe_blocks.push(None); - } + ) + { + self.unsafe_blocks.push(Some(expr.span)); + } else { + self.unsafe_blocks.push(None); } - _ => {} } + walk_expr(self, expr); } } @@ -93,13 +93,8 @@ impl<'tcx> LateLintPass<'tcx> for AvoidUnsafeBlock { visitor.unsafe_blocks.iter().for_each(|span| { if let Some(span) = span { - Detector::AvoidUnsafeBlock.span_lint( - cx, - AVOID_UNSAFE_BLOCK, - *span - ); + Detector::AvoidUnsafeBlock.span_lint(cx, AVOID_UNSAFE_BLOCK, *span); } }); - } } diff --git a/scout-audit-internal/src/detector.rs b/scout-audit-internal/src/detector.rs index 9b572876..15835c06 100644 --- a/scout-audit-internal/src/detector.rs +++ b/scout-audit-internal/src/detector.rs @@ -26,12 +26,12 @@ use strum::{Display, EnumIter}; #[derive(Debug, Display, Clone, EnumIter, PartialEq, Eq, Hash)] #[strum(serialize_all = "kebab-case")] pub enum Detector { + AvoidUnsafeBlock, AvoidCoreMemForget, DivideBeforeMultiply, InsufficientlyRandomValues, OverflowCheck, UnprotectedUpdateCurrentContractWasm, - UnsafeBlock, UnsafeExpect, UnsafeUnwrap, }