- Notifications
You must be signed in to change notification settings - Fork 1.8k
Ignore wildcards in function arguments and local bindings #11454
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
Conversation
r? @Centri3 (rustbot has picked a reviewer for you, use r? to override) |
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! Definitely a positive change, just two nits and this looks good.
| ||
impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns { | ||
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) { | ||
match get_parent_node(cx.tcx, pat.hir_id) { |
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.
nit: Can we extract this into a let-else
, then match on the contained data?
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.
To be honest, I would even go further rather than use useless defensive programming by returning in the else
. Would you concur that there should not exist any situation in which a pattern will not have a parent node (and moreover reach this method)? I could use .unwrap()
here instead of a let/else
.
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.
You could use tcx.hir().get_parent()
instead. Since this is a pattern that should be true, yeah, since it's always in a body.
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.
Done.
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.
The same holds for the Node::Param
we get, it must have a parent, I'll do the same change.
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.
Done.
tests/ui/ignored_unit_patterns.rs Outdated
pub fn moo(_: () /* Do not lint */) { | ||
// Lint | ||
let _ = foo().unwrap(); | ||
// Do not lint | ||
let _: () = foo().unwrap(); | ||
// Do not lint | ||
let _: () = (); | ||
} |
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.
Can we use ui_test
error annotations here? Like:
pub fn moo(_: () /* Do not lint */) { | |
// Lint | |
let _ = foo().unwrap(); | |
// Do not lint | |
let _: () = foo().unwrap(); | |
// Do not lint | |
let _: () = (); | |
} | |
pub fn moo(_: ()) { | |
let _ = foo().unwrap(); | |
//~^ ERROR: blah blah blah | |
let _: () = foo().unwrap(); | |
let _: () = (); | |
} |
Can you also add them to the already existing tests as well?
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.
Done (in a separate and prior commit for the existing tests).
107669f
to 8421856
Compare 8421856
to 2f5c445
Compare This version looks good to me. Thanks! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fix #11403
changelog: none