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

Don't lint manual_assert in else if #10013

Merged
merged 1 commit into from
Dec 1, 2022
Merged

Conversation

Jarcho
Copy link
Contributor

@Jarcho Jarcho commented Dec 1, 2022

fixes #9886
changelog: manual_assert: Don't lint in else if

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2022

r? @Manishearth

(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 Dec 1, 2022
@@ -47,6 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
if cx.tcx.item_name(macro_call.def_id) == sym::panic;
if !cx.tcx.sess.source_map().is_multiline(cond.span);
if let Some(format_args) = FormatArgsExpn::find_nested(cx, then, macro_call.expn);
if !is_else_clause(cx.tcx, expr);
Copy link
Member

@flip1995 flip1995 Dec 1, 2022

Choose a reason for hiding this comment

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

I don't think linting here is wrong. Couldn't we just wrap the suggestion in { ... } in the else_clause case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would also work, but would probably annoy people who would otherwise like the lint (me being one of them). It could be a config to enable linting a trailing else if.

Linting here doesn't have the same benefit of removing the whole if expression the other cases do. Changing

} else if foo {
    panic!("oh no!");
}

to

} else {
    assert!(foo, "oh no!");
}

is an even more pedantic change than the regular case. Because the else clause still needs to exist, all this accomplishes is shuffling the condition around, rather than remove a construct from the code.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I kind of agree with jarcho here.

However, I would like a comment here stating why we skip the else clause

@Manishearth
Copy link
Member

@bors r+

we can figure out making it a config in a followup if @flip1995 feels strongly

@bors
Copy link
Collaborator

bors commented Dec 1, 2022

📌 Commit 47fb67f has been approved by Manishearth

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Dec 1, 2022

⌛ Testing commit 47fb67f with merge fec0057...

@bors
Copy link
Collaborator

bors commented Dec 1, 2022

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

@bors bors merged commit fec0057 into rust-lang:master Dec 1, 2022
@flip1995
Copy link
Member

flip1995 commented Dec 2, 2022

we can figure out making it a config in a followup if @flip1995 feels strongly

No need for a config option. The reason given by Jarcho totally makes sense. I don't think this lint will gain much from a config value then.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

manual_assert mangles code and introduces syntax errors
5 participants