Skip to content

Commit be9ade2

Browse files
author
Nick Cameron
committed
Allow the second item to stay on the same line as the first more often.
1 parent 19fa5c9 commit be9ade2

14 files changed

+19
-38
lines changed

src/bin/cargo-fmt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ fn format_files(files: &Vec<PathBuf>,
200200
}
201201
println!("");
202202
}
203-
let mut command = try!(Command::new("rustfmt")
204-
.stdout(stdout)
203+
let mut command = try!(Command::new("rustfmt").stdout(stdout)
205204
.args(files)
206205
.args(fmt_args)
207206
.spawn());

src/chains.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ use config::BlockIndentStyle;
9191
use syntax::{ast, ptr};
9292
use syntax::codemap::{mk_sp, Span};
9393

94-
9594
pub fn rewrite_chain(expr: &ast::Expr,
9695
context: &RewriteContext,
9796
width: usize,
@@ -118,7 +117,7 @@ pub fn rewrite_chain(expr: &ast::Expr,
118117
} else if parent_rewrite.contains('\n') {
119118
(chain_indent(context, parent_block_indent.block_indent(context.config)), false)
120119
} else {
121-
(chain_indent_newline(context, offset + Indent::new(0, parent_rewrite.len())), false)
120+
(chain_indent_newline(context, offset + Indent::new(0, parent_rewrite.len())), true)
122121
};
123122

124123
let max_width = try_opt!((width + offset.width()).checked_sub(indent.width()));
@@ -128,8 +127,7 @@ pub fn rewrite_chain(expr: &ast::Expr,
128127
.collect::<Option<Vec<_>>>());
129128

130129
// Total of all items excluding the last.
131-
let almost_total = rewrites[..rewrites.len() - 1]
132-
.iter()
130+
let almost_total = rewrites[..rewrites.len() - 1].iter()
133131
.fold(0, |a, b| a + first_line_width(b)) + parent_rewrite.len();
134132
let total_width = almost_total + first_line_width(rewrites.last().unwrap());
135133

src/comment.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,7 @@ mod test {
707707
// This is probably intended to be a non-test fn, but it is not used. I'm
708708
// keeping it around unless it helps us test stuff.
709709
fn uncommented(text: &str) -> String {
710-
CharClasses::new(text.chars())
711-
.filter_map(|(s, c)| {
710+
CharClasses::new(text.chars()).filter_map(|(s, c)| {
712711
match s {
713712
FullCodeCharKind::Normal => Some(c),
714713
_ => None,

src/issues.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ fn issue_type() {
283283
});
284284

285285
assert_eq!(expected,
286-
"TODO(#100): more awesomeness"
287-
.chars()
286+
"TODO(#100): more awesomeness".chars()
288287
.map(|c| seeker.inspect(c))
289288
.find(Option::is_some)
290289
.unwrap());
@@ -296,8 +295,7 @@ fn issue_type() {
296295
});
297296

298297
assert_eq!(expected,
299-
"Test. FIXME: bad, bad, not good"
300-
.chars()
298+
"Test. FIXME: bad, bad, not good".chars()
301299
.map(|c| seeker.inspect(c))
302300
.find(Option::is_some)
303301
.unwrap());

src/items.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,8 +1523,7 @@ fn rewrite_args(context: &RewriteContext,
15231523
};
15241524

15251525
let more_items = itemize_list(context.codemap,
1526-
args[min_args - 1..]
1527-
.iter()
1526+
args[min_args - 1..].iter()
15281527
.map(ArgumentKind::Regular)
15291528
.chain(variadic_arg),
15301529
")",

src/missed_spans.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ impl<'a> FmtVisitor<'a> {
111111

112112
for (kind, offset, subslice) in CommentCodeSlices::new(snippet) {
113113
if let CodeCharKind::Comment = kind {
114-
let last_char = big_snippet[..(offset + big_diff)]
115-
.chars()
114+
let last_char = big_snippet[..(offset + big_diff)].chars()
116115
.rev()
117116
.skip_while(|rev_c| [' ', '\t'].contains(&rev_c))
118117
.next();

tests/system.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ fn assert_output(source: &str, expected_filename: &str) {
101101
#[test]
102102
fn idempotence_tests() {
103103
// Get all files in the tests/target directory.
104-
let files = fs::read_dir("tests/target")
105-
.expect("Couldn't read target dir")
104+
let files = fs::read_dir("tests/target").expect("Couldn't read target dir")
106105
.map(get_path_string);
107106
let (_reports, count, fails) = check_files(files);
108107

@@ -115,8 +114,7 @@ fn idempotence_tests() {
115114
// no warnings are emitted.
116115
#[test]
117116
fn self_tests() {
118-
let files = fs::read_dir("src/bin")
119-
.expect("Couldn't read src dir")
117+
let files = fs::read_dir("src/bin").expect("Couldn't read src dir")
120118
.chain(fs::read_dir("tests").expect("Couldn't read tests dir"))
121119
.map(get_path_string);
122120
// Hack because there's no `IntoIterator` impl for `[T; N]`.
@@ -313,8 +311,7 @@ fn get_target(file_name: &str, target: Option<&str>) -> String {
313311
if file_name.contains("source") {
314312
let target_file_name = file_name.replace("source", "target");
315313
if let Some(replace_name) = target {
316-
Path::new(&target_file_name)
317-
.with_file_name(replace_name)
314+
Path::new(&target_file_name).with_file_name(replace_name)
318315
.into_os_string()
319316
.into_string()
320317
.unwrap()

tests/target/chains-indent-inherit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// rustfmt-chain_indent: Inherit
22

33
fn test() {
4-
let x = my_long_function()
5-
.my_even_longer_function()
4+
let x = my_long_function().my_even_longer_function()
65
.my_nested_function()
76
.some_random_name()
87
.another_function()

tests/target/chains-indent-tabbed.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// rustfmt-chain_indent: Tabbed
22

33
fn test() {
4-
let x = my_long_function()
5-
.my_even_longer_function()
4+
let x = my_long_function().my_even_longer_function()
65
.my_nested_function()
76
.some_random_name()
87
.another_function()

tests/target/chains-indent-visual.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// rustfmt-chain_indent: Visual
22

33
fn test() {
4-
let x = my_long_function()
5-
.my_even_longer_function()
4+
let x = my_long_function().my_even_longer_function()
65
.my_nested_function()
76
.some_random_name()
87
.another_function()

0 commit comments

Comments
 (0)