skip exit late lint pass on tests
When using the `--test` or `--all-targets` flag, the exit lint should not fail on the main function.
This commit is contained in:
parent
c943f4c0e9
commit
2b93d2cca6
2 changed files with 11 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use clippy_utils::diagnostics::span_lint;
|
||||
use clippy_utils::is_entrypoint_fn;
|
||||
use rustc_hir::{Expr, ExprKind, Item, ItemKind, OwnerNode};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_session::declare_lint_pass;
|
||||
use rustc_span::sym;
|
||||
|
||||
|
|
@ -43,6 +43,8 @@ declare_lint_pass!(Exit => [EXIT]);
|
|||
|
||||
impl<'tcx> LateLintPass<'tcx> for Exit {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
|
||||
if cx.sess().is_test_crate() { return; }
|
||||
|
||||
if let ExprKind::Call(path_expr, [_]) = e.kind
|
||||
&& let ExprKind::Path(ref path) = path_expr.kind
|
||||
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
|
||||
|
|
|
|||
8
tests/ui/exit4.rs
Normal file
8
tests/ui/exit4.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
//@ check-pass
|
||||
//@compile-flags: --test
|
||||
|
||||
#![warn(clippy::exit)]
|
||||
|
||||
fn main() {
|
||||
std::process::exit(0)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue