Skip to content
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

Merged
merged 9 commits into from
Nov 7, 2019
Merged

Conversation

Licenser
Copy link
Contributor

@Licenser Licenser commented Oct 18, 2019

Addition to #4655 - adds the lint checking for std::process::exit

changelog: add restriction lint for std::process::exit

@llogiq
Copy link
Contributor

llogiq commented Oct 19, 2019

Looks good, but perhaps we can extend the lint to skip main functions automatically? IIRC we can get the parent item with utils::get_parent_item(cx, hir_id) and then we could check if its kind isItemFn named main.

@llogiq
Copy link
Contributor

llogiq commented Oct 19, 2019

I'd be fine with merging as-is and extending it in a follow-up PR though.

@Licenser
Copy link
Contributor Author

That's a good idea I didn't think about it :) will update!

Copy link
Member

@flip1995 flip1995 left a 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.

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
Copy link
Member

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 and ifs are expressions, not items. See ItemKind on possible items get_parent_item should find.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Member

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.

Copy link
Contributor Author

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

clippy_lints/src/exit.rs Outdated Show resolved Hide resolved
@bors
Copy link
Collaborator

bors commented Oct 23, 2019

☔ The latest upstream changes (presumably #4680) made this pull request unmergeable. Please resolve the merge conflicts.

clippy_lints/src/lib.rs Outdated Show resolved Hide resolved
clippy_lints/src/lib.rs Outdated Show resolved Hide resolved
@Licenser
Copy link
Contributor Author

heads up I currently can't compile clippy or run tests it fails on some odd things like not finding runstc cratre any more

@flip1995
Copy link
Member

I just had the same issue!

The fix is to update the RTIM version:

$ cargo install -Z install-upgrade rustup-toolchain-install-master --bin rustup-toolchain-install-master

and then install the master toolchain with

$ rustup-toolchain-install-master -f -n master -c rustc-dev

(or use the setup-toolchain.sh script)

@Licenser
Copy link
Contributor Author

I'm still getting the following errors when trying to compile/test:

error[E0603]: module `hygiene` is private
  --> clippy_lints/src/utils/mod.rs:48:20
   |
48 | use syntax_expand::hygiene::ExpnKind;
   |                    ^^^^^^^

error[E0603]: module `hygiene` is private
   --> clippy_lints/src/misc.rs:599:24
    |
599 |     use syntax_expand::hygiene::MacroKind;
    |                        ^^^^^^^

error[E0603]: enum `MacroKind` is private
  --> clippy_lints/src/types.rs:22:26
   |
22 | use syntax_expand::base::MacroKind;
   |                          ^^^^^^^^^

error[E0603]: module `hygiene` is private
  --> clippy_lints/src/types.rs:23:20
   |
23 | use syntax_expand::hygiene::ExpnKind;
   |                    ^^^^^^^

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0603`.
error: could not compile `clippy_lints`.

I ran the commands above, cargo clean, and cargo update.

@flip1995
Copy link
Member

That changes landed yesterday on the master branch, so you have to rebase

@Licenser
Copy link
Contributor Author

Should be good to go now!

@flip1995
Copy link
Member

flip1995 commented Nov 7, 2019

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 7, 2019

📌 Commit 0bd8527 has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Nov 7, 2019

🌲 The tree is currently closed for pull requests below priority 10, this pull request will be tested once the tree is reopened

flip1995 added a commit to flip1995/rust-clippy that referenced this pull request Nov 7, 2019
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`
@bors
Copy link
Collaborator

bors commented Nov 7, 2019

☔ The latest upstream changes (presumably #4788) made this pull request unmergeable. Please resolve the merge conflicts.

@flip1995
Copy link
Member

flip1995 commented Nov 7, 2019

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Nov 7, 2019

📌 Commit 2f1370d has been approved by flip1995

@bors
Copy link
Collaborator

bors commented Nov 7, 2019

🌲 The tree is currently closed for pull requests below priority 10, this pull request will be tested once the tree is reopened

flip1995 added a commit to flip1995/rust-clippy that referenced this pull request Nov 7, 2019
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`
bors added a commit that referenced this pull request Nov 7, 2019
Rollup of 4 pull requests

Successful merges:

 - #4697 (restriction lint for `std::process::exit`)
 - #4757 (Fix Deprecated lints don't expand)
 - #4758 (`DecimalLiteralRepresentation` simplification)
 - #4769 (don't warn on CRLF in `with_newline` lints)

Failed merges:

r? @ghost
bors added a commit that referenced this pull request Nov 7, 2019
Rollup of 4 pull requests

Successful merges:

 - #4697 (restriction lint for `std::process::exit`)
 - #4757 (Fix Deprecated lints don't expand)
 - #4758 (`DecimalLiteralRepresentation` simplification)
 - #4769 (don't warn on CRLF in `with_newline` lints)

Failed merges:

r? @ghost
bors added a commit that referenced this pull request Nov 7, 2019
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`
@bors
Copy link
Collaborator

bors commented Nov 7, 2019

⌛ Testing commit 2f1370d with merge 4be144a...

@bors
Copy link
Collaborator

bors commented Nov 7, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: flip1995
Pushing 4be144a to master...

@bors bors merged commit 2f1370d into rust-lang:master Nov 7, 2019
@Licenser
Copy link
Contributor Author

🎉 👍 thanks! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants