fix: unreachable err on Fn with None block

This commit is contained in:
Caleb Cartwright 2020-03-27 22:13:46 -05:00
parent 537d746e08
commit c1a66e1e22
4 changed files with 47 additions and 2 deletions

View File

@ -514,7 +514,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => {
self.visit_static(&StaticParts::from_item(item));
}
ast::ItemKind::Fn(defaultness, ref fn_signature, ref generics, ref body) => {
ast::ItemKind::Fn(defaultness, 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,
@ -526,7 +526,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
item.ident,
&fn_signature,
&item.vis,
body.as_deref(),
Some(body),
),
generics,
&fn_signature.decl,
@ -535,6 +535,18 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
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);
}
ast::ItemKind::TyAlias(_, ref generics, ref generic_bounds, ref ty) => match ty {
Some(ty) => {
let rewrite = rewrite_type_alias(

View File

@ -0,0 +1,15 @@
// rustfmt-format_code_in_doc_comments: true
/// ```
/// # #[rustversion::since(1.36)]
/// # fn dox() {
/// # use std::pin::Pin;
/// # type Projection<'a> = &'a ();
/// # type ProjectionRef<'a> = &'a ();
/// # trait Dox {
/// fn project_ex (self: Pin<&mut Self>) -> Projection<'_>;
/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>;
/// # }
/// # }
/// ```
struct Foo;

View File

@ -0,0 +1,3 @@
fn main() {
extern "C" fn packet_records_options_impl_layout_length_encoding_option_len_multiplier();
}

View File

@ -0,0 +1,15 @@
// rustfmt-format_code_in_doc_comments: true
/// ```
/// # #[rustversion::since(1.36)]
/// # fn dox() {
/// # use std::pin::Pin;
/// # type Projection<'a> = &'a ();
/// # type ProjectionRef<'a> = &'a ();
/// # trait Dox {
/// fn project_ex(self: Pin<&mut Self>) -> Projection<'_>;
/// fn project_ref(self: Pin<&Self>) -> ProjectionRef<'_>;
/// # }
/// # }
/// ```
struct Foo;