-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
restriction lint for std::process::exit
#4697
Conversation
Looks good, but perhaps we can extend the lint to skip |
I'd be fine with merging as-is and extending it in a follow-up PR though. |
That's a good idea I didn't think about it :) will update! |
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 think, the main
check can be simplified.
clippy_lints/src/exit.rs
Outdated
then { | ||
let mut parent = cx.tcx.hir().get_parent_item(e.hir_id); | ||
// We have to traverse the parents upwards until we find a function | ||
// otherwise a exit in a let or if in main would still trigger this |
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? let
s and if
s are expressions, not items. See ItemKind
on possible items get_parent_item
should 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_lint
is 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.
I did some research, it seems get_parent_item will skip non items
So the loop shouldn't be necessary? The loop will only help, when exit
is used in a nested function inside main. IMO we should still lint this though. We only want to bail out, if exit
is directly used inside main
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.
Even so the span_lint is hit for both only one error is ever emitted
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
☔ The latest upstream changes (presumably #4680) made this pull request unmergeable. Please resolve the merge conflicts. |
heads up I currently can't compile clippy or run tests it fails on some odd things like not finding runstc cratre any more |
I just had the same issue! The fix is to update the RTIM version:
and then install the master toolchain with
(or use the setup-toolchain.sh script) |
I'm still getting the following errors when trying to compile/test:
I ran the commands above, cargo clean, and cargo update. |
That changes landed yesterday on the master branch, so you have to rebase |
Should be good to go now! |
@bors r+ rollup |
📌 Commit 0bd8527 has been approved by |
🌲 The tree is currently closed for pull requests below priority 10, this pull request will be tested once the tree is reopened |
restriction lint for `std::process::exit` Addition to rust-lang#4655 - adds the lint checking for `std::process::exit` changelog: add restriction lint for `std::process::exit`
☔ The latest upstream changes (presumably #4788) made this pull request unmergeable. Please resolve the merge conflicts. |
Co-Authored-By: Philipp Krones <[email protected]>
Co-Authored-By: Philipp Krones <[email protected]>
@bors r+ rollup |
📌 Commit 2f1370d has been approved by |
🌲 The tree is currently closed for pull requests below priority 10, this pull request will be tested once the tree is reopened |
restriction lint for `std::process::exit` Addition to rust-lang#4655 - adds the lint checking for `std::process::exit` changelog: add restriction lint for `std::process::exit`
restriction lint for `std::process::exit` Addition to #4655 - adds the lint checking for `std::process::exit` changelog: add restriction lint for `std::process::exit`
☀️ Test successful - checks-travis, status-appveyor |
🎉 👍 thanks! :D |
Addition to #4655 - adds the lint checking for
std::process::exit
changelog: add restriction lint for
std::process::exit