diff --git a/src/imports.rs b/src/imports.rs index f6b41deaef95..08647dee490b 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -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), } }