-
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
Fix handling of panic calls #6310
Conversation
r? @Manishearth (rust_highfive has picked a reviewer for you, use r? to override) |
r? @flip1995 |
I'm getting this error:
Is that because |
Hmm, |
They should be used through the `match_panic_call` and `match_panic_def_id` functions to ensure consistency across Clippy.
Cc @m-ou-se |
Oops, clippy is correct: the path is |
It might be good to add a test to check that clippy now reacts to core::panic too. |
It's a good thing you had me add that test, because the output looks wonky :) |
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.
Ultimately this PR should be opened in rust-lang/rust, to avoid the sync round trip. But we can review and test it here and just apply the patches in rust-lang/rust.
Is there anything we can do in std/core to make it easier for Clippy to recognise panic/unimplemented/assert/etc.? Its detection right now seems very fragile, as it depends on the exact expansion of these macros. Those macros are going to change soon, and some will expand differently in Rust 2021. Also, Maybe some |
The problem is, that Clippy only sees the expanded version of macros and has no access to the pre-expansion code. So I don't think a diag item will help here. We can check if a certain span is from a specific macro expansion with Macros are tricky, and for example, if we need macro arguments it leads to hacks like this: rust-clippy/clippy_lints/src/utils/higher.rs Lines 246 to 253 in d212c38
|
Ugh, now only |
All the other tests are wrapped in |
I don't know; I tried adding that, and it didn't change the output at all. |
Clippy seems to check specifically for that |
This makes it work: - if let ExprKind::Block(ref block, _) = expr.kind;
- if let Some(ref ex) = block.expr;
- if let Some(params) = match_panic_call(cx, ex);
+ if let Some(params) = match_panic_call(cx, expr); ( |
@m-ou-se It worked! Wonder why the code was expecting a block... Thanks so much for helping me figure this stuff out :) |
Co-authored-by: Mara Bos <[email protected]>
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.
Wonder why the code was expecting a block...
Probably some legacy code, no one knows the reason anymore. 😄
This LGTM. It would be great, if you could do this in rustc directly, so we don't have to sync this back, before your rust PR can get merged.
# in Clippy repo
git diff master --patch > clippy.patch
sed -ie "s/--- a/--- a\/src\/tools\/clippy/g" clippy.patch
sed -ie "s/+++ b/+++ b\/src\/tools\/clippy/g" clippy.patch
# in Rust repo
git apply /path/to/clippy.patch
This should make Clippy more resilient and will unblock rust-lang#78343. This PR is made against rust-lang/rust to avoid the need for a subtree sync at @flip1995's suggestion in rust-lang/rust-clippy#6310.
Closing in favor of rust-lang/rust#79145 to avoid the sync. |
Fix handling of panic calls This should make Clippy more resilient and will unblock rust-lang#78343. This PR is made against rust-lang/rust to avoid the need for a subtree sync at `@flip1995's` suggestion in rust-lang/rust-clippy#6310. r? `@flip1995` cc `@m-ou-se`
Fix handling of panic calls This should make Clippy more resilient and will unblock rust-lang#78343. This PR is made against rust-lang/rust to avoid the need for a subtree sync at ``@flip1995's`` suggestion in rust-lang/rust-clippy#6310. r? ``@flip1995`` cc ``@m-ou-se``
This should make Clippy more resilient and will unblock #78343. This PR is made against rust-lang/rust to avoid the need for a subtree sync at @flip1995's suggestion in rust-lang#6310.
Fix handling of panic calls This should make Clippy more resilient and will unblock #78343. This PR is made against rust-lang/rust to avoid the need for a subtree sync at ``@flip1995's`` suggestion in rust-lang#6310. r? ``@flip1995`` cc ``@m-ou-se``
Fix handling of panic calls. This should make Clippy more resilient and will unblock rust-lang/rust#78343.
changelog: none