Skip to content

Commit af3e940

Browse files
committed
Attempt to format attributes if only they exist
1 parent 8d43ca2 commit af3e940

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

Diff for: src/imports.rs

+24-23
Original file line numberDiff line numberDiff line change
@@ -242,30 +242,31 @@ impl UseTree {
242242
format!("{}use {};", vis, s)
243243
}
244244
})?;
245-
if let Some(ref attrs) = self.attrs {
246-
let attr_str = attrs.rewrite(context, shape)?;
247-
let lo = attrs.last().as_ref()?.span().hi();
248-
let hi = self.span.lo();
249-
let span = mk_sp(lo, hi);
250-
251-
let allow_extend = if attrs.len() == 1 {
252-
let line_len = attr_str.len() + 1 + use_str.len();
253-
!attrs.first().unwrap().is_sugared_doc
254-
&& context.config.inline_attribute_width() >= line_len
255-
} else {
256-
false
257-
};
245+
match self.attrs {
246+
Some(ref attrs) if !attrs.is_empty() => {
247+
let attr_str = attrs.rewrite(context, shape)?;
248+
let lo = attrs.last().as_ref()?.span().hi();
249+
let hi = self.span.lo();
250+
let span = mk_sp(lo, hi);
251+
252+
let allow_extend = if attrs.len() == 1 {
253+
let line_len = attr_str.len() + 1 + use_str.len();
254+
!attrs.first().unwrap().is_sugared_doc
255+
&& context.config.inline_attribute_width() >= line_len
256+
} else {
257+
false
258+
};
258259

259-
combine_strs_with_missing_comments(
260-
context,
261-
&attr_str,
262-
&use_str,
263-
span,
264-
shape,
265-
allow_extend,
266-
)
267-
} else {
268-
Some(use_str)
260+
combine_strs_with_missing_comments(
261+
context,
262+
&attr_str,
263+
&use_str,
264+
span,
265+
shape,
266+
allow_extend,
267+
)
268+
}
269+
_ => Some(use_str),
269270
}
270271
}
271272

0 commit comments

Comments
 (0)