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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rustfmt-core/rustfmt-lib/src/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.

};

if let Some((fn_str, fn_brace_style)) = rewrite {
Expand Down
4 changes: 4 additions & 0 deletions rustfmt-core/rustfmt-lib/tests/target/issue-4068.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// following code is invalid but should not cause an internal error
fn main() {
extern "C" fn packet_records_options_impl_layout_length_encoding_option_len_multiplier();
}