Skip to content

Commit eae2921

Browse files
committed
Bootstrap it. Hard.
1 parent cd158ce commit eae2921

18 files changed

+88
-134
lines changed

src/expr.rs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,20 @@ impl Rewrite for ast::Expr {
136136
Some(ident) => format!(" {}", ident.node),
137137
None => String::new(),
138138
};
139-
wrap_str(format!("continue{}", id_str), context.config.max_width, width, offset)
139+
wrap_str(format!("continue{}", id_str),
140+
context.config.max_width,
141+
width,
142+
offset)
140143
}
141144
ast::ExprKind::Break(ref opt_ident) => {
142145
let id_str = match *opt_ident {
143146
Some(ident) => format!(" {}", ident.node),
144147
None => String::new(),
145148
};
146-
wrap_str(format!("break{}", id_str), context.config.max_width, width, offset)
149+
wrap_str(format!("break{}", id_str),
150+
context.config.max_width,
151+
width,
152+
offset)
147153
}
148154
ast::ExprKind::Closure(capture, ref fn_decl, ref body, _) => {
149155
rewrite_closure(capture, fn_decl, body, self.span, context, width, offset)
@@ -684,11 +690,8 @@ fn extract_comment(span: Span,
684690
-> Option<String> {
685691
let comment_str = context.snippet(span);
686692
if contains_comment(&comment_str) {
687-
let comment = try_opt!(rewrite_comment(comment_str.trim(),
688-
false,
689-
width,
690-
offset,
691-
context.config));
693+
let comment =
694+
try_opt!(rewrite_comment(comment_str.trim(), false, width, offset, context.config));
692695
Some(format!("\n{indent}{}\n{indent}",
693696
comment,
694697
indent = offset.to_string(context.config)))
@@ -788,14 +791,11 @@ fn rewrite_if_else(context: &RewriteContext,
788791
}
789792
};
790793

791-
let between_if_else_block = mk_sp(if_block.span.hi,
792-
context.codemap.span_before(mk_sp(if_block.span.hi,
793-
else_block.span.lo),
794-
"else"));
795-
let between_if_else_block_comment = extract_comment(between_if_else_block,
796-
&context,
797-
offset,
798-
width);
794+
let between_if_else_block =
795+
mk_sp(if_block.span.hi,
796+
context.codemap.span_before(mk_sp(if_block.span.hi, else_block.span.lo), "else"));
797+
let between_if_else_block_comment =
798+
extract_comment(between_if_else_block, &context, offset, width);
799799

800800
let after_else = mk_sp(context.codemap
801801
.span_after(mk_sp(if_block.span.hi, else_block.span.lo),
@@ -922,11 +922,8 @@ fn rewrite_match_arm_comment(context: &RewriteContext,
922922
}
923923
let missed_str = missed_str[first..].trim();
924924
if !missed_str.is_empty() {
925-
let comment = try_opt!(rewrite_comment(&missed_str,
926-
false,
927-
width,
928-
arm_indent,
929-
context.config));
925+
let comment =
926+
try_opt!(rewrite_comment(&missed_str, false, width, arm_indent, context.config));
930927
result.push('\n');
931928
result.push_str(arm_indent_str);
932929
result.push_str(&comment);
@@ -1150,10 +1147,9 @@ impl Rewrite for ast::Arm {
11501147
let body_budget = try_opt!(width.checked_sub(context.config.tab_spaces));
11511148
let indent = context.block_indent.block_indent(context.config);
11521149
let inner_context = &RewriteContext { block_indent: indent, ..*context };
1153-
let next_line_body = try_opt!(nop_block_collapse(body.rewrite(inner_context,
1154-
body_budget,
1155-
indent),
1156-
body_budget));
1150+
let next_line_body =
1151+
try_opt!(nop_block_collapse(body.rewrite(inner_context, body_budget, indent),
1152+
body_budget));
11571153
let indent_str = offset.block_indent(context.config).to_string(context.config);
11581154
let (body_prefix, body_suffix) = if context.config.wrap_match_arms {
11591155
if context.config.match_block_trailing_comma {
@@ -1766,10 +1762,10 @@ pub fn rewrite_unary_suffix<R: Rewrite>(context: &RewriteContext,
17661762
offset: Indent)
17671763
-> Option<String> {
17681764
rewrite.rewrite(context, try_opt!(width.checked_sub(suffix.len())), offset)
1769-
.map(|mut r| {
1770-
r.push_str(suffix);
1771-
r
1772-
})
1765+
.map(|mut r| {
1766+
r.push_str(suffix);
1767+
r
1768+
})
17731769
}
17741770

17751771
fn rewrite_unary_op(context: &RewriteContext,
@@ -1848,7 +1844,8 @@ pub fn rewrite_assign_rhs<S: Into<String>>(context: &RewriteContext,
18481844
// FIXME: DRY!
18491845
match (rhs, new_rhs) {
18501846
(Some(ref orig_rhs), Some(ref replacement_rhs))
1851-
if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 => {
1847+
if count_line_breaks(orig_rhs) >
1848+
count_line_breaks(replacement_rhs) + 1 => {
18521849
result.push_str(&format!("\n{}", new_offset.to_string(context.config)));
18531850
result.push_str(replacement_rhs);
18541851
}

src/items.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ impl Rewrite for ast::Local {
6666
let budget = try_opt!(width.checked_sub(context.block_indent.width() + 1));
6767

6868
// 1 = trailing semicolon;
69-
result = try_opt!(rewrite_assign_rhs(&context,
70-
result,
71-
ex,
72-
budget,
73-
context.block_indent));
69+
result =
70+
try_opt!(rewrite_assign_rhs(&context, result, ex, budget, context.block_indent));
7471
}
7572

7673
result.push(';');
@@ -656,18 +653,17 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
656653

657654
let has_body = !trait_items.is_empty();
658655

659-
let where_density = if (context.config.where_density == Density::Compressed &&
660-
(!result.contains('\n') ||
661-
context.config.fn_args_layout == FnArgLayoutStyle::Block)) ||
662-
(context.config.fn_args_layout == FnArgLayoutStyle::Block &&
663-
result.is_empty()) ||
664-
(context.config.where_density == Density::CompressedIfEmpty &&
665-
!has_body &&
666-
!result.contains('\n')) {
667-
Density::Compressed
668-
} else {
669-
Density::Tall
670-
};
656+
let where_density =
657+
if (context.config.where_density == Density::Compressed &&
658+
(!result.contains('\n') ||
659+
context.config.fn_args_layout == FnArgLayoutStyle::Block)) ||
660+
(context.config.fn_args_layout == FnArgLayoutStyle::Block && result.is_empty()) ||
661+
(context.config.where_density == Density::CompressedIfEmpty && !has_body &&
662+
!result.contains('\n')) {
663+
Density::Compressed
664+
} else {
665+
Density::Tall
666+
};
671667

672668
let where_budget = try_opt!(context.config
673669
.max_width
@@ -1134,9 +1130,8 @@ fn rewrite_explicit_self(explicit_self: &ast::ExplicitSelf,
11341130
let mut_str = format_mutability(m);
11351131
match lt {
11361132
Some(ref l) => {
1137-
let lifetime_str = try_opt!(l.rewrite(context,
1138-
usize::max_value(),
1139-
Indent::empty()));
1133+
let lifetime_str =
1134+
try_opt!(l.rewrite(context, usize::max_value(), Indent::empty()));
11401135
Some(format!("&{} {}self", lifetime_str, mut_str))
11411136
}
11421137
None => Some(format!("&{}self", mut_str)),

src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,8 @@ pub fn format_input(input: Input, config: &Config) -> (Summary, FileMap, FormatR
403403
let mut summary = Summary::new();
404404
let codemap = Rc::new(CodeMap::new());
405405

406-
let tty_handler = Handler::with_tty_emitter(ColorConfig::Auto,
407-
None,
408-
true,
409-
false,
410-
codemap.clone());
406+
let tty_handler =
407+
Handler::with_tty_emitter(ColorConfig::Auto, None, true, false, codemap.clone());
411408
let mut parse_session = ParseSess::with_span_handler(tty_handler, codemap.clone());
412409

413410
let main_file = match input {

src/lists.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,11 +307,8 @@ pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
307307
comment.trim().contains('\n') ||
308308
comment.trim().len() > width;
309309

310-
let formatted_comment = try_opt!(rewrite_comment(comment,
311-
block_style,
312-
width,
313-
offset,
314-
formatting.config));
310+
let formatted_comment =
311+
try_opt!(rewrite_comment(comment, block_style, width, offset, formatting.config));
315312

316313
result.push(' ');
317314
result.push_str(&formatted_comment);

src/patterns.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@ impl Rewrite for Pat {
144144
|f| f.node.rewrite(context, budget, offset),
145145
context.codemap.span_after(self.span, "{"),
146146
self.span.hi);
147-
let mut field_string = try_opt!(format_item_list(items,
148-
budget,
149-
offset,
150-
context.config));
147+
let mut field_string =
148+
try_opt!(format_item_list(items, budget, offset, context.config));
151149
if elipses {
152150
if field_string.contains('\n') {
153151
field_string.push_str(",\n");

src/types.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -375,12 +375,8 @@ impl Rewrite for ast::WherePredicate {
375375
// 3 = " = ".len()
376376
let used_width = 3 + ty_str.len();
377377
let budget = try_opt!(width.checked_sub(used_width));
378-
let path_str = try_opt!(rewrite_path(context,
379-
false,
380-
None,
381-
path,
382-
budget,
383-
offset + used_width));
378+
let path_str =
379+
try_opt!(rewrite_path(context, false, None, path, budget, offset + used_width));
384380
format!("{} = {}", path_str, ty_str)
385381
}
386382
};
@@ -538,9 +534,8 @@ impl Rewrite for ast::Ty {
538534
Some(match *lifetime {
539535
Some(ref lifetime) => {
540536
let lt_budget = try_opt!(width.checked_sub(2 + mut_len));
541-
let lt_str = try_opt!(lifetime.rewrite(context,
542-
lt_budget,
543-
offset + 2 + mut_len));
537+
let lt_str =
538+
try_opt!(lifetime.rewrite(context, lt_budget, offset + 2 + mut_len));
544539
let lt_len = lt_str.len();
545540
let budget = try_opt!(width.checked_sub(2 + mut_len + lt_len));
546541
format!("&{} {}{}",

tests/source/expr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ fn ranges() {
249249
let x = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa .. bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
250250
let y = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ... bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
251251
let z = ... x ;
252-
let infi_range_2 = ... ;
253252

254253
a ... b
255254

tests/source/single-line-if-else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
do_something()
3737
}
3838

39-
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaaaa } else { bbbbbbbbbb };
39+
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa } else { bbbbbbbbbb };
4040

4141
let x = if veeeeeeeeery_loooooong_condition() { aaaaaaaaaaaaaaaaaaaaaaaaa } else {
4242
bbbbbbbbbb };

tests/source/string-lit-2.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
fn main() -> &'static str {
2-
let too_many_lines = "H\
3-
e\
4-
l\
5-
l\
6-
o";
2+
let too_many_lines = "Hello";
73
let leave_me = "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\
84
s
95
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj";

tests/target/chains.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,18 @@ fn issue587() {
137137
fn try_shorthand() {
138138
let x = expr?;
139139
let y = expr.kaas()?.test();
140-
let loooooooooooooooooooooooooooooooooooooooooong = does_this?
141-
.look?
142-
.good?
143-
.should_we_break?
144-
.after_the_first_question_mark?;
140+
let loooooooooooooooooooooooooooooooooooooooooong =
141+
does_this?.look?.good?.should_we_break?.after_the_first_question_mark?;
145142
let yyyy = expr?.another?.another?.another?.another?.another?.another?.another?.another?.test();
146143
let zzzz = expr?.another?.another?.another?.another?;
147144
let aaa = x??????????????????????????????????????????????????????????????????????????;
148145

149146
let y = a.very
150-
.loooooooooooooooooooooooooooooooooooooong()
151-
.chain()
152-
.inside()
153-
.weeeeeeeeeeeeeee()?
154-
.test()
155-
.0
156-
.x;
147+
.loooooooooooooooooooooooooooooooooooooong()
148+
.chain()
149+
.inside()
150+
.weeeeeeeeeeeeeee()?
151+
.test()
152+
.0
153+
.x;
157154
}

tests/target/closure.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,18 @@ fn main() {
4646
do_something_else();
4747
};
4848

49-
let arg_test = |big_argument_name, test123| {
50-
looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
51-
};
49+
let arg_test =
50+
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
5251

53-
let arg_test = |big_argument_name, test123| {
54-
looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame()
55-
};
52+
let arg_test =
53+
|big_argument_name, test123| looooooooooooooooooong_function_naaaaaaaaaaaaaaaaame();
5654

5755
let simple_closure = move || -> () {};
5856

5957
let closure = |input: Ty| -> Option<String> { foo() };
6058

61-
let closure_with_return_type = |aaaaaaaaaaaaaaaaaaaaaaarg1,
62-
aaaaaaaaaaaaaaaaaaaaaaarg2|
63-
-> Strong {
64-
"sup".to_owned()
65-
};
59+
let closure_with_return_type =
60+
|aaaaaaaaaaaaaaaaaaaaaaarg1, aaaaaaaaaaaaaaaaaaaaaaarg2| -> Strong { "sup".to_owned() };
6661

6762
|arg1, arg2, _, _, arg3, arg4| {
6863
let temp = arg4 + arg3;

tests/target/expr.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,8 @@ fn arrays() {
202202
item: 3,
203203
}]);
204204

205-
let z = [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
206-
yyyyyyyyyyyyyyyyyyyyyyyyyyy,
207-
zzzzzzzzzzzzzzzzzz,
208-
q];
205+
let z =
206+
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz, q];
209207

210208
[1 + 3, 4, 5, 6, 7, 7, fncall::<Vec<_>>(3 - 1)]
211209
}
@@ -273,7 +271,6 @@ fn ranges() {
273271
let y =
274272
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb;
275273
let z = ...x;
276-
let infi_range_2 = ...;
277274

278275
a...b
279276

tests/target/hard-tabs.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,8 @@ fn main() {
5555
.go_to_next_line_with_tab()
5656
.go_to_next_line_with_tab();
5757

58-
let z = [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,
59-
yyyyyyyyyyyyyyyyyyyyyyyyyyy,
60-
zzzzzzzzzzzzzzzzzz,
61-
q];
58+
let z =
59+
[xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzz, q];
6260

6361
fn generic<T>(arg: T) -> &SomeType
6462
where T: Fn(// First arg

tests/target/single-line-if-else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn main() {
4141
}
4242

4343
let x = if veeeeeeeeery_loooooong_condition() {
44-
aaaaaaaaaaaaaaaaaaaaaaaaaaa
44+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
4545
} else {
4646
bbbbbbbbbb
4747
};

tests/target/static.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
const FILE_GENERIC_READ: DWORD = STANDARD_RIGHTS_READ | FILE_READ_DATA | FILE_READ_ATTRIBUTES |
22
FILE_READ_EA | SYNCHRONIZE;
33

4-
static boolnames: &'static [&'static str] = &["bw", "am", "xsb", "xhp", "xenl", "eo", "gn", "hc",
5-
"km", "hs", "in", "db", "da", "mir", "msgr", "os",
6-
"eslok", "xt", "hz", "ul", "xon", "nxon", "mc5i",
7-
"chts", "nrrmc", "npc", "ndscr", "ccc", "bce",
8-
"hls", "xhpa", "crxm", "daisy", "xvpa", "sam",
9-
"cpix", "lpix", "OTbs", "OTns", "OTnc", "OTMT",
10-
"OTNL", "OTpt", "OTxr"];
4+
static boolnames: &'static [&'static str] =
5+
&["bw", "am", "xsb", "xhp", "xenl", "eo", "gn", "hc", "km", "hs", "in", "db", "da", "mir",
6+
"msgr", "os", "eslok", "xt", "hz", "ul", "xon", "nxon", "mc5i", "chts", "nrrmc", "npc",
7+
"ndscr", "ccc", "bce", "hls", "xhpa", "crxm", "daisy", "xvpa", "sam", "cpix", "lpix",
8+
"OTbs", "OTns", "OTnc", "OTMT", "OTNL", "OTpt", "OTxr"];
119

1210
static mut name: SomeType =
1311
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;

tests/target/string-lit-2.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
fn main() -> &'static str {
2-
let too_many_lines = "H\
3-
e\
4-
l\
5-
l\
6-
o";
2+
let too_many_lines = "Hello";
73
let leave_me = "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss\
84
s
95
jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj";

0 commit comments

Comments
 (0)