Skip to content

Commit

Permalink
Properly format function signature in extern blocks
Browse files Browse the repository at this point in the history
Closes #4288

And we get to drop a method, which I think is a win :)
  • Loading branch information
ayazhafiz authored and calebcartwright committed Nov 29, 2020
1 parent 8e46225 commit 5ffccbb
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions src/items.rs
Expand Up @@ -125,6 +125,7 @@ impl Rewrite for ast::Local {
// FIXME convert to using rewrite style rather than visitor
// FIXME format modules in this style
#[allow(dead_code)]
#[derive(Debug)]
struct Item<'a> {
unsafety: ast::Unsafe,
abi: Cow<'static, str>,
Expand Down Expand Up @@ -153,6 +154,7 @@ impl<'a> Item<'a> {
}
}

#[derive(Debug)]
enum BodyElement<'a> {
// Stmt(&'a ast::Stmt),
// Field(&'a ast::Field),
Expand All @@ -174,26 +176,10 @@ pub(crate) struct FnSig<'a> {
}

impl<'a> FnSig<'a> {
pub(crate) fn new(
decl: &'a ast::FnDecl,
generics: &'a ast::Generics,
vis: ast::Visibility,
) -> FnSig<'a> {
FnSig {
decl,
generics,
ext: ast::Extern::None,
is_async: Cow::Owned(ast::Async::No),
constness: ast::Const::No,
defaultness: ast::Defaultness::Final,
unsafety: ast::Unsafe::No,
visibility: vis,
}
}

pub(crate) fn from_method_sig(
method_sig: &'a ast::FnSig,
generics: &'a ast::Generics,
visibility: ast::Visibility,
) -> FnSig<'a> {
FnSig {
unsafety: method_sig.header.unsafety,
Expand All @@ -203,7 +189,7 @@ impl<'a> FnSig<'a> {
ext: method_sig.header.ext,
decl: &*method_sig.decl,
generics,
visibility: DEFAULT_VISIBILITY,
visibility,
}
}

Expand All @@ -216,9 +202,8 @@ impl<'a> FnSig<'a> {
match *fn_kind {
visit::FnKind::Fn(fn_ctxt, _, fn_sig, vis, _) => match fn_ctxt {
visit::FnCtxt::Assoc(..) => {
let mut fn_sig = FnSig::from_method_sig(fn_sig, generics);
let mut fn_sig = FnSig::from_method_sig(fn_sig, generics, vis.clone());
fn_sig.defaultness = defaultness;
fn_sig.visibility = vis.clone();
fn_sig
}
_ => FnSig {
Expand Down Expand Up @@ -347,7 +332,7 @@ impl<'a> FmtVisitor<'a> {
&context,
indent,
ident,
&FnSig::from_method_sig(sig, generics),
&FnSig::from_method_sig(sig, generics, DEFAULT_VISIBILITY),
span,
FnBraceStyle::None,
)?;
Expand Down Expand Up @@ -3062,7 +3047,7 @@ impl Rewrite for ast::ForeignItem {
context,
shape.indent,
self.ident,
&FnSig::new(&fn_sig.decl, generics, self.vis.clone()),
&FnSig::from_method_sig(&fn_sig, generics, self.vis.clone()),
span,
FnBraceStyle::None,
)
Expand Down

0 comments on commit 5ffccbb

Please sign in to comment.