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

suppress internal error #4069

Merged
merged 2 commits into from
Mar 31, 2020
Merged

suppress internal error #4069

merged 2 commits into from
Mar 31, 2020

Conversation

rchaser53
Copy link
Contributor

@rchaser53 rchaser53 commented Feb 28, 2020

related: #4068

I think #4068 code is invalid, but rustfmt should not cause an internal error. So I send this PR.

@@ -364,7 +364,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
mk_sp(s.lo(), b.span.lo()),
)
}
_ => unreachable!(),
_ => return,
Copy link
Member

@calebcartwright calebcartwright Mar 10, 2020

Choose a reason for hiding this comment

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

I think this should still be unreachable!, since the other variants would be Closure or an Fn with None for the block.

Suggested change
_ => return,
_ => unreachable!(),

I think the actual issue is down in visit_item where I forgot to handle the potential None condition for the block while scrambling to update the rustc-ap crates to v642 to fix the broken nightly toolstate 😬

ast::ItemKind::Fn(ref fn_signature, ref generics, ref body) => {
let inner_attrs = inner_attributes(&item.attrs);
let fn_ctxt = match fn_signature.header.ext {
ast::Extern::None => visit::FnCtxt::Free,
_ => visit::FnCtxt::Foreign,
};
self.visit_fn(
visit::FnKind::Fn(
fn_ctxt,
item.ident,
&fn_signature,
&item.vis,
body.as_deref(),
),
generics,
&fn_signature.decl,
item.span,
ast::Defaultness::Final,
Some(&inner_attrs),
)
}

Should be:

                ast::ItemKind::Fn(ref fn_signature, ref generics, Some(ref body)) => {
                    let inner_attrs = inner_attributes(&item.attrs);
                    let fn_ctxt = match fn_signature.header.ext {
                        ast::Extern::None => visit::FnCtxt::Free,
                        _ => visit::FnCtxt::Foreign,
                    };
                    self.visit_fn(
                        visit::FnKind::Fn(
                            fn_ctxt,
                            item.ident,
                            &fn_signature,
                            &item.vis,
                            Some(body),
                        ),
                        generics,
                        &fn_signature.decl,
                        item.span,
                        ast::Defaultness::Final,
                        Some(&inner_attrs),
                    )
                }
                ast::ItemKind::Fn(ref fn_signature, ref generics, None) => {
                    let indent = self.block_indent;
                    let rewrite = self.rewrite_required_fn(
                        indent,
                        item.ident,
                        &fn_signature,
                        generics,
                        item.span,
                    );
                    self.push_rewrite(item.span, rewrite);
                }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. I fixed it.

@topecongiro
Copy link
Contributor

Thank you!

@topecongiro topecongiro merged commit dee282d into rust-lang:master Mar 31, 2020
@rchaser53 rchaser53 deleted the issue-4068 branch March 31, 2020 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants