-
Notifications
You must be signed in to change notification settings - Fork 1.8k
restriction lint for std::process::exit
#4697
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 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
695aa59
Add lint for exit
Licenser 60c2fdd
Update lints
Licenser 9471669
Exclude main from exit lint
Licenser ffcf4be
Improve function checking
Licenser eae6a62
Simplify dentry point detection
Licenser a984702
Update clippy_lints/src/lib.rs
Licenser abdf027
Update clippy_lints/src/lib.rs
Licenser 5e6017d
Update tests for exit
Licenser 2f1370d
Update lints
Licenser 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
Exclude main from exit lint
- Loading branch information
commit 9471669e4695921cd8b70c8edaad143d8e84f430
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 |
|---|---|---|
| @@ -1,4 +1,12 @@ | ||
| #[warn(clippy::exit)] | ||
| fn not_main() { | ||
| std::process::exit(3); | ||
| } | ||
|
|
||
| fn main() { | ||
| if true { | ||
| std::process::exit(2); | ||
| }; | ||
| not_main(); | ||
| std::process::exit(1); | ||
| } |
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
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.
Have you tested this?
lets andifs are expressions, not items. SeeItemKindon possible itemsget_parent_itemshould find.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 did some research, it seems get_parent_item will skip non items, which is fine as we don't fare for anything but the first function parent, so if there is a
if ... { exit(0) }it will still just skip the if and right go to the function.That said I'm running in a odd problem and I'm a bit stuck. I added another test to ensure this works with a if un a function, and here it gets odd. Even so the
span_lintis hit for both only one error is ever emitted. So I'm a bit stomped. I left the test failing.A hand with why only one span is emitted would be greatly appreciated.
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.
So the loop shouldn't be necessary? The loop will only help, when
exitis used in a nested function inside main. IMO we should still lint this though. We only want to bail out, ifexitis directly used insidemainThere 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.
That is really weird.
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.
Good point, I removed the loop, I had the thought that there might something else in the path we need skip but you're right the next item should be the function I removed the loop!
And yes that's really weird o.O