Skip to content

Commit fea751b

Browse files
committed
Run rustfmt on the code
1 parent bb8a4a0 commit fea751b

File tree

10 files changed

+144
-201
lines changed

10 files changed

+144
-201
lines changed

src/changes.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@ 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 {
39-
file_map: HashMap::new(),
40-
codemap: codemap,
41-
file_spans: Vec::with_capacity(codemap.files.borrow().len()),
42-
};
38+
let mut result = ChangeSet { file_map: HashMap::new(),
39+
codemap: codemap,
40+
file_spans: Vec::with_capacity(codemap.files.borrow().len()), };
4341

4442
for f in codemap.files.borrow().iter() {
4543
// Use the length of the file as a heuristic for how much space we
@@ -116,11 +114,7 @@ impl<'a> ChangeSet<'a> {
116114

117115
// Return an iterator over the entire changed text.
118116
pub fn text<'c>(&'c self) -> FileIterator<'c, 'a> {
119-
FileIterator {
120-
change_set: self,
121-
keys: self.file_map.keys().collect(),
122-
cur_key: 0,
123-
}
117+
FileIterator { change_set: self, keys: self.file_map.keys().collect(), cur_key: 0 }
124118
}
125119

126120
// Append a newline to the end of each file.
@@ -153,12 +147,11 @@ impl<'a> ChangeSet<'a> {
153147
let text = &self.file_map[filename];
154148

155149
// prints all newlines either as `\n` or as `\r\n`
156-
fn write_system_newlines<T>(
157-
mut writer: T,
158-
text: &StringBuffer,
159-
config: &Config)
160-
-> Result<(), ::std::io::Error>
161-
where T: Write,
150+
fn write_system_newlines<T>(mut writer: T,
151+
text: &StringBuffer,
152+
config: &Config)
153+
-> Result<(), ::std::io::Error>
154+
where T: Write
162155
{
163156
match config.newline_style {
164157
NewlineStyle::Unix => write!(writer, "{}", text),

src/comment.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@ 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 {
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-
};
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, };
3634

3735
let indent_str = make_indent(offset);
3836
let line_breaks = s.chars().filter(|&c| c == '\n').count();
@@ -95,8 +93,8 @@ fn format_comments() {
9593

9694
let input = "// comment";
9795
let expected_output = "/* com\n \
98-
* men\n \
99-
* t */";
96+
* men\n \
97+
* t */";
10098
assert_eq!(expected_output, rewrite_comment(input, true, 9, 69));
10199
}
102100

src/expr.rs

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,21 @@ fn rewrite_string_lit(context: &RewriteContext,
6161
span: Span,
6262
width: usize,
6363
offset: usize)
64-
-> Option<String> {
64+
-> Option<String> {
6565
// Check if there is anything to fix: we always try to fixup multi-line
6666
// strings, or if the string is too long for the line.
6767
let l_loc = context.codemap.lookup_char_pos(span.lo);
6868
let r_loc = context.codemap.lookup_char_pos(span.hi);
6969
if l_loc.line == r_loc.line && r_loc.col.to_usize() <= context.config.max_width {
7070
return context.codemap.span_to_snippet(span).ok();
7171
}
72-
let fmt = StringFormat {
73-
opener: "\"",
74-
closer: "\"",
75-
line_start: " ",
76-
line_end: "\\",
77-
width: width,
78-
offset: offset,
79-
trim_end: false
80-
};
72+
let fmt = StringFormat { opener: "\"",
73+
closer: "\"",
74+
line_start: " ",
75+
line_end: "\\",
76+
width: width,
77+
offset: offset,
78+
trim_end: false, };
8179

8280
Some(rewrite_string(&s.escape_default(), &fmt))
8381
}
@@ -88,7 +86,7 @@ fn rewrite_call(context: &RewriteContext,
8886
span: Span,
8987
width: usize,
9088
offset: usize)
91-
-> Option<String> {
89+
-> Option<String> {
9290
debug!("rewrite_call, width: {}, offset: {}", width, offset);
9391

9492
// TODO using byte lens instead of char lens (and probably all over the place too)
@@ -117,20 +115,22 @@ fn rewrite_call(context: &RewriteContext,
117115
callee.span.hi + BytePos(1),
118116
span.hi);
119117

120-
let fmt = ListFormatting {
121-
tactic: ListTactic::HorizontalVertical,
122-
separator: ",",
123-
trailing_separator: SeparatorTactic::Never,
124-
indent: offset,
125-
h_width: remaining_width,
126-
v_width: remaining_width,
127-
ends_with_newline: true,
128-
};
118+
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
119+
separator: ",",
120+
trailing_separator: SeparatorTactic::Never,
121+
indent: offset,
122+
h_width: remaining_width,
123+
v_width: remaining_width,
124+
ends_with_newline: true, };
129125

130126
Some(format!("{}({})", callee_str, write_list(&items, &fmt)))
131127
}
132128

133-
fn rewrite_paren(context: &RewriteContext, subexpr: &ast::Expr, width: usize, offset: usize) -> Option<String> {
129+
fn rewrite_paren(context: &RewriteContext,
130+
subexpr: &ast::Expr,
131+
width: usize,
132+
offset: usize)
133+
-> Option<String> {
134134
debug!("rewrite_paren, width: {}, offset: {}", width, offset);
135135
// 1 is for opening paren, 2 is for opening+closing, we want to keep the closing
136136
// paren on the same line as the subexpr
@@ -146,14 +146,13 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
146146
span: Span,
147147
width: usize,
148148
offset: usize)
149-
-> Option<String>
150-
{
149+
-> Option<String> {
151150
debug!("rewrite_struct_lit: width {}, offset {}", width, offset);
152151
assert!(fields.len() > 0 || base.is_some());
153152

154153
enum StructLitField<'a> {
155154
Regular(&'a ast::Field),
156-
Base(&'a ast::Expr)
155+
Base(&'a ast::Expr),
157156
}
158157

159158
let path_str = pprust::path_to_string(path);
@@ -201,19 +200,17 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
201200
span_after(span, "{", context.codemap),
202201
span.hi);
203202

204-
let fmt = ListFormatting {
205-
tactic: ListTactic::HorizontalVertical,
206-
separator: ",",
207-
trailing_separator: if base.is_some() {
203+
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
204+
separator: ",",
205+
trailing_separator: if base.is_some() {
208206
SeparatorTactic::Never
209207
} else {
210208
context.config.struct_lit_trailing_comma
211209
},
212-
indent: indent,
213-
h_width: budget,
214-
v_width: budget,
215-
ends_with_newline: true,
216-
};
210+
indent: indent,
211+
h_width: budget,
212+
v_width: budget,
213+
ends_with_newline: true, };
217214
let fields_str = write_list(&items, &fmt);
218215
Some(format!("{} {{ {} }}", path_str, fields_str))
219216

@@ -223,7 +220,11 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
223220
// }
224221
}
225222

226-
fn rewrite_field(context: &RewriteContext, field: &ast::Field, width: usize, offset: usize) -> Option<String> {
223+
fn rewrite_field(context: &RewriteContext,
224+
field: &ast::Field,
225+
width: usize,
226+
offset: usize)
227+
-> Option<String> {
227228
let name = &token::get_ident(field.ident.node);
228229
let overhead = name.len() + 2;
229230
let expr = field.expr.rewrite(context, width - overhead, offset + overhead);
@@ -235,7 +236,7 @@ fn rewrite_tuple_lit(context: &RewriteContext,
235236
span: Span,
236237
width: usize,
237238
offset: usize)
238-
-> Option<String> {
239+
-> Option<String> {
239240
let indent = offset + 1;
240241

241242
let items = itemize_list(context.codemap,
@@ -260,15 +261,13 @@ fn rewrite_tuple_lit(context: &RewriteContext,
260261
SeparatorTactic::Never
261262
};
262263

263-
let fmt = ListFormatting {
264-
tactic: ListTactic::HorizontalVertical,
265-
separator: ",",
266-
trailing_separator: trailing_separator_tactic,
267-
indent: indent,
268-
h_width: width - 2,
269-
v_width: width - 2,
270-
ends_with_newline: true,
271-
};
264+
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
265+
separator: ",",
266+
trailing_separator: trailing_separator_tactic,
267+
indent: indent,
268+
h_width: width - 2,
269+
v_width: width - 2,
270+
ends_with_newline: true, };
272271

273272
Some(format!("({})", write_list(&items, &fmt)))
274273
}

src/imports.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ impl<'a> FmtVisitor<'a> {
4646
multi_line_budget: usize,
4747
path: &ast::Path,
4848
path_list: &[ast::PathListItem],
49-
visibility: ast::Visibility) -> Option<String> {
49+
visibility: ast::Visibility)
50+
-> Option<String> {
5051
let path_str = pprust::path_to_string(path);
5152
let vis = format_visibility(visibility);
5253

@@ -68,15 +69,13 @@ impl<'a> FmtVisitor<'a> {
6869
let remaining_line_budget = one_line_budget.checked_sub(used_width).unwrap_or(0);
6970
let remaining_multi_budget = multi_line_budget.checked_sub(used_width).unwrap_or(0);
7071

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

8180
// TODO handle any comments inbetween items.
8281
// If `self` is in the list, put it first.

src/issues.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static FIX_ME_CHARS: &'static [char] = &['F', 'I', 'X', 'M', 'E'];
2121
pub enum ReportTactic {
2222
Always,
2323
Unnumbered,
24-
Never
24+
Never,
2525
}
2626

2727
impl ReportTactic {
@@ -40,20 +40,20 @@ impl_enum_decodable!(ReportTactic, Always, Unnumbered, Never);
4040
enum Seeking {
4141
Issue {
4242
todo_idx: usize,
43-
fixme_idx: usize
43+
fixme_idx: usize,
4444
},
4545
Number {
4646
issue: Issue,
47-
part: NumberPart
48-
}
47+
part: NumberPart,
48+
},
4949
}
5050

5151
#[derive(Clone, Copy)]
5252
enum NumberPart {
5353
OpenParen,
5454
Pound,
5555
Number,
56-
CloseParen
56+
CloseParen,
5757
}
5858

5959
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
@@ -79,13 +79,13 @@ impl fmt::Display for Issue {
7979
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
8080
enum IssueType {
8181
Todo,
82-
Fixme
82+
Fixme,
8383
}
8484

8585
enum IssueClassification {
8686
Good,
8787
Bad(Issue),
88-
None
88+
None,
8989
}
9090

9191
pub struct BadIssueSeeker {
@@ -96,11 +96,9 @@ pub struct BadIssueSeeker {
9696

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

106104
// Check whether or not the current char is conclusive evidence for an
@@ -176,8 +174,7 @@ impl BadIssueSeeker {
176174
c: char,
177175
issue: Issue,
178176
mut part: NumberPart)
179-
-> IssueClassification
180-
{
177+
-> IssueClassification {
181178
if ! issue.missing_number || c == '\n' {
182179
return IssueClassification::Bad(issue);
183180
} else if c == ')' {
@@ -272,10 +269,7 @@ fn find_issue() {
272269
#[test]
273270
fn issue_type() {
274271
let mut seeker = BadIssueSeeker::new(ReportTactic::Always, ReportTactic::Never);
275-
let expected = Some(Issue {
276-
issue_type: IssueType::Todo,
277-
missing_number: false
278-
});
272+
let expected = Some(Issue { issue_type: IssueType::Todo, missing_number: false });
279273

280274
assert_eq!(expected,
281275
"TODO(#100): more awesomeness".chars()
@@ -284,10 +278,7 @@ fn issue_type() {
284278
.unwrap());
285279

286280
let mut seeker = BadIssueSeeker::new(ReportTactic::Never, ReportTactic::Unnumbered);
287-
let expected = Some(Issue {
288-
issue_type: IssueType::Fixme,
289-
missing_number: true
290-
});
281+
let expected = Some(Issue { issue_type: IssueType::Fixme, missing_number: true });
291282

292283
assert_eq!(expected,
293284
"Test. FIXME: bad, bad, not good".chars()

0 commit comments

Comments
 (0)