-
Notifications
You must be signed in to change notification settings - Fork 1.7k
skip exit late lint pass on tests #15222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
When using the `--test` or `--all-targets` flag, the exit lint should not fail on the main function.
clippy_lints/src/exit.rs
Outdated
if cx.sess().is_test_crate() { | ||
return; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suppresses the lint entirely in --test
sessions and will not emit a lint anywhere in the crate, even if we aren't actually in a main fn and we should emit a warning, right?
I think that would interact confusingly with #[expect]
and create a situation similar to #13358, where if you have something like:
fn foo() {
#[expect(clippy::exit)]
std::process::exit();
}
and run cargo clippy --all-targets
, then you get an unfulfilled lint expectation, but if you remove the #[expect]
, you do get the warning there.
--all-targets
runs clippy twice, once without --test
and again with --test
, so only sometimes emitting a warning dependent on the session (like is done here) is a bit confusing for users IMO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if, instead of using !is_entrypoint_fn
at the end of the condition chain, which I guess is also dependent on the session and different for the test harness, we could just change that to check if the enclosing function's name is not literally "main". That seems closer to what we actually want and would be more consistent between compiler sessions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@y21 I had the same thought after reading your first comment, and upon consideration, this seems like a good way to go
I saw the if cx.sess().is_test_crate() { return; }
pattern elsewhere, which is why it seemed reasonable to slot it in here too -- the only real thought was: in a test context, is this lint relevant?
The confusing interaction with --all-targets
is worth fixing, and checking that the name is literally main
makes it clear in both compilation contexts/sessions, so that feels like a good solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update docs to be a bit more clear
fix: check against 'main' function name instead of entrypoint function
changelog: [
exit
]: When using the--test
or--all-targets
flag, the exit lint should not fail on the main function.Fixes #13518
With help from @sesgoe