mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-29 12:36:35 +03:00
Attempt to format attributes if only they exist
This commit is contained in:
+23
-22
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user