Merge pull request #3523 from topecongiro/issue-3515

Attempt to format attributes if only they exist
This commit is contained in:
Seiichi Uchida 2019-04-24 07:22:55 -07:00 committed by GitHub
commit a6daccc229
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 24 deletions

View file

@ -19,7 +19,6 @@ matrix:
- env: CFG_RELEASE_CHANNEL=beta
- os: osx
- env: INTEGRATION=bitflags
- env: INTEGRATION=cargo
- env: INTEGRATION=chalk
- env: INTEGRATION=crater
- env: INTEGRATION=error-chain
@ -41,6 +40,8 @@ matrix:
- env: INTEGRATION=rust-semverver
# can be moved back to include section after https://github.com/rust-lang-nursery/failure/pull/298 is merged
- env: INTEGRATION=failure
# `cargo test` doesn't finish - disabling for now.
# - env: INTEGRATION=cargo
script:
- |

View file

@ -242,30 +242,31 @@ impl UseTree {
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),
}
}

View file

@ -0,0 +1,6 @@
// rustfmt-reorder_imports: false
use std :: fmt :: { self , Display } ;
use std :: collections :: HashMap ;
fn main() {}

View file

@ -0,0 +1,6 @@
// rustfmt-reorder_imports: false
use std::fmt::{self, Display};
use std::collections::HashMap;
fn main() {}

View file

@ -1,3 +1,3 @@
// rustfmt-reorder_imports: false
pub use self :: super :: super :: super :: root::mozilla::detail::StringClassFlags as nsTStringRepr_ClassFlags ;
pub use self::super::super::super::root::mozilla::detail::StringClassFlags as nsTStringRepr_ClassFlags;