mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-10 23:54:58 +00:00
Test and source fallout
This commit is contained in:
parent
4bb31a7231
commit
488c0b9546
@ -219,7 +219,10 @@ fn execute(opts: &Options) -> FmtResult<Summary> {
|
||||
|
||||
Ok(run(Input::Text(input), &config))
|
||||
}
|
||||
Operation::Format { mut files, config_path } => {
|
||||
Operation::Format {
|
||||
mut files,
|
||||
config_path,
|
||||
} => {
|
||||
let options = try!(CliOptions::from_matches(&matches));
|
||||
|
||||
// Add any additional files that were specified via `--file-lines`.
|
||||
|
@ -130,7 +130,10 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
|
||||
.checked_sub(nested_shape.indent.width() +
|
||||
nested_shape.offset));
|
||||
|
||||
let other_child_shape = Shape { width: max_width, ..nested_shape };
|
||||
let other_child_shape = Shape {
|
||||
width: max_width,
|
||||
..nested_shape
|
||||
};
|
||||
let first_child_shape = if extend {
|
||||
let mut shape = try_opt!(parent_shape.shrink_left(last_line_width(&parent_rewrite)));
|
||||
match context.config.chain_indent {
|
||||
|
47
src/expr.rs
47
src/expr.rs
@ -19,8 +19,8 @@ use {Indent, Shape, Spanned};
|
||||
use codemap::SpanUtils;
|
||||
use rewrite::{Rewrite, RewriteContext};
|
||||
use lists::{write_list, itemize_list, ListFormatting, SeparatorTactic, ListTactic,
|
||||
DefinitiveListTactic, definitive_tactic, ListItem, format_item_list,
|
||||
struct_lit_shape, struct_lit_tactic, shape_for_tactic, struct_lit_formatting};
|
||||
DefinitiveListTactic, definitive_tactic, ListItem, format_item_list, struct_lit_shape,
|
||||
struct_lit_tactic, shape_for_tactic, struct_lit_formatting};
|
||||
use string::{StringFormat, rewrite_string};
|
||||
use utils::{extra_offset, last_line_width, wrap_str, binary_search, first_line_width,
|
||||
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,
|
||||
.visual_indent(prefix.len());
|
||||
|
||||
let rhs_result = try_opt!(rhs.rewrite(context, rhs_shape));
|
||||
let lhs_result = try_opt!(lhs.rewrite(context, Shape { width: lhs_budget, ..shape }));
|
||||
let lhs_result = try_opt!(lhs.rewrite(context,
|
||||
Shape {
|
||||
width: lhs_budget,
|
||||
..shape
|
||||
}));
|
||||
Some(format!("{}{}{}\n{}{}{}",
|
||||
prefix,
|
||||
lhs_result,
|
||||
@ -658,9 +662,7 @@ impl Rewrite for ast::Block {
|
||||
impl Rewrite for ast::Stmt {
|
||||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
let result = match self.node {
|
||||
ast::StmtKind::Local(ref local) => {
|
||||
local.rewrite(context, shape)
|
||||
}
|
||||
ast::StmtKind::Local(ref local) => local.rewrite(context, shape),
|
||||
ast::StmtKind::Expr(ref ex) |
|
||||
ast::StmtKind::Semi(ref ex) => {
|
||||
let suffix = if semicolon_for_stmt(self) { ";" } else { "" };
|
||||
@ -893,7 +895,10 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
||||
block_width
|
||||
};
|
||||
|
||||
let block_shape = Shape { width: block_width, ..shape };
|
||||
let block_shape = Shape {
|
||||
width: block_width,
|
||||
..shape
|
||||
};
|
||||
let block_str = try_opt!(self.block.rewrite(context, block_shape));
|
||||
|
||||
let cond_span = if let Some(cond) = self.cond {
|
||||
@ -975,7 +980,10 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
||||
last_in_chain = true;
|
||||
// When rewriting a block, the width is only used for single line
|
||||
// blocks, passing 1 lets us avoid that.
|
||||
let else_shape = Shape { width: min(1, shape.width), ..shape };
|
||||
let else_shape = Shape {
|
||||
width: min(1, shape.width),
|
||||
..shape
|
||||
};
|
||||
else_block.rewrite(context, else_shape)
|
||||
}
|
||||
};
|
||||
@ -1175,7 +1183,11 @@ fn rewrite_match(context: &RewriteContext,
|
||||
}
|
||||
|
||||
fn arm_start_pos(arm: &ast::Arm) -> BytePos {
|
||||
let &ast::Arm { ref attrs, ref pats, .. } = arm;
|
||||
let &ast::Arm {
|
||||
ref attrs,
|
||||
ref pats,
|
||||
..
|
||||
} = arm;
|
||||
if !attrs.is_empty() {
|
||||
return attrs[0].span.lo;
|
||||
}
|
||||
@ -1205,7 +1217,12 @@ fn arm_comma(config: &Config, body: &ast::Expr) -> &'static str {
|
||||
impl Rewrite for ast::Arm {
|
||||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
debug!("Arm::rewrite {:?} {:?}", self, shape);
|
||||
let &ast::Arm { ref attrs, ref pats, ref guard, ref body } = self;
|
||||
let &ast::Arm {
|
||||
ref attrs,
|
||||
ref pats,
|
||||
ref guard,
|
||||
ref body,
|
||||
} = self;
|
||||
|
||||
// FIXME this is all a bit grotty, would be nice to abstract out the
|
||||
// treatment of attributes.
|
||||
@ -1250,7 +1267,10 @@ impl Rewrite for ast::Arm {
|
||||
let pats_str = try_opt!(write_list(items, &fmt));
|
||||
|
||||
let guard_shape = if pats_str.contains('\n') {
|
||||
Shape { width: context.config.max_width - shape.indent.width(), ..shape }
|
||||
Shape {
|
||||
width: context.config.max_width - shape.indent.width(),
|
||||
..shape
|
||||
}
|
||||
} else {
|
||||
shape
|
||||
};
|
||||
@ -1598,7 +1618,10 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
|
||||
|item| item.span.hi,
|
||||
|item| {
|
||||
item.rewrite(context,
|
||||
Shape { width: remaining_width, ..nested_shape })
|
||||
Shape {
|
||||
width: remaining_width,
|
||||
..nested_shape
|
||||
})
|
||||
},
|
||||
span.lo,
|
||||
span.hi);
|
||||
|
@ -193,13 +193,13 @@ impl<'a> FmtVisitor<'a> {
|
||||
// before the current `self.last_pos`
|
||||
let pos_before_first_use_item = use_items.first()
|
||||
.map(|p_i| {
|
||||
cmp::max(self.last_pos,
|
||||
p_i.attrs
|
||||
.iter()
|
||||
.map(|attr| attr.span.lo)
|
||||
.min()
|
||||
.unwrap_or(p_i.span.lo))
|
||||
})
|
||||
cmp::max(self.last_pos,
|
||||
p_i.attrs
|
||||
.iter()
|
||||
.map(|attr| attr.span.lo)
|
||||
.min()
|
||||
.unwrap_or(p_i.span.lo))
|
||||
})
|
||||
.unwrap_or(self.last_pos);
|
||||
// Construct a list of pairs, each containing a `use` item and the start of span before
|
||||
// that `use` item.
|
||||
|
@ -98,7 +98,10 @@ impl BadIssueSeeker {
|
||||
// unnumbered TO-DO or FIX-ME.
|
||||
pub fn inspect(&mut self, c: char) -> Option<Issue> {
|
||||
match self.state {
|
||||
Seeking::Issue { todo_idx, fixme_idx } => {
|
||||
Seeking::Issue {
|
||||
todo_idx,
|
||||
fixme_idx,
|
||||
} => {
|
||||
self.state = self.inspect_issue(c, todo_idx, fixme_idx);
|
||||
}
|
||||
Seeking::Number { issue, part } => {
|
||||
|
47
src/items.rs
47
src/items.rs
@ -73,10 +73,7 @@ impl Rewrite for ast::Local {
|
||||
//let budget = try_opt!(shape.width.checked_sub(shape.indent.block_only().width() + 1));
|
||||
let nested_shape = try_opt!(shape.sub_width(1));
|
||||
|
||||
result = try_opt!(rewrite_assign_rhs(&context,
|
||||
result,
|
||||
ex,
|
||||
nested_shape));
|
||||
result = try_opt!(rewrite_assign_rhs(&context, result, ex, nested_shape));
|
||||
}
|
||||
|
||||
result.push(';');
|
||||
@ -932,13 +929,13 @@ fn format_struct_struct(context: &RewriteContext,
|
||||
fields.iter(),
|
||||
"}",
|
||||
|field| {
|
||||
// Include attributes and doc comments, if present
|
||||
if !field.attrs.is_empty() {
|
||||
field.attrs[0].span.lo
|
||||
} else {
|
||||
field.span.lo
|
||||
}
|
||||
},
|
||||
// Include attributes and doc comments, if present
|
||||
if !field.attrs.is_empty() {
|
||||
field.attrs[0].span.lo
|
||||
} else {
|
||||
field.span.lo
|
||||
}
|
||||
},
|
||||
|field| field.ty.span.hi,
|
||||
|field| field.rewrite(context, Shape::legacy(item_budget, item_indent)),
|
||||
context.codemap.span_after(span, "{"),
|
||||
@ -1035,13 +1032,13 @@ fn format_tuple_struct(context: &RewriteContext,
|
||||
fields.iter(),
|
||||
")",
|
||||
|field| {
|
||||
// Include attributes and doc comments, if present
|
||||
if !field.attrs.is_empty() {
|
||||
field.attrs[0].span.lo
|
||||
} else {
|
||||
field.span.lo
|
||||
}
|
||||
},
|
||||
// Include attributes and doc comments, if present
|
||||
if !field.attrs.is_empty() {
|
||||
field.attrs[0].span.lo
|
||||
} else {
|
||||
field.span.lo
|
||||
}
|
||||
},
|
||||
|field| field.ty.span.hi,
|
||||
|field| field.rewrite(context, Shape::legacy(item_budget, item_indent)),
|
||||
context.codemap.span_after(span, "("),
|
||||
@ -1920,13 +1917,13 @@ fn rewrite_generics(context: &RewriteContext,
|
||||
|
||||
// Extract comments between generics.
|
||||
let lt_spans = lifetimes.iter().map(|l| {
|
||||
let hi = if l.bounds.is_empty() {
|
||||
l.lifetime.span.hi
|
||||
} else {
|
||||
l.bounds[l.bounds.len() - 1].span.hi
|
||||
};
|
||||
mk_sp(l.lifetime.span.lo, hi)
|
||||
});
|
||||
let hi = if l.bounds.is_empty() {
|
||||
l.lifetime.span.hi
|
||||
} else {
|
||||
l.bounds[l.bounds.len() - 1].span.hi
|
||||
};
|
||||
mk_sp(l.lifetime.span.lo, hi)
|
||||
});
|
||||
let ty_spans = tys.iter().map(span_for_ty_param);
|
||||
|
||||
let items = itemize_list(context.codemap,
|
||||
|
40
src/types.rs
40
src/types.rs
@ -357,21 +357,21 @@ impl Rewrite for ast::WherePredicate {
|
||||
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
|
||||
// TODO: dead spans?
|
||||
let result = match *self {
|
||||
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate { ref bound_lifetimes,
|
||||
ref bounded_ty,
|
||||
ref bounds,
|
||||
.. }) => {
|
||||
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
|
||||
ref bound_lifetimes,
|
||||
ref bounded_ty,
|
||||
ref bounds,
|
||||
..
|
||||
}) => {
|
||||
let type_str = try_opt!(bounded_ty.rewrite(context, shape));
|
||||
|
||||
let colon = type_bound_colon(context);
|
||||
|
||||
if !bound_lifetimes.is_empty() {
|
||||
let lifetime_str: String = try_opt!(bound_lifetimes.iter()
|
||||
.map(|lt| {
|
||||
lt.rewrite(context, shape)
|
||||
})
|
||||
.intersperse(Some(", ".to_string()))
|
||||
.collect());
|
||||
.map(|lt| lt.rewrite(context, shape))
|
||||
.intersperse(Some(", ".to_string()))
|
||||
.collect());
|
||||
|
||||
// 6 = "for<> ".len()
|
||||
let used_width = lifetime_str.len() + type_str.len() + colon.len() + 6;
|
||||
@ -386,7 +386,11 @@ impl Rewrite for ast::WherePredicate {
|
||||
.collect());
|
||||
|
||||
if context.config.spaces_within_angle_brackets && lifetime_str.len() > 0 {
|
||||
format!("for< {} > {}{}{}", lifetime_str, type_str, colon, bounds_str)
|
||||
format!("for< {} > {}{}{}",
|
||||
lifetime_str,
|
||||
type_str,
|
||||
colon,
|
||||
bounds_str)
|
||||
} else {
|
||||
format!("for<{}> {}{}{}", lifetime_str, type_str, colon, bounds_str)
|
||||
}
|
||||
@ -405,14 +409,18 @@ impl Rewrite for ast::WherePredicate {
|
||||
format!("{}{}{}", type_str, colon, bounds_str)
|
||||
}
|
||||
}
|
||||
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate { ref lifetime,
|
||||
ref bounds,
|
||||
.. }) => {
|
||||
ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
|
||||
ref lifetime,
|
||||
ref bounds,
|
||||
..
|
||||
}) => {
|
||||
try_opt!(rewrite_bounded_lifetime(lifetime, bounds.iter(), context, shape))
|
||||
}
|
||||
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate { ref lhs_ty,
|
||||
ref rhs_ty,
|
||||
.. }) => {
|
||||
ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
|
||||
ref lhs_ty,
|
||||
ref rhs_ty,
|
||||
..
|
||||
}) => {
|
||||
let lhs_ty_str = try_opt!(lhs_ty.rewrite(context, shape));
|
||||
// 3 = " = ".len()
|
||||
let used_width = 3 + lhs_ty_str.len();
|
||||
|
@ -174,19 +174,19 @@ fn arrays() {
|
||||
let xy = [ strukt { test123: value_one_two_three_four, turbo: coolio(), } , /* comment */ 1 ];
|
||||
|
||||
let a =WeightedChoice::new(&mut [Weighted {
|
||||
weight: x,
|
||||
weightweight: x,
|
||||
item: 0,
|
||||
},
|
||||
Weighted {
|
||||
weight: 1,
|
||||
weightweight: 1,
|
||||
item: 1,
|
||||
},
|
||||
Weighted {
|
||||
weight: x,
|
||||
weightweight: x,
|
||||
item: 2,
|
||||
},
|
||||
Weighted {
|
||||
weight: 1,
|
||||
weightweight: 1,
|
||||
item: 3,
|
||||
}]);
|
||||
|
||||
|
@ -95,22 +95,10 @@ fn arrays() {
|
||||
];
|
||||
|
||||
let a = WeightedChoice::new(&mut [
|
||||
Weighted {
|
||||
weight: x,
|
||||
item: 0,
|
||||
},
|
||||
Weighted {
|
||||
weight: 1,
|
||||
item: 1,
|
||||
},
|
||||
Weighted {
|
||||
weight: x,
|
||||
item: 2,
|
||||
},
|
||||
Weighted {
|
||||
weight: 1,
|
||||
item: 3,
|
||||
},
|
||||
Weighted { weight: x, item: 0 },
|
||||
Weighted { weight: 1, item: 1 },
|
||||
Weighted { weight: x, item: 2 },
|
||||
Weighted { weight: 1, item: 3 },
|
||||
]);
|
||||
|
||||
let z =
|
||||
|
@ -174,19 +174,19 @@ fn arrays() {
|
||||
1];
|
||||
|
||||
let a = WeightedChoice::new(&mut [Weighted {
|
||||
weight: x,
|
||||
weightweight: x,
|
||||
item: 0,
|
||||
},
|
||||
Weighted {
|
||||
weight: 1,
|
||||
weightweight: 1,
|
||||
item: 1,
|
||||
},
|
||||
Weighted {
|
||||
weight: x,
|
||||
weightweight: x,
|
||||
item: 2,
|
||||
},
|
||||
Weighted {
|
||||
weight: 1,
|
||||
weightweight: 1,
|
||||
item: 3,
|
||||
}]);
|
||||
|
||||
|
@ -24,13 +24,24 @@ fn main() {
|
||||
let foo {} = 42;
|
||||
let foo { .. } = 42;
|
||||
let foo { x, y: ref foo, .. } = 42;
|
||||
let foo { x, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo, .. } = 42;
|
||||
let foo { x, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo } = 42;
|
||||
let foo { x,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,
|
||||
.. };
|
||||
let foo { x,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo };
|
||||
let foo {
|
||||
x,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,
|
||||
..
|
||||
} = 42;
|
||||
let foo {
|
||||
x,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,
|
||||
} = 42;
|
||||
let foo {
|
||||
x,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,
|
||||
..
|
||||
};
|
||||
let foo {
|
||||
x,
|
||||
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: ref foo,
|
||||
};
|
||||
}
|
||||
|
||||
impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
|
||||
|
Loading…
Reference in New Issue
Block a user