Skip to content

Commit

Permalink
detector fix
Browse files Browse the repository at this point in the history
  • Loading branch information
faculerena committed Dec 7, 2023
1 parent 7a8c93c commit 27e64ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
27 changes: 11 additions & 16 deletions detectors/unsafe-block/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
});

}
}
2 changes: 1 addition & 1 deletion scout-audit-internal/src/detector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 27e64ed

Please sign in to comment.