Skip to content

Commit a6daccc

Browse files
authored
Merge pull request #3523 from topecongiro/issue-3515
Attempt to format attributes if only they exist
2 parents aeb556e + ec0d263 commit a6daccc

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ matrix:
1919
- env: CFG_RELEASE_CHANNEL=beta
2020
- os: osx
2121
- env: INTEGRATION=bitflags
22-
- env: INTEGRATION=cargo
2322
- env: INTEGRATION=chalk
2423
- env: INTEGRATION=crater
2524
- env: INTEGRATION=error-chain
@@ -41,6 +40,8 @@ matrix:
4140
- env: INTEGRATION=rust-semverver
4241
# can be moved back to include section after https://github.com/rust-lang-nursery/failure/pull/298 is merged
4342
- env: INTEGRATION=failure
43+
# `cargo test` doesn't finish - disabling for now.
44+
# - env: INTEGRATION=cargo
4445

4546
script:
4647
- |

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

tests/source/issue-3515.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// rustfmt-reorder_imports: false
2+
3+
use std :: fmt :: { self , Display } ;
4+
use std :: collections :: HashMap ;
5+
6+
fn main() {}

tests/target/issue-3515.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// rustfmt-reorder_imports: false
2+
3+
use std::fmt::{self, Display};
4+
use std::collections::HashMap;
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// rustfmt-reorder_imports: false
22

3-
pub use self :: super :: super :: super :: root::mozilla::detail::StringClassFlags as nsTStringRepr_ClassFlags ;
3+
pub use self::super::super::super::root::mozilla::detail::StringClassFlags as nsTStringRepr_ClassFlags;

0 commit comments

Comments
 (0)