Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy_lints/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for Exit {
// in compilation contexts like --all-targets (which include --tests), you get false positives
// because in a test context, main is not the entrypoint function
&& ident.name != sym::main
&& !e.span.in_external_macro(cx.tcx.sess.source_map())
{
span_lint(cx, EXIT, e.span, "usage of `process::exit`");
}
Expand Down
19 changes: 19 additions & 0 deletions tests/ui/exit1.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@aux-build: proc_macros.rs
#![warn(clippy::exit)]

fn not_main() {
Expand All @@ -14,3 +15,21 @@ fn main() {
not_main();
std::process::exit(1);
}

fn issue17082() {
macro_rules! mac {
($x:expr) => {{
$x;
}};
(ex $x:expr) => {{
std::process::exit($x);
//~^ exit
}};
}
mac!(std::process::exit(1));
//~^ exit
mac!(ex 1);
proc_macros::external! {
std::process::exit(1);
}
}
21 changes: 19 additions & 2 deletions tests/ui/exit1.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
error: usage of `process::exit`
--> tests/ui/exit1.rs:5:9
--> tests/ui/exit1.rs:6:9
|
LL | std::process::exit(4);
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::exit` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::exit)]`

error: aborting due to 1 previous error
error: usage of `process::exit`
--> tests/ui/exit1.rs:29:10
|
LL | mac!(std::process::exit(1));
| ^^^^^^^^^^^^^^^^^^^^^

error: usage of `process::exit`
--> tests/ui/exit1.rs:25:13
|
LL | std::process::exit($x);
| ^^^^^^^^^^^^^^^^^^^^^^
...
LL | mac!(ex 1);
| ---------- in this macro invocation
|
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors