diff options
| author | Centri3 <114838443+Centri3@users.noreply.github.com> | 2023-05-15 11:20:04 -0500 |
|---|---|---|
| committer | Centri3 <114838443+Centri3@users.noreply.github.com> | 2023-05-23 00:35:00 -0500 |
| commit | f4b02aa3741299b8226f50ba63ec1f4e27a64d14 (patch) | |
| tree | bac95b8a03fa716e7505628bc4d597ca8d5c9a48 | |
| parent | fe792d9f7dceac7ddb38524a15031c0ea68730fa (diff) | |
| download | rust-f4b02aa3741299b8226f50ba63ec1f4e27a64d14.tar.gz rust-f4b02aa3741299b8226f50ba63ec1f4e27a64d14.zip | |
fix #10776
| -rw-r--r-- | clippy_lints/src/mixed_read_write_in_expression.rs | 6 | ||||
| -rw-r--r-- | tests/ui/diverging_sub_expression.rs | 4 | ||||
| -rw-r--r-- | tests/ui/diverging_sub_expression.stderr | 40 |
3 files changed, 6 insertions, 44 deletions
diff --git a/clippy_lints/src/mixed_read_write_in_expression.rs b/clippy_lints/src/mixed_read_write_in_expression.rs index f0be7771bb1..2dfab259915 100644 --- a/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/clippy_lints/src/mixed_read_write_in_expression.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_note}; use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id}; use if_chain::if_chain; -use rustc_hir::intravisit::{walk_expr, Visitor}; +use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; @@ -155,6 +155,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { self.report_diverging_sub_expr(e); } }, + ExprKind::Block(block, ..) => walk_block(self, block), _ => { // do not lint expressions referencing objects of type `!`, as that required a // diverging expression @@ -163,9 +164,6 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { } self.maybe_walk_expr(e); } - fn visit_block(&mut self, _: &'tcx Block<'_>) { - // don't continue over blocks, LateLintPass already does that - } } /// Walks up the AST from the given write expression (`vis.write_expr`) looking diff --git a/tests/ui/diverging_sub_expression.rs b/tests/ui/diverging_sub_expression.rs index e8f992e6dde..1dd3f3b8bc4 100644 --- a/tests/ui/diverging_sub_expression.rs +++ b/tests/ui/diverging_sub_expression.rs @@ -1,5 +1,6 @@ #![warn(clippy::diverging_sub_expression)] #![allow(clippy::match_same_arms, clippy::overly_complex_bool_expr)] +#![allow(clippy::nonminimal_bool)] #[allow(clippy::empty_loop)] fn diverge() -> ! { loop {} @@ -35,6 +36,9 @@ fn foobar() { 99 => return, _ => true || panic!("boo"), }, + // lint blocks as well + 15 => true || { return; }, + 16 => false || { return; }, _ => true || break, }; } diff --git a/tests/ui/diverging_sub_expression.stderr b/tests/ui/diverging_sub_expression.stderr index 51a3b0d972e..e69de29bb2d 100644 --- a/tests/ui/diverging_sub_expression.stderr +++ b/tests/ui/diverging_sub_expression.stderr @@ -1,40 +0,0 @@ -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:19:10 - | -LL | b || diverge(); - | ^^^^^^^^^ - | - = note: `-D clippy::diverging-sub-expression` implied by `-D warnings` - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:20:10 - | -LL | b || A.foo(); - | ^^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:29:26 - | -LL | 6 => true || return, - | ^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:30:26 - | -LL | 7 => true || continue, - | ^^^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:33:26 - | -LL | 3 => true || diverge(), - | ^^^^^^^^^ - -error: sub-expression diverges - --> $DIR/diverging_sub_expression.rs:38:26 - | -LL | _ => true || break, - | ^^^^^ - -error: aborting due to 6 previous errors - |
