about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJared Davis <message@jared-pri.me>2025-07-07 10:38:29 -0400
committerJared Davis <message@jared-pri.me>2025-07-07 10:38:29 -0400
commit2b93d2cca61ede7af6201dc7a2be7c6957ebfb77 (patch)
treef164266445b51b25da1d8a45e5e5436d3c621420
parentc943f4c0e97e808a7f1577f68361c6e24e6ead5d (diff)
downloadrust-2b93d2cca61ede7af6201dc7a2be7c6957ebfb77.tar.gz
rust-2b93d2cca61ede7af6201dc7a2be7c6957ebfb77.zip
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.
-rw-r--r--clippy_lints/src/exit.rs4
-rw-r--r--tests/ui/exit4.rs8
2 files changed, 11 insertions, 1 deletions
diff --git a/clippy_lints/src/exit.rs b/clippy_lints/src/exit.rs
index cc8e4d7d9e2..862dd6d6476 100644
--- a/clippy_lints/src/exit.rs
+++ b/clippy_lints/src/exit.rs
@@ -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()
diff --git a/tests/ui/exit4.rs b/tests/ui/exit4.rs
new file mode 100644
index 00000000000..d52cdbce0ea
--- /dev/null
+++ b/tests/ui/exit4.rs
@@ -0,0 +1,8 @@
+//@ check-pass
+//@compile-flags: --test
+
+#![warn(clippy::exit)]
+
+fn main() {
+    std::process::exit(0)
+}
\ No newline at end of file