Skip to content

The exit lint is emitted for test target but not for bin target #13518

Open
@stormshield-guillaumed

Description

@stormshield-guillaumed

Summary

The lint should trigger in presence of an exit call except when the call is in the main function. The lint works fine unless you include the test target of a binary with --tests or --all-targets. As main is not the entrypoint for the test target, the lint triggers if main contains an exit call.

Lint Name

exit

Reproducer

I tried this code:

fn main() {
    std::process::exit(0);
}

I saw this happen with cargo clippy --all-targets -- -Dclippy::exit:

    Checking clippy-repro v0.0.0 (/home/runner/work/clippy-repro/clippy-repro)
error: usage of `process::exit`
 --> src/main.rs:2:5
  |
2 |     std::process::exit(0);
  |     ^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#exit
  = note: requested on the command line with `-D clippy::exit`

error: could not compile `clippy-repro` (bin "clippy-repro" test) due to 1 previous error

I expected to see this happen:

     Checking clippy-repro v0.0.0 (/home/runner/work/clippy-repro/clippy-repro)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.06s

Version

cargo 1.83.0-nightly (ad074abe3 2024-10-04)
release: 1.83.0-nightly
commit-hash: ad074abe3a18ce8444c06f962ceecfd056acfc73
commit-date: 2024-10-04
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Ubuntu 22.4.0 (jammy) [64-bit]

clippy 0.1.83 (55a22d2 2024-10-06)

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions