Skip to content

Commit

Permalink
Allow the second item to stay on the same line as the first more often.
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Apr 22, 2016
1 parent 19fa5c9 commit be9ade2
Show file tree
Hide file tree
Showing 14 changed files with 19 additions and 38 deletions.
3 changes: 1 addition & 2 deletions src/bin/cargo-fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ fn format_files(files: &Vec<PathBuf>,
}
println!("");
}
let mut command = try!(Command::new("rustfmt")
.stdout(stdout)
let mut command = try!(Command::new("rustfmt").stdout(stdout)
.args(files)
.args(fmt_args)
.spawn());
Expand Down
6 changes: 2 additions & 4 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ use config::BlockIndentStyle;
use syntax::{ast, ptr};
use syntax::codemap::{mk_sp, Span};


pub fn rewrite_chain(expr: &ast::Expr,
context: &RewriteContext,
width: usize,
Expand All @@ -118,7 +117,7 @@ pub fn rewrite_chain(expr: &ast::Expr,
} else if parent_rewrite.contains('\n') {
(chain_indent(context, parent_block_indent.block_indent(context.config)), false)
} else {
(chain_indent_newline(context, offset + Indent::new(0, parent_rewrite.len())), false)
(chain_indent_newline(context, offset + Indent::new(0, parent_rewrite.len())), true)
};

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

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

Expand Down
3 changes: 1 addition & 2 deletions src/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ mod test {
// This is probably intended to be a non-test fn, but it is not used. I'm
// keeping it around unless it helps us test stuff.
fn uncommented(text: &str) -> String {
CharClasses::new(text.chars())
.filter_map(|(s, c)| {
CharClasses::new(text.chars()).filter_map(|(s, c)| {
match s {
FullCodeCharKind::Normal => Some(c),
_ => None,
Expand Down
6 changes: 2 additions & 4 deletions src/issues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ fn issue_type() {
});

assert_eq!(expected,
"TODO(#100): more awesomeness"
.chars()
"TODO(#100): more awesomeness".chars()
.map(|c| seeker.inspect(c))
.find(Option::is_some)
.unwrap());
Expand All @@ -296,8 +295,7 @@ fn issue_type() {
});

assert_eq!(expected,
"Test. FIXME: bad, bad, not good"
.chars()
"Test. FIXME: bad, bad, not good".chars()
.map(|c| seeker.inspect(c))
.find(Option::is_some)
.unwrap());
Expand Down
3 changes: 1 addition & 2 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1523,8 +1523,7 @@ fn rewrite_args(context: &RewriteContext,
};

let more_items = itemize_list(context.codemap,
args[min_args - 1..]
.iter()
args[min_args - 1..].iter()
.map(ArgumentKind::Regular)
.chain(variadic_arg),
")",
Expand Down
3 changes: 1 addition & 2 deletions src/missed_spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ impl<'a> FmtVisitor<'a> {

for (kind, offset, subslice) in CommentCodeSlices::new(snippet) {
if let CodeCharKind::Comment = kind {
let last_char = big_snippet[..(offset + big_diff)]
.chars()
let last_char = big_snippet[..(offset + big_diff)].chars()
.rev()
.skip_while(|rev_c| [' ', '\t'].contains(&rev_c))
.next();
Expand Down
9 changes: 3 additions & 6 deletions tests/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ fn assert_output(source: &str, expected_filename: &str) {
#[test]
fn idempotence_tests() {
// Get all files in the tests/target directory.
let files = fs::read_dir("tests/target")
.expect("Couldn't read target dir")
let files = fs::read_dir("tests/target").expect("Couldn't read target dir")
.map(get_path_string);
let (_reports, count, fails) = check_files(files);

Expand All @@ -115,8 +114,7 @@ fn idempotence_tests() {
// no warnings are emitted.
#[test]
fn self_tests() {
let files = fs::read_dir("src/bin")
.expect("Couldn't read src dir")
let files = fs::read_dir("src/bin").expect("Couldn't read src dir")
.chain(fs::read_dir("tests").expect("Couldn't read tests dir"))
.map(get_path_string);
// Hack because there's no `IntoIterator` impl for `[T; N]`.
Expand Down Expand Up @@ -313,8 +311,7 @@ fn get_target(file_name: &str, target: Option<&str>) -> String {
if file_name.contains("source") {
let target_file_name = file_name.replace("source", "target");
if let Some(replace_name) = target {
Path::new(&target_file_name)
.with_file_name(replace_name)
Path::new(&target_file_name).with_file_name(replace_name)
.into_os_string()
.into_string()
.unwrap()
Expand Down
3 changes: 1 addition & 2 deletions tests/target/chains-indent-inherit.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// rustfmt-chain_indent: Inherit

fn test() {
let x = my_long_function()
.my_even_longer_function()
let x = my_long_function().my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
Expand Down
3 changes: 1 addition & 2 deletions tests/target/chains-indent-tabbed.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// rustfmt-chain_indent: Tabbed

fn test() {
let x = my_long_function()
.my_even_longer_function()
let x = my_long_function().my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
Expand Down
3 changes: 1 addition & 2 deletions tests/target/chains-indent-visual.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// rustfmt-chain_indent: Visual

fn test() {
let x = my_long_function()
.my_even_longer_function()
let x = my_long_function().my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
Expand Down
3 changes: 1 addition & 2 deletions tests/target/chains-no-overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ fn main() {
false => (),
});

loong_func()
.quux(move || if true {
loong_func().quux(move || if true {
1
} else {
2
Expand Down
6 changes: 2 additions & 4 deletions tests/target/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ fn main() {
x
});

some_fuuuuuuuuunction()
.method_call_a(aaaaa, bbbbb, |c| {
some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
let x = c;
x
})
Expand Down Expand Up @@ -100,8 +99,7 @@ fn floaters() {
.bar()
.baz();

Foo { x: val }
.baz(|| {
Foo { x: val }.baz(|| {
// force multiline
})
.quux();
Expand Down
3 changes: 1 addition & 2 deletions tests/target/comment-not-disappear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ fn c() {
}

fn foo() -> Vec<i32> {
(0..11)
.map(|x|
(0..11).map(|x|
// This comment disappears.
if x % 2 == 0 { x } else { x * 2 })
.collect()
Expand Down
3 changes: 1 addition & 2 deletions tests/target/hard-tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ fn main() {
* Will it still format correctly? */ {
}

let chain = funktion_kall()
.go_to_next_line_with_tab()
let chain = funktion_kall().go_to_next_line_with_tab()
.go_to_next_line_with_tab()
.go_to_next_line_with_tab();

Expand Down

0 comments on commit be9ade2

Please sign in to comment.