Skip to content

replace if_let_chain with if_chain #2154

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

Merged
merged 3 commits into from
Oct 24, 2017
Merged

replace if_let_chain with if_chain #2154

merged 3 commits into from
Oct 24, 2017

Conversation

durka
Copy link
Contributor

@durka durka commented Oct 19, 2017

Fixes #2150. Done mostly mechanically with a hacked-up version of @japaric's untry.

@durka
Copy link
Contributor Author

durka commented Oct 19, 2017

The tests don't get very far on my machine due to some procedural macro BS, so I figured travis could have a crack at it.

@durka
Copy link
Contributor Author

durka commented Oct 19, 2017

Rebased on #2153 temporarily.

@durka durka force-pushed the ifchain branch 2 times, most recently from 4ceccc4 to 8550397 Compare October 19, 2017 22:21
@oli-obk
Copy link
Contributor

oli-obk commented Oct 20, 2017

I merged #2153, can you rebase over master?

if_chain! {
if let Some(inner) = expr_block(then);
if let ast::ExprKind::If(ref check_inner, ref content, None) = inner.node;
then {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I'd prefer it if we didn't have to use an additional indentation level. Maybe use something like

if_chain! {
   ...
then {
   ...
}}

Opinions?

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 went with the indentation used in the crate's examples: https://docs.rs/if_chain/0.1.2/if_chain/

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I can get behind staying with the official style

@oli-obk oli-obk added the S-needs-discussion Status: Needs further discussion before merging or work can be started label Oct 20, 2017
@durka
Copy link
Contributor Author

durka commented Oct 20, 2017

Rebased.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

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

You lost all comments in the chains. Are they not supported?

@durka
Copy link
Contributor Author

durka commented Oct 20, 2017

I think I can fix that. At least for line comments it should be easy...

@durka
Copy link
Contributor Author

durka commented Oct 23, 2017

I recovered the comments and linebreaks. And my frankenstein untry learned to handle nested chains.

@@ -117,40 +117,41 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
if decl.inputs.is_empty() && name == "new" && cx.access_levels.is_reachable(id) {
let self_ty = cx.tcx
.type_of(cx.tcx.hir.local_def_id(cx.tcx.hir.get_parent(id)));
if_let_chain!{[
same_tys(cx, self_ty, return_ty(cx, id)),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indentation is wrong here, but I didn't cause that...

@oli-obk oli-obk merged commit f9682ca into rust-lang:master Oct 24, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Oct 24, 2017

Awesome! Another code duplication bites the dust

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-needs-discussion Status: Needs further discussion before merging or work can be started
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants