Skip to content

Commit 2b93d2c

Browse files
committed
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.
1 parent c943f4c commit 2b93d2c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clippy_lints/src/exit.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::is_entrypoint_fn;
33
use rustc_hir::{Expr, ExprKind, Item, ItemKind, OwnerNode};
4-
use rustc_lint::{LateContext, LateLintPass};
4+
use rustc_lint::{LateContext, LateLintPass, LintContext};
55
use rustc_session::declare_lint_pass;
66
use rustc_span::sym;
77

@@ -43,6 +43,8 @@ declare_lint_pass!(Exit => [EXIT]);
4343

4444
impl<'tcx> LateLintPass<'tcx> for Exit {
4545
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
46+
if cx.sess().is_test_crate() { return; }
47+
4648
if let ExprKind::Call(path_expr, [_]) = e.kind
4749
&& let ExprKind::Path(ref path) = path_expr.kind
4850
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()

tests/ui/exit4.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//@ check-pass
2+
//@compile-flags: --test
3+
4+
#![warn(clippy::exit)]
5+
6+
fn main() {
7+
std::process::exit(0)
8+
}

0 commit comments

Comments
 (0)