From: topecongiro Date: Wed, 5 Jul 2017 09:31:37 +0000 (+0900) Subject: Format source codes X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=cb48435ff372d6b7970b16b53a1e5a6d446fe7b5;p=rust.git Format source codes --- diff --git a/src/chains.rs b/src/chains.rs index fb26fb2ff7d..e4ad0d82fd4 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -186,8 +186,8 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) - let almost_total = rewrites[..last_non_try_index] .iter() .fold(0, |a, b| a + first_line_width(b)) + parent_rewrite.len(); - let one_line_len = rewrites.iter().fold(0, |a, r| a + first_line_width(r)) + - parent_rewrite.len(); + let one_line_len = + rewrites.iter().fold(0, |a, r| a + first_line_width(r)) + parent_rewrite.len(); let one_line_budget = min(shape.width, context.config.chain_one_line_max()); let veto_single_line = if one_line_len > one_line_budget { diff --git a/src/expr.rs b/src/expr.rs index 90694226113..1647cf5e357 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -954,8 +954,8 @@ fn rewrite_cond(context: &RewriteContext, expr: &ast::Expr, shape: Shape) -> Opt } _ => { to_control_flow(expr, ExprType::SubExpression).and_then(|control_flow| { - let alt_block_sep = String::from("\n") + - &shape.indent.block_only().to_string(context.config); + let alt_block_sep = + String::from("\n") + &shape.indent.block_only().to_string(context.config); control_flow .rewrite_cond(context, shape, &alt_block_sep) .and_then(|rw| Some(rw.0)) @@ -1299,8 +1299,8 @@ impl<'a> Rewrite for ControlFlow<'a> { fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { debug!("ControlFlow::rewrite {:?} {:?}", self, shape); - let alt_block_sep = String::from("\n") + - &shape.indent.block_only().to_string(context.config); + let alt_block_sep = + String::from("\n") + &shape.indent.block_only().to_string(context.config); let (cond_str, used_width) = try_opt!(self.rewrite_cond(context, shape, &alt_block_sep)); // If `used_width` is 0, it indicates that whole control flow is written in a single line. if used_width == 0 { @@ -1723,8 +1723,8 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { extend &= context.use_block_indent(); let comma = arm_comma(&context.config, body); - let alt_block_sep = String::from("\n") + - &shape.indent.block_only().to_string(context.config); + let alt_block_sep = + String::from("\n") + &shape.indent.block_only().to_string(context.config); let pat_width = extra_offset(&pats_str, shape); // Let's try and get the arm body on the same line as the condition. diff --git a/src/items.rs b/src/items.rs index bbe5438a01f..42526fc9b13 100644 --- a/src/items.rs +++ b/src/items.rs @@ -1952,8 +1952,8 @@ fn rewrite_fn_base( generics_str.contains('\n'), )); - let multi_line_arg_str = arg_str.contains('\n') || - arg_str.chars().last().map_or(false, |c| c == ','); + let multi_line_arg_str = + arg_str.contains('\n') || arg_str.chars().last().map_or(false, |c| c == ','); let put_args_in_block = match context.config.fn_args_layout() { IndentStyle::Block => multi_line_arg_str || generics_str.contains('\n'), @@ -2339,8 +2339,8 @@ fn compute_budgets_for_args( if one_line_budget > 0 { // 4 = "() {".len() - let multi_line_overhead = indent.width() + result.len() + - if newline_brace { 2 } else { 4 }; + let multi_line_overhead = + indent.width() + result.len() + if newline_brace { 2 } else { 4 }; let multi_line_budget = try_opt!(context.config.max_width().checked_sub(multi_line_overhead)); diff --git a/src/lists.rs b/src/lists.rs index d6cb00b55cd..63e9e360ade 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -353,8 +353,8 @@ fn next(&mut self) -> Option { .span_to_snippet(mk_sp(self.prev_span_end, (self.get_lo)(&item))) .unwrap(); let trimmed_pre_snippet = pre_snippet.trim(); - let has_pre_comment = trimmed_pre_snippet.contains("//") || - trimmed_pre_snippet.contains("/*"); + let has_pre_comment = + trimmed_pre_snippet.contains("//") || trimmed_pre_snippet.contains("/*"); let pre_comment = if has_pre_comment { Some(trimmed_pre_snippet.to_owned()) } else { diff --git a/src/modules.rs b/src/modules.rs index 5b5050d51c9..c8275520ca1 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -47,8 +47,8 @@ fn list_submodules<'a>( for item in &module.items { if let ast::ItemKind::Mod(ref sub_mod) = item.node { if !utils::contains_skip(&item.attrs) { - let is_internal = codemap.span_to_filename(item.span) == - codemap.span_to_filename(sub_mod.inner); + let is_internal = + codemap.span_to_filename(item.span) == codemap.span_to_filename(sub_mod.inner); let dir_path = if is_internal { search_dir.join(&item.ident.to_string()) } else { diff --git a/tests/source/static.rs b/tests/source/static.rs index a571b5f11f6..b51c56d1205 100644 --- a/tests/source/static.rs +++ b/tests/source/static.rs @@ -16,3 +16,6 @@ impl Color { pub const WHITE: u32 = 10; } + +// #1391 +pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS = 0 as usize; diff --git a/tests/system.rs b/tests/system.rs index 26b1edaff5b..b43bb081921 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -147,8 +147,8 @@ fn self_tests() { fn stdin_formatting_smoke_test() { let input = Input::Text("fn main () {}".to_owned()); let config = Config::default(); - let (error_summary, file_map, _report) = format_input::(input, &config, None) - .unwrap(); + let (error_summary, file_map, _report) = + format_input::(input, &config, None).unwrap(); assert!(error_summary.has_no_errors()); for &(ref file_name, ref text) in &file_map { if file_name == "stdin" { @@ -164,8 +164,8 @@ fn format_lines_errors_are_reported() { let long_identifier = String::from_utf8(vec![b'a'; 239]).unwrap(); let input = Input::Text(format!("fn {}() {{}}", long_identifier)); let config = Config::default(); - let (error_summary, _file_map, _report) = format_input::(input, &config, None) - .unwrap(); + let (error_summary, _file_map, _report) = + format_input::(input, &config, None).unwrap(); assert!(error_summary.has_formatting_errors()); } @@ -242,8 +242,8 @@ fn read_config(filename: &str) -> Config { fn format_file>(filename: P, config: &Config) -> (FileMap, FormatReport) { let input = Input::File(filename.into()); - let (_error_summary, file_map, report) = format_input::(input, &config, None) - .unwrap(); + let (_error_summary, file_map, report) = + format_input::(input, &config, None).unwrap(); return (file_map, report); } diff --git a/tests/target/expr.rs b/tests/target/expr.rs index de4391d4056..4d75239f357 100644 --- a/tests/target/expr.rs +++ b/tests/target/expr.rs @@ -7,11 +7,11 @@ fn foo() -> bool { let referenced = &5; let very_long_variable_name = (a + first + simple + test); - let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA + - BBBBBBBBBBBBBBBBB + b + c); + let very_long_variable_name = + (a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c); - let is_internalxxxx = self.codemap.span_to_filename(s) == - self.codemap.span_to_filename(m.inner); + let is_internalxxxx = + self.codemap.span_to_filename(s) == self.codemap.span_to_filename(m.inner); let some_val = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa * bbbb / (bbbbbb - function_call(x, *very_long_pointer, y)) + 1000; @@ -84,8 +84,8 @@ fn foo() -> bool { } fn bar() { - let range = (111111111 + 333333333333333333 + 1111 + 400000000000000000).. - (2222 + 2333333333333333); + let range = + (111111111 + 333333333333333333 + 1111 + 400000000000000000)..(2222 + 2333333333333333); let another_range = 5..some_func(a, b /* comment */); @@ -274,8 +274,8 @@ fn casts() { } let some_trait_xxx = xxxxxxxxxxx + xxxxxxxxxxxxx as SomeTraitXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX; - let slightly_longer_trait = yyyyyyyyy + - yyyyyyyyyyy as SomeTraitYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY; + let slightly_longer_trait = + yyyyyyyyy + yyyyyyyyyyy as SomeTraitYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY; } fn indices() { @@ -311,8 +311,8 @@ fn issue767() { fn ranges() { let x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; - let y = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... - bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + let y = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; let z = ...x; // #1766 diff --git a/tests/target/long_field_access.rs b/tests/target/long_field_access.rs index e4efd86b7f9..349d2c2f639 100644 --- a/tests/target/long_field_access.rs +++ b/tests/target/long_field_access.rs @@ -1,4 +1,4 @@ fn f() { - block_flow.base.stacking_relative_position_of_display_port = self.base - .stacking_relative_position_of_display_port; + block_flow.base.stacking_relative_position_of_display_port = + self.base.stacking_relative_position_of_display_port; } diff --git a/tests/target/static.rs b/tests/target/static.rs index 12a8eba111b..30a549cc732 100644 --- a/tests/target/static.rs +++ b/tests/target/static.rs @@ -1,5 +1,5 @@ -const FILE_GENERIC_READ: DWORD = STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES | - FILE_READ_EA | SYNCHRONIZE; +const FILE_GENERIC_READ: DWORD = + STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES | FILE_READ_EA | SYNCHRONIZE; static boolnames: &'static [&'static str] = &[ "bw", @@ -58,3 +58,7 @@ impl Color { pub const WHITE: u32 = 10; } + +// #1391 +pub const XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: NTSTATUS = + 0 as usize; diff --git a/tests/target/type-ascription.rs b/tests/target/type-ascription.rs index f99d524eb2e..a2f082ba4b4 100644 --- a/tests/target/type-ascription.rs +++ b/tests/target/type-ascription.rs @@ -1,9 +1,9 @@ fn main() { - let xxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: - SomeTrait; + let xxxxxxxxxxx = + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: SomeTrait; - let xxxxxxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: - AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; + let xxxxxxxxxxxxxxx = + yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA; let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww): AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;