Attempt to format attributes if only they exist

This commit is contained in:
topecongiro
2019-04-23 08:50:59 +09:00
parent 8d43ca297a
commit af3e940940
+23 -22
View File
@@ -242,30 +242,31 @@ pub fn rewrite_top_level(&self, context: &RewriteContext<'_>, shape: Shape) -> O
format!("{}use {};", vis, s)
}
})?;
if let Some(ref attrs) = self.attrs {
let attr_str = attrs.rewrite(context, shape)?;
let lo = attrs.last().as_ref()?.span().hi();
let hi = self.span.lo();
let span = mk_sp(lo, hi);
match self.attrs {
Some(ref attrs) if !attrs.is_empty() => {
let attr_str = attrs.rewrite(context, shape)?;
let lo = attrs.last().as_ref()?.span().hi();
let hi = self.span.lo();
let span = mk_sp(lo, hi);
let allow_extend = if attrs.len() == 1 {
let line_len = attr_str.len() + 1 + use_str.len();
!attrs.first().unwrap().is_sugared_doc
&& context.config.inline_attribute_width() >= line_len
} else {
false
};
let allow_extend = if attrs.len() == 1 {
let line_len = attr_str.len() + 1 + use_str.len();
!attrs.first().unwrap().is_sugared_doc
&& context.config.inline_attribute_width() >= line_len
} else {
false
};
combine_strs_with_missing_comments(
context,
&attr_str,
&use_str,
span,
shape,
allow_extend,
)
} else {
Some(use_str)
combine_strs_with_missing_comments(
context,
&attr_str,
&use_str,
span,
shape,
allow_extend,
)
}
_ => Some(use_str),
}
}