Skip to content

Commit

Permalink
Follow review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
blyxyas committed Jul 23, 2024
1 parent 4e222c6 commit cfe4c15
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
25 changes: 5 additions & 20 deletions clippy_lints/src/if_let_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ declare_lint_pass!(IfLetMutex => [IF_LET_MUTEX]);

impl<'tcx> LateLintPass<'tcx> for IfLetMutex {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
let mut arm_visit = ArmVisitor { cx };
let mut op_visit = OppVisitor { cx };
let mut arm_visit = MutexVisitor { cx };
let mut op_visit = MutexVisitor { cx };
if let Some(higher::IfLet {
let_expr,
if_then,
Expand Down Expand Up @@ -87,11 +87,11 @@ impl<'tcx> LateLintPass<'tcx> for IfLetMutex {
}

/// Checks if `Mutex::lock` is called in the `if let` expr.
pub struct OppVisitor<'a, 'tcx> {
pub struct MutexVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
}

impl<'tcx> Visitor<'tcx> for OppVisitor<'_, 'tcx> {
impl<'tcx> Visitor<'tcx> for MutexVisitor<'_, 'tcx> {
type Result = ControlFlow<&'tcx Expr<'tcx>>;
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) -> ControlFlow<&'tcx Expr<'tcx>> {
if let Some(mutex) = is_mutex_lock_call(self.cx, expr) {
Expand All @@ -101,22 +101,7 @@ impl<'tcx> Visitor<'tcx> for OppVisitor<'_, 'tcx> {
}
}

/// Checks if `Mutex::lock` is called in any of the branches.
pub struct ArmVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
}

impl<'tcx> Visitor<'tcx> for ArmVisitor<'_, 'tcx> {
type Result = ControlFlow<&'tcx Expr<'tcx>>;
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) -> ControlFlow<&'tcx Expr<'tcx>> {
if let Some(mutex) = is_mutex_lock_call(self.cx, expr) {
return ControlFlow::Break(mutex);
}
visit::walk_expr(self, expr)
}
}

impl<'tcx, 'l> ArmVisitor<'tcx, 'l> {
impl<'tcx, 'l> MutexVisitor<'tcx, 'l> {
fn found_mutex_if_same_as(&self, op_mutex: &Expr<'_>, found_mutex: Option<&'tcx Expr<'tcx>>) -> Option<&Expr<'_>> {
found_mutex.and_then(|arm_mutex| {
SpanlessEq::new(self.cx)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/mut_range_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl<'tcx> Visitor<'tcx> for BreakAfterExprVisitor {
self.break_after_expr = true;
}

return ControlFlow::Break(());
ControlFlow::Break(())
} else {
intravisit::walk_expr(self, expr)
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/option_map_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(super) fn check<'tcx>(
// Visit the body, and return if we've found a reference
if reference_visitor.visit_body(body).is_break() {
return;
};
}
}

if !unwrap_arg.span.eq_ctxt(map_span) {
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub fn for_each_expr_without_closures<'tcx, B, C: Continue>(
v.res
}

/// Calls the given function once for each expression contained. This will enter bodies, bzut not
/// Calls the given function once for each expression contained. This will enter bodies, but not
/// nested items.
pub fn for_each_expr<'tcx, B, C: Continue>(
cx: &LateContext<'tcx>,
Expand Down

0 comments on commit cfe4c15

Please sign in to comment.