Skip to content

Commit 8c400e9

Browse files
committed
handles the case third parameter is None
1 parent 7ca6ae7 commit 8c400e9

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

rustfmt-core/rustfmt-lib/src/visitor.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
364364
mk_sp(s.lo(), b.span.lo()),
365365
)
366366
}
367-
_ => return,
367+
_ => unreachable!(),
368368
};
369369

370370
if let Some((fn_str, fn_brace_style)) = rewrite {
@@ -502,7 +502,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
502502
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => {
503503
self.visit_static(&StaticParts::from_item(item));
504504
}
505-
ast::ItemKind::Fn(ref fn_signature, ref generics, ref body) => {
505+
ast::ItemKind::Fn(ref fn_signature, ref generics, Some(ref body)) => {
506506
let inner_attrs = inner_attributes(&item.attrs);
507507
let fn_ctxt = match fn_signature.header.ext {
508508
ast::Extern::None => visit::FnCtxt::Free,
@@ -514,7 +514,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
514514
item.ident,
515515
&fn_signature,
516516
&item.vis,
517-
body.as_deref(),
517+
Some(body),
518518
),
519519
generics,
520520
&fn_signature.decl,
@@ -523,6 +523,17 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
523523
Some(&inner_attrs),
524524
)
525525
}
526+
ast::ItemKind::Fn(ref fn_signature, ref generics, None) => {
527+
let indent = self.block_indent;
528+
let rewrite = self.rewrite_required_fn(
529+
indent,
530+
item.ident,
531+
&fn_signature,
532+
generics,
533+
item.span,
534+
);
535+
self.push_rewrite(item.span, rewrite);
536+
}
526537
ast::ItemKind::TyAlias(ref ty, ref generics) => match ty.kind.opaque_top_hack() {
527538
None => {
528539
let rewrite = rewrite_type_alias(
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// following code is invalid but should not cause an internal error
22
fn main() {
3-
extern "C" fn packet_records_options_impl_layout_length_encoding_option_len_multiplier();
3+
extern "C" fn packet_records_options_impl_layout_length_encoding_option_len_multiplier();
44
}

0 commit comments

Comments
 (0)