Skip to content

Commit 018fa85

Browse files
committed
Reformat code to new struct lit style
1 parent 7518f68 commit 018fa85

File tree

7 files changed

+112
-84
lines changed

7 files changed

+112
-84
lines changed

src/changes.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ pub struct ChangeSet<'a> {
3535
impl<'a> ChangeSet<'a> {
3636
// Create a new ChangeSet for a given libsyntax CodeMap.
3737
pub fn from_codemap(codemap: &'a CodeMap) -> ChangeSet<'a> {
38-
let mut result = ChangeSet { file_map: HashMap::new(),
39-
codemap: codemap,
40-
file_spans: Vec::with_capacity(codemap.files.borrow().len()), };
38+
let mut result = ChangeSet {
39+
file_map: HashMap::new(),
40+
codemap: codemap,
41+
file_spans: Vec::with_capacity(codemap.files.borrow().len()),
42+
};
4143

4244
for f in codemap.files.borrow().iter() {
4345
// Use the length of the file as a heuristic for how much space we

src/comment.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ pub fn rewrite_comment(orig: &str, block_style: bool, width: usize, offset: usiz
2424
let max_chars = width.checked_sub(closer.len()).unwrap_or(1)
2525
.checked_sub(opener.len()).unwrap_or(1);
2626

27-
let fmt = StringFormat { opener: "",
28-
closer: "",
29-
line_start: line_start,
30-
line_end: "",
31-
width: max_chars,
32-
offset: offset + opener.len() - line_start.len(),
33-
trim_end: true, };
27+
let fmt = StringFormat {
28+
opener: "",
29+
closer: "",
30+
line_start: line_start,
31+
line_end: "",
32+
width: max_chars,
33+
offset: offset + opener.len() - line_start.len(),
34+
trim_end: true,
35+
};
3436

3537
let indent_str = make_indent(offset);
3638
let line_breaks = s.chars().filter(|&c| c == '\n').count();

src/expr.rs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ fn rewrite_string_lit(context: &RewriteContext,
101101
if l_loc.line == r_loc.line && r_loc.col.to_usize() <= context.config.max_width {
102102
return context.codemap.span_to_snippet(span).ok();
103103
}
104-
let fmt = StringFormat { opener: "\"",
105-
closer: "\"",
106-
line_start: " ",
107-
line_end: "\\",
108-
width: width,
109-
offset: offset,
110-
trim_end: false, };
104+
let fmt = StringFormat {
105+
opener: "\"",
106+
closer: "\"",
107+
line_start: " ",
108+
line_end: "\\",
109+
width: width,
110+
offset: offset,
111+
trim_end: false,
112+
};
111113

112114
Some(rewrite_string(&s.escape_default(), &fmt))
113115
}
@@ -147,13 +149,15 @@ fn rewrite_call(context: &RewriteContext,
147149
callee.span.hi + BytePos(1),
148150
span.hi);
149151

150-
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
151-
separator: ",",
152-
trailing_separator: SeparatorTactic::Never,
153-
indent: offset,
154-
h_width: remaining_width,
155-
v_width: remaining_width,
156-
ends_with_newline: true, };
152+
let fmt = ListFormatting {
153+
tactic: ListTactic::HorizontalVertical,
154+
separator: ",",
155+
trailing_separator: SeparatorTactic::Never,
156+
indent: offset,
157+
h_width: remaining_width,
158+
v_width: remaining_width,
159+
ends_with_newline: true,
160+
};
157161

158162
Some(format!("{}({})", callee_str, write_list(&items, &fmt)))
159163
}
@@ -239,17 +243,19 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
239243
span_after(span, "{", context.codemap),
240244
span.hi);
241245

242-
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
243-
separator: ",",
244-
trailing_separator: if base.is_some() {
246+
let fmt = ListFormatting {
247+
tactic: ListTactic::HorizontalVertical,
248+
separator: ",",
249+
trailing_separator: if base.is_some() {
245250
SeparatorTactic::Never
246251
} else {
247252
context.config.struct_lit_trailing_comma
248253
},
249-
indent: indent,
250-
h_width: budget,
251-
v_width: budget,
252-
ends_with_newline: true, };
254+
indent: indent,
255+
h_width: budget,
256+
v_width: budget,
257+
ends_with_newline: true,
258+
};
253259
let fields_str = write_list(&items, &fmt);
254260

255261
match context.config.struct_lit_style {
@@ -305,13 +311,15 @@ fn rewrite_tuple_lit(context: &RewriteContext,
305311
span.lo + BytePos(1), // Remove parens
306312
span.hi - BytePos(1));
307313

308-
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
309-
separator: ",",
310-
trailing_separator: SeparatorTactic::Never,
311-
indent: indent,
312-
h_width: width - 2,
313-
v_width: width - 2,
314-
ends_with_newline: true, };
314+
let fmt = ListFormatting {
315+
tactic: ListTactic::HorizontalVertical,
316+
separator: ",",
317+
trailing_separator: SeparatorTactic::Never,
318+
indent: indent,
319+
h_width: width - 2,
320+
v_width: width - 2,
321+
ends_with_newline: true,
322+
};
315323

316324
Some(format!("({})", write_list(&items, &fmt)))
317325
}

src/imports.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ impl<'a> FmtVisitor<'a> {
7171
let remaining_line_budget = one_line_budget.checked_sub(used_width).unwrap_or(0);
7272
let remaining_multi_budget = multi_line_budget.checked_sub(used_width).unwrap_or(0);
7373

74-
let fmt = ListFormatting { tactic: ListTactic::Mixed,
75-
separator: ",",
76-
trailing_separator: SeparatorTactic::Never,
77-
indent: block_indent + indent,
78-
h_width: remaining_line_budget,
79-
v_width: remaining_multi_budget,
80-
ends_with_newline: true, };
74+
let fmt = ListFormatting {
75+
tactic: ListTactic::Mixed,
76+
separator: ",",
77+
trailing_separator: SeparatorTactic::Never,
78+
indent: block_indent + indent,
79+
h_width: remaining_line_budget,
80+
v_width: remaining_multi_budget,
81+
ends_with_newline: true,
82+
};
8183

8284
let mut items = itemize_list(self.codemap,
8385
vec![ListItem::from_str("")], /* Dummy value, explanation

src/issues.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ pub struct BadIssueSeeker {
9696

9797
impl BadIssueSeeker {
9898
pub fn new(report_todo: ReportTactic, report_fixme: ReportTactic) -> BadIssueSeeker {
99-
BadIssueSeeker { state: Seeking::Issue { todo_idx: 0, fixme_idx: 0 },
100-
report_todo: report_todo,
101-
report_fixme: report_fixme, }
99+
BadIssueSeeker {
100+
state: Seeking::Issue { todo_idx: 0, fixme_idx: 0 },
101+
report_todo: report_todo,
102+
report_fixme: report_fixme,
103+
}
102104
}
103105

104106
// Check whether or not the current char is conclusive evidence for an

src/items.rs

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,15 @@ impl<'a> FmtVisitor<'a> {
305305
item.item = arg;
306306
}
307307

308-
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
309-
separator: ",",
310-
trailing_separator: SeparatorTactic::Never,
311-
indent: arg_indent,
312-
h_width: one_line_budget,
313-
v_width: multi_line_budget,
314-
ends_with_newline: true, };
308+
let fmt = ListFormatting {
309+
tactic: ListTactic::HorizontalVertical,
310+
separator: ",",
311+
trailing_separator: SeparatorTactic::Never,
312+
indent: arg_indent,
313+
h_width: one_line_budget,
314+
v_width: multi_line_budget,
315+
ends_with_newline: true,
316+
};
315317

316318
write_list(&arg_items, &fmt)
317319
}
@@ -566,13 +568,15 @@ impl<'a> FmtVisitor<'a> {
566568

567569
// 1 = ,
568570
let budget = self.config.ideal_width - offset + self.config.tab_spaces - 1;
569-
let fmt = ListFormatting { tactic: tactic,
570-
separator: ",",
571-
trailing_separator: self.config.struct_trailing_comma,
572-
indent: offset + self.config.tab_spaces,
573-
h_width: self.config.max_width,
574-
v_width: budget,
575-
ends_with_newline: false, };
571+
let fmt = ListFormatting {
572+
tactic: tactic,
573+
separator: ",",
574+
trailing_separator: self.config.struct_trailing_comma,
575+
indent: offset + self.config.tab_spaces,
576+
h_width: self.config.max_width,
577+
v_width: budget,
578+
ends_with_newline: false,
579+
};
576580

577581
result.push_str(&write_list(&items, &fmt));
578582

@@ -707,13 +711,15 @@ impl<'a> FmtVisitor<'a> {
707711
item.item = ty;
708712
}
709713

710-
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
711-
separator: ",",
712-
trailing_separator: SeparatorTactic::Never,
713-
indent: offset + 1,
714-
h_width: budget,
715-
v_width: budget,
716-
ends_with_newline: true, };
714+
let fmt = ListFormatting {
715+
tactic: ListTactic::HorizontalVertical,
716+
separator: ",",
717+
trailing_separator: SeparatorTactic::Never,
718+
indent: offset + 1,
719+
h_width: budget,
720+
v_width: budget,
721+
ends_with_newline: true,
722+
};
717723
result.push_str(&write_list(&items, &fmt));
718724

719725
result.push('>');
@@ -748,13 +754,15 @@ impl<'a> FmtVisitor<'a> {
748754
span_end);
749755

750756
let budget = self.config.ideal_width + self.config.leeway - indent - 10;
751-
let fmt = ListFormatting { tactic: ListTactic::Vertical,
752-
separator: ",",
753-
trailing_separator: SeparatorTactic::Never,
754-
indent: indent + 10,
755-
h_width: budget,
756-
v_width: budget,
757-
ends_with_newline: true, };
757+
let fmt = ListFormatting {
758+
tactic: ListTactic::Vertical,
759+
separator: ",",
760+
trailing_separator: SeparatorTactic::Never,
761+
indent: indent + 10,
762+
h_width: budget,
763+
v_width: budget,
764+
ends_with_newline: true,
765+
};
758766
result.push_str(&write_list(&items, &fmt));
759767

760768
result

src/visitor.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
3838
self.codemap.lookup_char_pos(ex.span.hi));
3939
self.format_missing(ex.span.lo);
4040
let offset = self.changes.cur_offset_span(ex.span);
41-
let context = RewriteContext { codemap: self.codemap,
42-
config: self.config,
43-
block_indent: self.block_indent, };
41+
let context = RewriteContext {
42+
codemap: self.codemap,
43+
config: self.config,
44+
block_indent: self.block_indent,
45+
};
4446
let rewrite = ex.rewrite(&context, self.config.max_width - offset, offset);
4547

4648
if let Some(new_str) = rewrite {
@@ -284,11 +286,13 @@ impl<'a, 'v> visit::Visitor<'v> for FmtVisitor<'a> {
284286

285287
impl<'a> FmtVisitor<'a> {
286288
pub fn from_codemap<'b>(codemap: &'b CodeMap, config: &'b Config) -> FmtVisitor<'b> {
287-
FmtVisitor { codemap: codemap,
288-
changes: ChangeSet::from_codemap(codemap),
289-
last_pos: BytePos(0),
290-
block_indent: 0,
291-
config: config, }
289+
FmtVisitor {
290+
codemap: codemap,
291+
changes: ChangeSet::from_codemap(codemap),
292+
last_pos: BytePos(0),
293+
block_indent: 0,
294+
config: config,
295+
}
292296
}
293297

294298
pub fn snippet(&self, span: Span) -> String {

0 commit comments

Comments
 (0)