Skip to content

Commit f4b02aa

Browse files
committed
fix #10776
1 parent fe792d9 commit f4b02aa

File tree

3 files changed

+6
-44
lines changed

3 files changed

+6
-44
lines changed

clippy_lints/src/mixed_read_write_in_expression.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
22
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
33
use if_chain::if_chain;
4-
use rustc_hir::intravisit::{walk_expr, Visitor};
4+
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
55
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::ty;
@@ -155,6 +155,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
155155
self.report_diverging_sub_expr(e);
156156
}
157157
},
158+
ExprKind::Block(block, ..) => walk_block(self, block),
158159
_ => {
159160
// do not lint expressions referencing objects of type `!`, as that required a
160161
// diverging expression
@@ -163,9 +164,6 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
163164
}
164165
self.maybe_walk_expr(e);
165166
}
166-
fn visit_block(&mut self, _: &'tcx Block<'_>) {
167-
// don't continue over blocks, LateLintPass already does that
168-
}
169167
}
170168

171169
/// Walks up the AST from the given write expression (`vis.write_expr`) looking

tests/ui/diverging_sub_expression.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![warn(clippy::diverging_sub_expression)]
22
#![allow(clippy::match_same_arms, clippy::overly_complex_bool_expr)]
3+
#![allow(clippy::nonminimal_bool)]
34
#[allow(clippy::empty_loop)]
45
fn diverge() -> ! {
56
loop {}
@@ -35,6 +36,9 @@ fn foobar() {
3536
99 => return,
3637
_ => true || panic!("boo"),
3738
},
39+
// lint blocks as well
40+
15 => true || { return; },
41+
16 => false || { return; },
3842
_ => true || break,
3943
};
4044
}
-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +0,0 @@
1-
error: sub-expression diverges
2-
--> $DIR/diverging_sub_expression.rs:19:10
3-
|
4-
LL | b || diverge();
5-
| ^^^^^^^^^
6-
|
7-
= note: `-D clippy::diverging-sub-expression` implied by `-D warnings`
8-
9-
error: sub-expression diverges
10-
--> $DIR/diverging_sub_expression.rs:20:10
11-
|
12-
LL | b || A.foo();
13-
| ^^^^^^^
14-
15-
error: sub-expression diverges
16-
--> $DIR/diverging_sub_expression.rs:29:26
17-
|
18-
LL | 6 => true || return,
19-
| ^^^^^^
20-
21-
error: sub-expression diverges
22-
--> $DIR/diverging_sub_expression.rs:30:26
23-
|
24-
LL | 7 => true || continue,
25-
| ^^^^^^^^
26-
27-
error: sub-expression diverges
28-
--> $DIR/diverging_sub_expression.rs:33:26
29-
|
30-
LL | 3 => true || diverge(),
31-
| ^^^^^^^^^
32-
33-
error: sub-expression diverges
34-
--> $DIR/diverging_sub_expression.rs:38:26
35-
|
36-
LL | _ => true || break,
37-
| ^^^^^
38-
39-
error: aborting due to 6 previous errors
40-

0 commit comments

Comments
 (0)