-
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2b93d2c
skip exit late lint pass on tests
Jared-Prime 1f36d4d
run `cargo dev fmt` on changes
Jared-Prime c000a01
fix: check against 'main' function name instead of entrypoint function
sesgoe 5853e6f
chore: add tests to check against the --test compile flag
sesgoe 52aa383
Merge pull request #1 from sesgoe/ses/update-clippy-fix-13518
Jared-Prime 1c7fb0f
do not completely suppress warning with test code
Jared-Prime 9580d61
remove no longer used import
Jared-Prime 81dd4e6
use preinterned symbol
Jared-Prime File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
//@ check-pass | ||
//@compile-flags: --test | ||
|
||
#![warn(clippy::exit)] | ||
|
||
fn main() { | ||
std::process::exit(0) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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 IMOThere 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 sessionsThere 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 literallymain
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.
Thanks, @y21 . I added the changes and documentation updates recommended by @sesgoe then removed the blanket skip for test crates. Let me know if anything else required here!