Skip to content

Commit a3ac175

Browse files
committed
Run rustfmt on the code
1 parent 4735edf commit a3ac175

File tree

10 files changed

+147
-205
lines changed

10 files changed

+147
-205
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();
@@ -102,8 +100,8 @@ fn format_comments() {
102100

103101
let input = "// comment";
104102
let expected_output = "/* com\n \
105-
* men\n \
106-
* t */";
103+
* men\n \
104+
* t */";
107105
assert_eq!(expected_output, rewrite_comment(input, true, 9, 69));
108106

109107
assert_eq!("/* trimmed */", rewrite_comment("/* trimmed */", true, 100, 100));

src/expr.rs

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

8482
Some(rewrite_string(&s.escape_default(), &fmt))
8583
}
@@ -90,7 +88,7 @@ fn rewrite_call(context: &RewriteContext,
9088
span: Span,
9189
width: usize,
9290
offset: usize)
93-
-> Option<String> {
91+
-> Option<String> {
9492
debug!("rewrite_call, width: {}, offset: {}", width, offset);
9593

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

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

132128
Some(format!("{}({})", callee_str, write_list(&items, &fmt)))
133129
}
134130

135-
fn rewrite_paren(context: &RewriteContext, subexpr: &ast::Expr, width: usize, offset: usize) -> Option<String> {
131+
fn rewrite_paren(context: &RewriteContext,
132+
subexpr: &ast::Expr,
133+
width: usize,
134+
offset: usize)
135+
-> Option<String> {
136136
debug!("rewrite_paren, width: {}, offset: {}", width, offset);
137137
// 1 is for opening paren, 2 is for opening+closing, we want to keep the closing
138138
// paren on the same line as the subexpr
@@ -148,14 +148,13 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
148148
span: Span,
149149
width: usize,
150150
offset: usize)
151-
-> Option<String>
152-
{
151+
-> Option<String> {
153152
debug!("rewrite_struct_lit: width {}, offset {}", width, offset);
154153
assert!(fields.len() > 0 || base.is_some());
155154

156155
enum StructLitField<'a> {
157156
Regular(&'a ast::Field),
158-
Base(&'a ast::Expr)
157+
Base(&'a ast::Expr),
159158
}
160159

161160
let path_str = pprust::path_to_string(path);
@@ -203,19 +202,17 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
203202
span_after(span, "{", context.codemap),
204203
span.hi);
205204

206-
let fmt = ListFormatting {
207-
tactic: ListTactic::HorizontalVertical,
208-
separator: ",",
209-
trailing_separator: if base.is_some() {
205+
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
206+
separator: ",",
207+
trailing_separator: if base.is_some() {
210208
SeparatorTactic::Never
211209
} else {
212210
context.config.struct_lit_trailing_comma
213211
},
214-
indent: indent,
215-
h_width: budget,
216-
v_width: budget,
217-
ends_with_newline: true,
218-
};
212+
indent: indent,
213+
h_width: budget,
214+
v_width: budget,
215+
ends_with_newline: true, };
219216
let fields_str = write_list(&items, &fmt);
220217
Some(format!("{} {{ {} }}", path_str, fields_str))
221218

@@ -225,7 +222,11 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
225222
// }
226223
}
227224

228-
fn rewrite_field(context: &RewriteContext, field: &ast::Field, width: usize, offset: usize) -> Option<String> {
225+
fn rewrite_field(context: &RewriteContext,
226+
field: &ast::Field,
227+
width: usize,
228+
offset: usize)
229+
-> Option<String> {
229230
let name = &token::get_ident(field.ident.node);
230231
let overhead = name.len() + 2;
231232
let expr = field.expr.rewrite(context, width - overhead, offset + overhead);
@@ -262,15 +263,13 @@ fn rewrite_tuple_lit(context: &RewriteContext,
262263
SeparatorTactic::Never
263264
};
264265

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

275274
Some(format!("({})", write_list(&items, &fmt)))
276275
}

src/imports.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ impl<'a> FmtVisitor<'a> {
4848
path: &ast::Path,
4949
path_list: &[ast::PathListItem],
5050
visibility: ast::Visibility,
51-
span: Span) -> Option<String> {
51+
span: Span)
52+
-> Option<String> {
5253
let path_str = pprust::path_to_string(path);
5354
let vis = format_visibility(visibility);
5455

@@ -70,18 +71,17 @@ impl<'a> FmtVisitor<'a> {
7071
let remaining_line_budget = one_line_budget.checked_sub(used_width).unwrap_or(0);
7172
let remaining_multi_budget = multi_line_budget.checked_sub(used_width).unwrap_or(0);
7273

73-
let fmt = ListFormatting {
74-
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,
81-
};
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, };
8281

8382
let mut items = itemize_list(self.codemap,
84-
vec![ListItem::from_str("")], // Dummy value, explanation below
83+
vec![ListItem::from_str("")], /* Dummy value, explanation
84+
* below */
8585
path_list.iter(),
8686
",",
8787
"}",

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)