Skip to content

Commit 0e862d8

Browse files
committed
apply inline_attribute_width for extern crate
1 parent a00ec7e commit 0e862d8

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

src/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::source_map::{self, BytePos, Span, DUMMY_SP};
77

88
use crate::comment::combine_strs_with_missing_comments;
99
use crate::config::lists::*;
10-
use crate::config::{Edition, IndentStyle, Version};
10+
use crate::config::{Edition, IndentStyle};
1111
use crate::lists::{
1212
definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
1313
};
@@ -250,7 +250,7 @@ impl UseTree {
250250
let hi = self.span.lo();
251251
let span = mk_sp(lo, hi);
252252

253-
let allow_extend = if context.config.version() == Version::Two {
253+
let allow_extend = if attrs.len() == 1 {
254254
let line_len = attr_str.len() + 1 + use_str.len();
255255
!attrs.first().unwrap().is_sugared_doc
256256
&& context.config.inline_attribute_width() >= line_len

src/reorder.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,22 @@ fn rewrite_reorderable_item(
8383
_ => return None,
8484
};
8585

86-
combine_strs_with_missing_comments(context, &attrs_str, &item_str, missed_span, shape, false)
86+
let allow_extend = if attrs.len() == 1 {
87+
let line_len = attrs_str.len() + 1 + item_str.len();
88+
!attrs.first().unwrap().is_sugared_doc
89+
&& context.config.inline_attribute_width() >= line_len
90+
} else {
91+
false
92+
};
93+
94+
combine_strs_with_missing_comments(
95+
context,
96+
&attrs_str,
97+
&item_str,
98+
missed_span,
99+
shape,
100+
allow_extend,
101+
)
87102
}
88103

89104
/// Rewrite a list of items with reordering. Every item in `items` must have

tests/source/issue-3343/two.rs renamed to tests/source/issue-3343.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// rustfmt-version: Two
21
// rustfmt-config: inline_attribute_width.toml
32

43
#[cfg(feature = "alloc")]
@@ -10,5 +9,15 @@ use total_len_is::_50__;
109
#[cfg(feature = "alloc")]
1110
use total_len_is::_51___;
1211

12+
#[cfg(feature = "alloc")]
13+
extern crate len_is_50_;
14+
15+
#[cfg(feature = "alloc")]
16+
extern crate len_is_51__;
17+
1318
/// this is a comment to test is_sugared_doc property
1419
use core::convert;
20+
21+
#[foooooo]
22+
#[barrrrrrr]
23+
use line2_plus_line_3_is_::_50______;

tests/target/issue-3343/two.rs renamed to tests/target/issue-3343.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// rustfmt-version: Two
21
// rustfmt-config: inline_attribute_width.toml
32

43
#[cfg(feature = "alloc")] use core::slice;
@@ -8,5 +7,14 @@
87
#[cfg(feature = "alloc")]
98
use total_len_is::_51___;
109

10+
#[cfg(feature = "alloc")] extern crate len_is_50_;
11+
12+
#[cfg(feature = "alloc")]
13+
extern crate len_is_51__;
14+
1115
/// this is a comment to test is_sugared_doc property
1216
use core::convert;
17+
18+
#[foooooo]
19+
#[barrrrrrr]
20+
use line2_plus_line_3_is_::_50______;

tests/target/issue-3343/one.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)