Skip to content

Commit 488c0b9

Browse files
committed
Test and source fallout
1 parent 4bb31a7 commit 488c0b9

File tree

11 files changed

+130
-94
lines changed

11 files changed

+130
-94
lines changed

src/bin/rustfmt.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
219219

220220
Ok(run(Input::Text(input), &config))
221221
}
222-
Operation::Format { mut files, config_path } => {
222+
Operation::Format {
223+
mut files,
224+
config_path,
225+
} => {
223226
let options = try!(CliOptions::from_matches(&matches));
224227

225228
// Add any additional files that were specified via `--file-lines`.

src/chains.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
130130
.checked_sub(nested_shape.indent.width() +
131131
nested_shape.offset));
132132

133-
let other_child_shape = Shape { width: max_width, ..nested_shape };
133+
let other_child_shape = Shape {
134+
width: max_width,
135+
..nested_shape
136+
};
134137
let first_child_shape = if extend {
135138
let mut shape = try_opt!(parent_shape.shrink_left(last_line_width(&parent_rewrite)));
136139
match context.config.chain_indent {

src/expr.rs

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use {Indent, Shape, Spanned};
1919
use codemap::SpanUtils;
2020
use rewrite::{Rewrite, RewriteContext};
2121
use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic,
22-
DefinitiveListTactic, definitive_tactic, ListItem, format_item_list,
23-
struct_lit_shape, struct_lit_tactic, shape_for_tactic, struct_lit_formatting};
22+
DefinitiveListTactic, definitive_tactic, ListItem, format_item_list, struct_lit_shape,
23+
struct_lit_tactic, shape_for_tactic, struct_lit_formatting};
2424
use string::{StringFormat, rewrite_string};
2525
use utils::{extra_offset, last_line_width, wrap_str, binary_search, first_line_width,
2626
semicolon_for_stmt, trimmed_last_line_width, left_most_sub_expr, stmt_expr};
@@ -308,7 +308,11 @@ pub fn rewrite_pair<LHS, RHS>(lhs: &LHS,
308308
.visual_indent(prefix.len());
309309

310310
let rhs_result = try_opt!(rhs.rewrite(context, rhs_shape));
311-
let lhs_result = try_opt!(lhs.rewrite(context, Shape { width: lhs_budget, ..shape }));
311+
let lhs_result = try_opt!(lhs.rewrite(context,
312+
Shape {
313+
width: lhs_budget,
314+
..shape
315+
}));
312316
Some(format!("{}{}{}\n{}{}{}",
313317
prefix,
314318
lhs_result,
@@ -658,9 +662,7 @@ impl Rewrite for ast::Block {
658662
impl Rewrite for ast::Stmt {
659663
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
660664
let result = match self.node {
661-
ast::StmtKind::Local(ref local) => {
662-
local.rewrite(context, shape)
663-
}
665+
ast::StmtKind::Local(ref local) => local.rewrite(context, shape),
664666
ast::StmtKind::Expr(ref ex) |
665667
ast::StmtKind::Semi(ref ex) => {
666668
let suffix = if semicolon_for_stmt(self) { ";" } else { "" };
@@ -893,7 +895,10 @@ impl<'a> Rewrite for ControlFlow<'a> {
893895
block_width
894896
};
895897

896-
let block_shape = Shape { width: block_width, ..shape };
898+
let block_shape = Shape {
899+
width: block_width,
900+
..shape
901+
};
897902
let block_str = try_opt!(self.block.rewrite(context, block_shape));
898903

899904
let cond_span = if let Some(cond) = self.cond {
@@ -975,7 +980,10 @@ impl<'a> Rewrite for ControlFlow<'a> {
975980
last_in_chain = true;
976981
// When rewriting a block, the width is only used for single line
977982
// blocks, passing 1 lets us avoid that.
978-
let else_shape = Shape { width: min(1, shape.width), ..shape };
983+
let else_shape = Shape {
984+
width: min(1, shape.width),
985+
..shape
986+
};
979987
else_block.rewrite(context, else_shape)
980988
}
981989
};
@@ -1175,7 +1183,11 @@ fn rewrite_match(context: &RewriteContext,
11751183
}
11761184

11771185
fn arm_start_pos(arm: &ast::Arm) -> BytePos {
1178-
let &ast::Arm { ref attrs, ref pats, .. } = arm;
1186+
let &ast::Arm {
1187+
ref attrs,
1188+
ref pats,
1189+
..
1190+
} = arm;
11791191
if !attrs.is_empty() {
11801192
return attrs[0].span.lo;
11811193
}
@@ -1205,7 +1217,12 @@ fn arm_comma(config: &Config, body: &ast::Expr) -> &'static str {
12051217
impl Rewrite for ast::Arm {
12061218
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
12071219
debug!("Arm::rewrite {:?} {:?}", self, shape);
1208-
let &ast::Arm { ref attrs, ref pats, ref guard, ref body } = self;
1220+
let &ast::Arm {
1221+
ref attrs,
1222+
ref pats,
1223+
ref guard,
1224+
ref body,
1225+
} = self;
12091226

12101227
// FIXME this is all a bit grotty, would be nice to abstract out the
12111228
// treatment of attributes.
@@ -1250,7 +1267,10 @@ impl Rewrite for ast::Arm {
12501267
let pats_str = try_opt!(write_list(items, &fmt));
12511268

12521269
let guard_shape = if pats_str.contains('\n') {
1253-
Shape { width: context.config.max_width - shape.indent.width(), ..shape }
1270+
Shape {
1271+
width: context.config.max_width - shape.indent.width(),
1272+
..shape
1273+
}
12541274
} else {
12551275
shape
12561276
};
@@ -1598,7 +1618,10 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
15981618
|item| item.span.hi,
15991619
|item| {
16001620
item.rewrite(context,
1601-
Shape { width: remaining_width, ..nested_shape })
1621+
Shape {
1622+
width: remaining_width,
1623+
..nested_shape
1624+
})
16021625
},
16031626
span.lo,
16041627
span.hi);

src/imports.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,13 @@ impl<'a> FmtVisitor<'a> {
193193
// before the current `self.last_pos`
194194
let pos_before_first_use_item = use_items.first()
195195
.map(|p_i| {
196-
cmp::max(self.last_pos,
197-
p_i.attrs
198-
.iter()
199-
.map(|attr| attr.span.lo)
200-
.min()
201-
.unwrap_or(p_i.span.lo))
202-
})
196+
cmp::max(self.last_pos,
197+
p_i.attrs
198+
.iter()
199+
.map(|attr| attr.span.lo)
200+
.min()
201+
.unwrap_or(p_i.span.lo))
202+
})
203203
.unwrap_or(self.last_pos);
204204
// Construct a list of pairs, each containing a `use` item and the start of span before
205205
// that `use` item.

src/issues.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ impl BadIssueSeeker {
9898
// unnumbered TO-DO or FIX-ME.
9999
pub fn inspect(&mut self, c: char) -> Option<Issue> {
100100
match self.state {
101-
Seeking::Issue { todo_idx, fixme_idx } => {
101+
Seeking::Issue {
102+
todo_idx,
103+
fixme_idx,
104+
} => {
102105
self.state = self.inspect_issue(c, todo_idx, fixme_idx);
103106
}
104107
Seeking::Number { issue, part } => {

src/items.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,7 @@ impl Rewrite for ast::Local {
7373
//let budget = try_opt!(shape.width.checked_sub(shape.indent.block_only().width() + 1));
7474
let nested_shape = try_opt!(shape.sub_width(1));
7575

76-
result = try_opt!(rewrite_assign_rhs(&context,
77-
result,
78-
ex,
79-
nested_shape));
76+
result = try_opt!(rewrite_assign_rhs(&context, result, ex, nested_shape));
8077
}
8178

8279
result.push(';');
@@ -932,13 +929,13 @@ fn format_struct_struct(context: &RewriteContext,
932929
fields.iter(),
933930
"}",
934931
|field| {
935-
// Include attributes and doc comments, if present
936-
if !field.attrs.is_empty() {
937-
field.attrs[0].span.lo
938-
} else {
939-
field.span.lo
940-
}
941-
},
932+
// Include attributes and doc comments, if present
933+
if !field.attrs.is_empty() {
934+
field.attrs[0].span.lo
935+
} else {
936+
field.span.lo
937+
}
938+
},
942939
|field| field.ty.span.hi,
943940
|field| field.rewrite(context, Shape::legacy(item_budget, item_indent)),
944941
context.codemap.span_after(span, "{"),
@@ -1035,13 +1032,13 @@ fn format_tuple_struct(context: &RewriteContext,
10351032
fields.iter(),
10361033
")",
10371034
|field| {
1038-
// Include attributes and doc comments, if present
1039-
if !field.attrs.is_empty() {
1040-
field.attrs[0].span.lo
1041-
} else {
1042-
field.span.lo
1043-
}
1044-
},
1035+
// Include attributes and doc comments, if present
1036+
if !field.attrs.is_empty() {
1037+
field.attrs[0].span.lo
1038+
} else {
1039+
field.span.lo
1040+
}
1041+
},
10451042
|field| field.ty.span.hi,
10461043
|field| field.rewrite(context, Shape::legacy(item_budget, item_indent)),
10471044
context.codemap.span_after(span, "("),
@@ -1920,13 +1917,13 @@ fn rewrite_generics(context: &RewriteContext,
19201917

19211918
// Extract comments between generics.
19221919
let lt_spans = lifetimes.iter().map(|l| {
1923-
let hi = if l.bounds.is_empty() {
1924-
l.lifetime.span.hi
1925-
} else {
1926-
l.bounds[l.bounds.len() - 1].span.hi
1927-
};
1928-
mk_sp(l.lifetime.span.lo, hi)
1929-
});
1920+
let hi = if l.bounds.is_empty() {
1921+
l.lifetime.span.hi
1922+
} else {
1923+
l.bounds[l.bounds.len() - 1].span.hi
1924+
};
1925+
mk_sp(l.lifetime.span.lo, hi)
1926+
});
19301927
let ty_spans = tys.iter().map(span_for_ty_param);
19311928

19321929
let items = itemize_list(context.codemap,

src/types.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,21 @@ impl Rewrite for ast::WherePredicate {
357357
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
358358
// TODO: dead spans?
359359
let result = match *self {
360-
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate { ref bound_lifetimes,
361-
ref bounded_ty,
362-
ref bounds,
363-
.. }) => {
360+
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
361+
ref bound_lifetimes,
362+
ref bounded_ty,
363+
ref bounds,
364+
..
365+
}) => {
364366
let type_str = try_opt!(bounded_ty.rewrite(context, shape));
365367

366368
let colon = type_bound_colon(context);
367369

368370
if !bound_lifetimes.is_empty() {
369371
let lifetime_str: String = try_opt!(bound_lifetimes.iter()
370-
.map(|lt| {
371-
lt.rewrite(context, shape)
372-
})
373-
.intersperse(Some(", ".to_string()))
374-
.collect());
372+
.map(|lt| lt.rewrite(context, shape))
373+
.intersperse(Some(", ".to_string()))
374+
.collect());
375375

376376
// 6 = "for<> ".len()
377377
let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
@@ -386,7 +386,11 @@ impl Rewrite for ast::WherePredicate {
386386
.collect());
387387

388388
if context.config.spaces_within_angle_brackets && lifetime_str.len() > 0 {
389-
format!("for< {} > {}{}{}", lifetime_str, type_str, colon, bounds_str)
389+
format!("for< {} > {}{}{}",
390+
lifetime_str,
391+
type_str,
392+
colon,
393+
bounds_str)
390394
} else {
391395
format!("for<{}> {}{}{}", lifetime_str, type_str, colon, bounds_str)
392396
}
@@ -405,14 +409,18 @@ impl Rewrite for ast::WherePredicate {
405409
format!("{}{}{}", type_str, colon, bounds_str)
406410
}
407411
}
408-
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate { ref lifetime,
409-
ref bounds,
410-
.. }) => {
412+
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
413+
ref lifetime,
414+
ref bounds,
415+
..
416+
}) => {
411417
try_opt!(rewrite_bounded_lifetime(lifetime, bounds.iter(), context, shape))
412418
}
413-
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate { ref lhs_ty,
414-
ref rhs_ty,
415-
.. }) => {
419+
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
420+
ref lhs_ty,
421+
ref rhs_ty,
422+
..
423+
}) => {
416424
let lhs_ty_str = try_opt!(lhs_ty.rewrite(context, shape));
417425
// 3 = " = ".len()
418426
let used_width = 3 + lhs_ty_str.len();

tests/source/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ fn arrays() {
174174
let xy = [ strukt { test123: value_one_two_three_four, turbo: coolio(), } , /* comment */ 1 ];
175175

176176
let a =WeightedChoice::new(&mut [Weighted {
177-
weight: x,
177+
weightweight: x,
178178
item: 0,
179179
},
180180
Weighted {
181-
weight: 1,
181+
weightweight: 1,
182182
item: 1,
183183
},
184184
Weighted {
185-
weight: x,
185+
weightweight: x,
186186
item: 2,
187187
},
188188
Weighted {
189-
weight: 1,
189+
weightweight: 1,
190190
item: 3,
191191
}]);
192192

tests/target/expr-block.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,10 @@ fn arrays() {
9595
];
9696

9797
let a = WeightedChoice::new(&mut [
98-
Weighted {
99-
weight: x,
100-
item: 0,
101-
},
102-
Weighted {
103-
weight: 1,
104-
item: 1,
105-
},
106-
Weighted {
107-
weight: x,
108-
item: 2,
109-
},
110-
Weighted {
111-
weight: 1,
112-
item: 3,
113-
},
98+
Weighted { weight: x, item: 0 },
99+
Weighted { weight: 1, item: 1 },
100+
Weighted { weight: x, item: 2 },
101+
Weighted { weight: 1, item: 3 },
114102
]);
115103

116104
let z =

tests/target/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ fn arrays() {
174174
1];
175175

176176
let a = WeightedChoice::new(&mut [Weighted {
177-
weight: x,
177+
weightweight: x,
178178
item: 0,
179179
},
180180
Weighted {
181-
weight: 1,
181+
weightweight: 1,
182182
item: 1,
183183
},
184184
Weighted {
185-
weight: x,
185+
weightweight: x,
186186
item: 2,
187187
},
188188
Weighted {
189-
weight: 1,
189+
weightweight: 1,
190190
item: 3,
191191
}]);
192192

0 commit comments

Comments
 (0)