Skip to content

Commit c1a66e1

Browse files
fix: unreachable err on Fn with None block
1 parent 537d746 commit c1a66e1

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

src/visitor.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
514514
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => {
515515
self.visit_static(&StaticParts::from_item(item));
516516
}
517-
ast::ItemKind::Fn(defaultness, ref fn_signature, ref generics, ref body) => {
517+
ast::ItemKind::Fn(defaultness, ref fn_signature, ref generics, Some(ref body)) => {
518518
let inner_attrs = inner_attributes(&item.attrs);
519519
let fn_ctxt = match fn_signature.header.ext {
520520
ast::Extern::None => visit::FnCtxt::Free,
@@ -526,7 +526,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
526526
item.ident,
527527
&fn_signature,
528528
&item.vis,
529-
body.as_deref(),
529+
Some(body),
530530
),
531531
generics,
532532
&fn_signature.decl,
@@ -535,6 +535,18 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
535535
Some(&inner_attrs),
536536
)
537537
}
538+
ast::ItemKind::Fn(_, ref fn_signature, ref generics, None) => {
539+
let indent = self.block_indent;
540+
let rewrite = self.rewrite_required_fn(
541+
indent,
542+
item.ident,
543+
&fn_signature,
544+
generics,
545+
item.span,
546+
);
547+
548+
self.push_rewrite(item.span, rewrite);
549+
}
538550
ast::ItemKind::TyAlias(_, ref generics, ref generic_bounds, ref ty) => match ty {
539551
Some(ty) => {
540552
let rewrite = rewrite_type_alias(

tests/source/issue_4057.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-format_code_in_doc_comments: true
2+
3+
/// ```
4+
/// # #[rustversion::since(1.36)]
5+
/// # fn dox() {
6+
/// # use std::pin::Pin;
7+
/// # type Projection<'a> = &'a ();
8+
/// # type ProjectionRef<'a> = &'a ();
9+
/// # trait Dox {
10+
/// fn project_ex (self: Pin<&mut Self>) -> Projection<'_>;
11+
/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>;
12+
/// # }
13+
/// # }
14+
/// ```
15+
struct Foo;

tests/target/issue-4068.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
extern "C" fn packet_records_options_impl_layout_length_encoding_option_len_multiplier();
3+
}

tests/target/issue_4057.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-format_code_in_doc_comments: true
2+
3+
/// ```
4+
/// # #[rustversion::since(1.36)]
5+
/// # fn dox() {
6+
/// # use std::pin::Pin;
7+
/// # type Projection<'a> = &'a ();
8+
/// # type ProjectionRef<'a> = &'a ();
9+
/// # trait Dox {
10+
/// fn project_ex(self: Pin<&mut Self>) -> Projection<'_>;
11+
/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>;
12+
/// # }
13+
/// # }
14+
/// ```
15+
struct Foo;

0 commit comments

Comments
 (0)