Skip to content

Conversation

samueltardieu
Copy link
Member

Fix #11403

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Sep 2, 2023

r? @Centri3

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 2, 2023
Copy link
Member

@Centri3 Centri3 left a 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) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member Author

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 18 to 25
pub fn moo(_: () /* Do not lint */) {
// Lint
let _ = foo().unwrap();
// Do not lint
let _: () = foo().unwrap();
// Do not lint
let _: () = ();
}
Copy link
Member

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:

Suggested change
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?

Copy link
Member Author

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).

@samueltardieu samueltardieu force-pushed the issue-11403 branch 2 times, most recently from 107669f to 8421856 Compare September 4, 2023 15:16
@Centri3
Copy link
Member

Centri3 commented Sep 5, 2023

This version looks good to me. Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Sep 5, 2023

📌 Commit 2f5c445 has been approved by Centri3

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Sep 5, 2023

⌛ Testing commit 2f5c445 with merge eb0df1d...

@bors
Copy link
Contributor

bors commented Sep 5, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Centri3
Pushing eb0df1d to master...

@bors bors merged commit eb0df1d into rust-lang:master Sep 5, 2023
@samueltardieu samueltardieu deleted the issue-11403 branch November 29, 2023 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

4 participants