-
Notifications
You must be signed in to change notification settings - Fork 888
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
suppress internal error #4069
Conversation
@@ -364,7 +364,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { | |||
mk_sp(s.lo(), b.span.lo()), | |||
) | |||
} | |||
_ => unreachable!(), | |||
_ => return, |
There was a problem hiding this comment.
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.
_ => 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 😬
rustfmt/rustfmt-core/rustfmt-lib/src/visitor.rs
Lines 505 to 525 in 9124dd8
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);
}
There was a problem hiding this comment.
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.
Thank you! |
related: #4068
I think #4068 code is invalid, but rustfmt should not cause an internal error. So I send this PR.