mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-15 01:17:16 +00:00
fix #10776
This commit is contained in:
parent
fe792d9f7d
commit
f4b02aa374
3 changed files with 6 additions and 44 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
Loading…
Reference in a new issue