Merge pull request #1861 from topecongiro/refactor-chain

Remove unnecessary rewriting
This commit is contained in:
Nick Cameron 2017-08-10 09:03:45 +12:00 committed by GitHub
commit 62689ef568
13 changed files with 185 additions and 300 deletions

View File

@ -98,40 +98,31 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
if chain_only_try(&subexpr_list) {
return rewrite_try(&parent, subexpr_list.len(), context, shape);
}
let trailing_try_num = subexpr_list
.iter()
.take_while(|e| match e.node {
ast::ExprKind::Try(..) => true,
_ => false,
})
.count();
let suffix_try_num = subexpr_list.iter().take_while(|e| is_try(e)).count();
let prefix_try_num = subexpr_list.iter().rev().take_while(|e| is_try(e)).count();
// Parent is the first item in the chain, e.g., `foo` in `foo.bar.baz()`.
let parent_shape = if is_block_expr(context, &parent, "\n") {
match context.config.chain_indent() {
IndentStyle::Visual => shape.visual_indent(0),
IndentStyle::Block => shape.block(),
IndentStyle::Block => shape,
}
} else {
shape
};
let parent_rewrite = try_opt!(parent.rewrite(context, parent_shape));
let parent_rewrite = try_opt!(
parent
.rewrite(context, parent_shape)
.map(|parent_rw| parent_rw + &repeat_try(prefix_try_num))
);
let parent_rewrite_contains_newline = parent_rewrite.contains('\n');
let is_small_parent = parent_rewrite.len() <= context.config.tab_spaces();
// Decide how to layout the rest of the chain. `extend` is true if we can
// put the first non-parent item on the same line as the parent.
let first_subexpr_is_try = subexpr_list.last().map_or(false, is_try);
let (nested_shape, extend) = if !parent_rewrite_contains_newline && is_continuable(&parent) {
let nested_shape = if first_subexpr_is_try {
parent_shape
.block_indent(context.config.tab_spaces())
.with_max_width(context.config)
} else {
chain_indent(context, shape.add_offset(parent_rewrite.len()))
};
(
nested_shape,
chain_indent(context, shape.add_offset(parent_rewrite.len())),
context.config.chain_indent() == IndentStyle::Visual || is_small_parent,
)
} else if is_block_expr(context, &parent, &parent_rewrite) {
@ -142,13 +133,9 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
// brace.
IndentStyle::Visual => (parent_shape, false),
}
} else if parent_rewrite_contains_newline {
(chain_indent(context, parent_shape), false)
} else {
(
shape
.block_indent(context.config.tab_spaces())
.with_max_width(context.config),
chain_indent(context, shape.add_offset(parent_rewrite.len())),
false,
)
};
@ -171,10 +158,13 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
other_child_shape
);
let child_shape_iter = Some(first_child_shape).into_iter().chain(
::std::iter::repeat(other_child_shape).take(subexpr_list.len() - 1),
);
let iter = subexpr_list.iter().rev().zip(child_shape_iter);
let child_shape_iter = Some(first_child_shape)
.into_iter()
.chain(iter::repeat(other_child_shape));
let subexpr_num = subexpr_list.len();
let last_subexpr = &subexpr_list[suffix_try_num];
let subexpr_list = &subexpr_list[suffix_try_num..subexpr_num - prefix_try_num];
let iter = subexpr_list.iter().skip(1).rev().zip(child_shape_iter);
let mut rewrites = try_opt!(
iter.map(|(e, shape)| {
rewrite_chain_subexpr(e, total_span, context, shape)
@ -182,84 +172,46 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
);
// Total of all items excluding the last.
let last_non_try_index = rewrites.len() - (1 + trailing_try_num);
let almost_total = rewrites[..last_non_try_index]
.iter()
.fold(0, |a, b| a + first_line_width(b)) + parent_rewrite.len();
let one_line_len =
rewrites.iter().fold(0, |a, r| a + first_line_width(r)) + parent_rewrite.len();
let one_line_budget = min(shape.width, context.config.chain_one_line_max());
let veto_single_line = if one_line_len > one_line_budget {
if rewrites.len() > 1 {
true
} else if rewrites.len() == 1 {
context.config.chain_split_single_child() || one_line_len > shape.width
} else {
false
}
} else if context.config.take_source_hints() && subexpr_list.len() > 1 {
// Look at the source code. Unless all chain elements start on the same
// line, we won't consider putting them on a single line either.
let last_span = context.snippet(mk_sp(subexpr_list[1].span.hi, total_span.hi));
let first_span = context.snippet(subexpr_list[1].span);
let last_iter = last_span.chars().take_while(|c| c.is_whitespace());
first_span.chars().chain(last_iter).any(|c| c == '\n')
let extend_last_subexr = last_line_extendable(&parent_rewrite) && rewrites.is_empty();
let almost_total = if extend_last_subexr {
last_line_width(&parent_rewrite)
} else {
false
rewrites.iter().fold(0, |a, b| a + b.len()) + parent_rewrite.len()
};
let mut fits_single_line = !veto_single_line && almost_total <= shape.width;
if fits_single_line {
let len = rewrites.len();
let (init, last) = rewrites.split_at_mut(len - (1 + trailing_try_num));
fits_single_line = init.iter().all(|s| !s.contains('\n'));
if fits_single_line {
fits_single_line = match expr.node {
ref e @ ast::ExprKind::MethodCall(..) => {
if rewrite_method_call_with_overflow(
e,
&mut last[0],
almost_total,
total_span,
context,
shape,
) {
// If the first line of the last method does not fit into a single line
// after the others, allow new lines.
almost_total + first_line_width(&last[0]) < context.config.max_width()
} else {
false
let one_line_budget = if rewrites.is_empty() && !context.config.chain_split_single_child() {
shape.width
} else {
min(shape.width, context.config.chain_one_line_max())
};
let all_in_one_line = !parent_rewrite_contains_newline &&
rewrites.iter().all(|s| !s.contains('\n')) &&
almost_total < one_line_budget;
let rewrite_last = || rewrite_chain_subexpr(last_subexpr, total_span, context, nested_shape);
let (last_subexpr_str, fits_single_line) = try_opt!(if all_in_one_line || extend_last_subexr {
parent_shape.offset_left(almost_total).map(|shape| {
if let Some(rw) = rewrite_chain_subexpr(last_subexpr, total_span, context, shape) {
let line_count = rw.lines().count();
let fits_single_line = almost_total + first_line_width(&rw) <= one_line_budget;
if (line_count >= 5 && fits_single_line) || extend_last_subexr {
(Some(rw), true)
} else {
match rewrite_last() {
Some(ref new_rw) if !fits_single_line => (Some(new_rw.clone()), false),
Some(ref new_rw) if new_rw.lines().count() >= line_count => {
(Some(rw), fits_single_line)
}
new_rw @ Some(..) => (new_rw, false),
_ => (Some(rw), fits_single_line),
}
}
_ => !last[0].contains('\n'),
} else {
(rewrite_last(), false)
}
}
}
// Try overflowing the last element if we are using block indent and it goes multi line
// or it fits in a single line but goes over the max width.
if !fits_single_line && context.use_block_indent() {
let (init, last) = rewrites.split_at_mut(last_non_try_index);
let almost_single_line = init.iter().all(|s| !s.contains('\n'));
if almost_single_line && last[0].contains('\n') {
let overflow_shape = Shape {
width: one_line_budget,
..parent_shape
};
fits_single_line = rewrite_last_child_with_overflow(
context,
&subexpr_list[trailing_try_num],
overflow_shape,
total_span,
almost_total,
one_line_budget,
&mut last[0],
);
}
}
})
} else {
Some((rewrite_last(), false))
});
rewrites.push(try_opt!(last_subexpr_str));
let connector = if fits_single_line && !parent_rewrite_contains_newline {
// Yay, we can put everything on one line.
@ -272,52 +224,42 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
format!("\n{}", nested_shape.indent.to_string(context.config))
};
let first_connector = choose_first_connector(
context,
&parent_rewrite,
&rewrites[0],
&connector,
&subexpr_list,
extend,
);
let first_connector = if is_small_parent || fits_single_line ||
last_line_extendable(&parent_rewrite) ||
context.config.chain_indent() == IndentStyle::Visual
{
""
} else {
connector.as_str()
};
if is_small_parent && rewrites.len() > 1 {
let result = if is_small_parent && rewrites.len() > 1 {
let second_connector = choose_first_connector(
context,
&rewrites[0],
&rewrites[1],
&connector,
&subexpr_list[0..subexpr_list.len() - 1],
&subexpr_list[..subexpr_num - 1],
false,
);
wrap_str(
format!(
"{}{}{}{}{}",
parent_rewrite,
first_connector,
rewrites[0],
second_connector,
join_rewrites(
&rewrites[1..],
&subexpr_list[0..subexpr_list.len() - 1],
&connector,
)
),
context.config.max_width(),
shape,
format!(
"{}{}{}{}{}",
parent_rewrite,
first_connector,
rewrites[0],
second_connector,
join_rewrites(&rewrites[1..], &subexpr_list[..subexpr_num - 1], &connector)
)
} else {
wrap_str(
format!(
"{}{}{}",
parent_rewrite,
first_connector,
join_rewrites(&rewrites, &subexpr_list, &connector)
),
context.config.max_width(),
shape,
format!(
"{}{}{}",
parent_rewrite,
first_connector,
join_rewrites(&rewrites, &subexpr_list, &connector)
)
}
};
let result = format!("{}{}", result, repeat_try(suffix_try_num));
wrap_str(result, context.config.max_width(), shape)
}
fn is_extendable_parent(context: &RewriteContext, parent_str: &str) -> bool {
@ -335,38 +277,18 @@ fn chain_only_try(exprs: &[ast::Expr]) -> bool {
// Try to rewrite and replace the last non-try child. Return `true` if
// replacing succeeds.
fn rewrite_last_child_with_overflow(
context: &RewriteContext,
expr: &ast::Expr,
shape: Shape,
span: Span,
almost_total: usize,
one_line_budget: usize,
last_child: &mut String,
) -> bool {
if let Some(shape) = shape.shrink_left(almost_total) {
if let Some(ref mut rw) = rewrite_chain_subexpr(expr, span, context, shape) {
if almost_total + first_line_width(rw) <= one_line_budget && rw.lines().count() > 3 {
::std::mem::swap(last_child, rw);
return true;
}
}
}
false
fn repeat_try(try_count: usize) -> String {
iter::repeat("?").take(try_count).collect::<String>()
}
pub fn rewrite_try(
fn rewrite_try(
expr: &ast::Expr,
try_count: usize,
context: &RewriteContext,
shape: Shape,
) -> Option<String> {
let sub_expr = try_opt!(expr.rewrite(context, try_opt!(shape.sub_width(try_count))));
Some(format!(
"{}{}",
sub_expr,
iter::repeat("?").take(try_count).collect::<String>()
))
Some(format!("{}{}", sub_expr, repeat_try(try_count)))
}
fn join_rewrites(rewrites: &[String], subexps: &[ast::Expr], connector: &str) -> String {
@ -426,47 +348,9 @@ fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext) -> (ast::Expr,
fn chain_indent(context: &RewriteContext, shape: Shape) -> Shape {
match context.config.chain_indent() {
IndentStyle::Visual => shape.visual_indent(0),
IndentStyle::Block => shape.block_indent(context.config.tab_spaces()),
}
}
fn rewrite_method_call_with_overflow(
expr_kind: &ast::ExprKind,
last: &mut String,
almost_total: usize,
total_span: Span,
context: &RewriteContext,
shape: Shape,
) -> bool {
if let &ast::ExprKind::MethodCall(ref segment, ref expressions) = expr_kind {
let shape = match shape.shrink_left(almost_total) {
Some(b) => b,
None => return false,
};
let types = match segment.parameters {
Some(ref params) => match **params {
ast::PathParameters::AngleBracketed(ref data) => &data.types[..],
_ => &[],
},
_ => &[],
};
let mut last_rewrite = rewrite_method_call(
segment.identifier,
types,
expressions,
total_span,
context,
shape,
);
if let Some(ref mut s) = last_rewrite {
::std::mem::swap(s, last);
true
} else {
false
}
} else {
unreachable!();
IndentStyle::Block => shape
.block_indent(context.config.tab_spaces())
.with_max_width(context.config),
}
}

View File

@ -466,6 +466,7 @@ where
|item| item.rewrite(context, nested_shape),
span.lo,
span.hi,
false,
).collect::<Vec<_>>();
if items.is_empty() {
@ -587,6 +588,7 @@ fn rewrite_closure_fn_decl(
|arg| arg.rewrite(context, arg_shape),
context.codemap.span_after(span, "|"),
body.span.lo,
false,
);
let item_vec = arg_items.collect::<Vec<_>>();
// 1 = space between arguments and return type.
@ -1130,10 +1132,7 @@ impl<'a> ControlFlow<'a> {
let new_width = try_opt!(width.checked_sub(pat_expr_str.len() + fixed_cost));
let expr = &self.block.stmts[0];
let if_str = try_opt!(expr.rewrite(
context,
Shape::legacy(new_width, Indent::empty()),
));
let if_str = try_opt!(expr.rewrite(context, Shape::legacy(new_width, Indent::empty())));
let new_width = try_opt!(new_width.checked_sub(if_str.len()));
let else_expr = &else_node.stmts[0];
@ -1246,14 +1245,12 @@ impl<'a> ControlFlow<'a> {
// for event in event
let between_kwd_cond = mk_sp(
context.codemap.span_after(self.span, self.keyword.trim()),
self.pat.map_or(
cond_span.lo,
|p| if self.matcher.is_empty() {
self.pat
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
p.span.lo
} else {
context.codemap.span_before(self.span, self.matcher.trim())
},
),
}),
);
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);
@ -2194,6 +2191,7 @@ where
|item| item.rewrite(context, shape),
span.lo,
span.hi,
true,
);
let mut item_vec: Vec<_> = items.collect();
@ -2245,7 +2243,7 @@ where
// Replace the last item with its first line to see if it fits with
// first arguments.
let (orig_last, placeholder) = if overflow_last {
let placeholder = if overflow_last {
let mut context = context.clone();
if let Some(expr) = args[args.len() - 1].to_expr() {
match expr.node {
@ -2253,20 +2251,14 @@ where
_ => (),
}
}
last_arg_shape(&context, &item_vec, shape, args_max_width)
.map_or((None, None), |arg_shape| {
rewrite_last_arg_with_overflow(
&context,
args,
&mut item_vec[args.len() - 1],
arg_shape,
)
})
last_arg_shape(&context, &item_vec, shape, args_max_width).and_then(|arg_shape| {
rewrite_last_arg_with_overflow(&context, args, &mut item_vec[args.len() - 1], arg_shape)
})
} else {
(None, None)
None
};
let tactic = definitive_tactic(
let mut tactic = definitive_tactic(
&*item_vec,
ListTactic::LimitedHorizontalVertical(args_max_width),
Separator::Comma,
@ -2279,10 +2271,17 @@ where
(true, DefinitiveListTactic::Horizontal, placeholder @ Some(..)) => {
item_vec[args.len() - 1].item = placeholder;
}
(true, _, _) => {
item_vec[args.len() - 1].item = orig_last;
_ if args.len() >= 1 => {
item_vec[args.len() - 1].item = args.last()
.and_then(|last_arg| last_arg.rewrite(context, shape));
tactic = definitive_tactic(
&*item_vec,
ListTactic::LimitedHorizontalVertical(args_max_width),
Separator::Comma,
one_line_width,
);
}
(false, _, _) => {}
_ => (),
}
tactic
@ -2357,7 +2356,7 @@ fn rewrite_last_arg_with_overflow<'a, T>(
args: &[&T],
last_item: &mut ListItem,
shape: Shape,
) -> (Option<String>, Option<String>)
) -> Option<String>
where
T: Rewrite + Spanned + ToExpr + 'a,
{
@ -2388,14 +2387,13 @@ where
} else {
last_arg.rewrite(context, shape)
};
let orig_last = last_item.item.clone();
if let Some(rewrite) = rewrite {
let rewrite_first_line = Some(rewrite[..first_line_width(&rewrite)].to_owned());
last_item.item = rewrite_first_line;
(orig_last, Some(rewrite))
Some(rewrite)
} else {
(orig_last, None)
None
}
}
@ -2653,6 +2651,7 @@ fn rewrite_struct_lit<'a>(
rewrite,
body_lo,
span.hi,
false,
);
let item_vec = items.collect::<Vec<_>>();
@ -2805,6 +2804,7 @@ where
|item| item.rewrite(context, nested_shape),
list_lo,
span.hi - BytePos(1),
false,
);
let item_vec: Vec<_> = items.collect();
let tactic = definitive_tactic(

View File

@ -447,6 +447,7 @@ fn rewrite_use_list(
rewrite_path_item,
context.codemap.span_after(span, "{"),
span.hi,
false,
);
items.extend(iter);
items

View File

@ -469,6 +469,7 @@ impl<'a> FmtVisitor<'a> {
|f| self.format_variant(f),
body_lo,
body_hi,
false,
);
let shape = Shape::indented(self.block_indent, self.config)
@ -2207,6 +2208,7 @@ fn rewrite_args(
},
comment_span_start,
span.hi,
false,
);
arg_items.extend(more_items);
@ -2411,6 +2413,7 @@ fn rewrite_generics_inner(
|&(_, ref str)| str.clone(),
context.codemap.span_after(span, "<"),
span.hi,
false,
);
format_generics_item_list(context, items, shape, one_line_width)
}
@ -2554,6 +2557,7 @@ fn rewrite_where_clause_rfc_style(
|pred| pred.rewrite(context, block_shape),
span_start,
span_end,
false,
);
let comma_tactic = if where_clause_option.suppress_comma {
SeparatorTactic::Never
@ -2654,6 +2658,7 @@ fn rewrite_where_clause(
|pred| pred.rewrite(context, Shape::legacy(budget, offset)),
span_start,
span_end,
false,
);
let item_vec = items.collect::<Vec<_>>();
// FIXME: we don't need to collect here if the where_layout isn't

View File

@ -454,6 +454,7 @@ where
prev_span_end: BytePos,
next_span_start: BytePos,
terminator: &'a str,
leave_last: bool,
}
impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
@ -592,7 +593,11 @@ where
ListItem {
pre_comment: pre_comment,
pre_comment_style: pre_comment_style,
item: (self.get_item_string)(&item),
item: if self.inner.peek().is_none() && self.leave_last {
None
} else {
(self.get_item_string)(&item)
},
post_comment: post_comment,
new_lines: new_lines,
}
@ -610,6 +615,7 @@ pub fn itemize_list<'a, T, I, F1, F2, F3>(
get_item_string: F3,
prev_span_end: BytePos,
next_span_start: BytePos,
leave_last: bool,
) -> ListItems<'a, I, F1, F2, F3>
where
I: Iterator<Item = T>,
@ -626,6 +632,7 @@ where
prev_span_end: prev_span_end,
next_span_start: next_span_start,
terminator: terminator,
leave_last: leave_last,
}
}

View File

@ -146,10 +146,11 @@ impl<'a> FmtVisitor<'a> {
let subslice_num_lines = subslice.chars().filter(|c| *c == '\n').count();
if rewrite_next_comment &&
!self.config
.file_lines()
.intersects_range(file_name, cur_line, cur_line + subslice_num_lines)
{
!self.config.file_lines().intersects_range(
file_name,
cur_line,
cur_line + subslice_num_lines,
) {
rewrite_next_comment = false;
}

View File

@ -162,6 +162,7 @@ fn rewrite_struct_pat(
|f| f.node.rewrite(context, v_shape),
context.codemap.span_after(span, "{"),
span.hi,
false,
);
let item_vec = items.collect::<Vec<_>>();
@ -342,6 +343,7 @@ fn count_wildcard_suffix_len(
|item| item.rewrite(context, shape),
context.codemap.span_after(span, "("),
span.hi - BytePos(1),
false,
).collect();
for item in items.iter().rev().take_while(|i| match i.item {

View File

@ -241,6 +241,7 @@ fn rewrite_segment(
|seg| seg.rewrite(context, generics_shape),
list_lo,
span_hi,
false,
);
let generics_str = try_opt!(format_generics_item_list(
context,
@ -344,6 +345,7 @@ where
},
list_lo,
span.hi,
false,
);
let item_vec: Vec<_> = items.collect();
@ -553,10 +555,7 @@ impl Rewrite for ast::TyParamBound {
let budget = try_opt!(shape.width.checked_sub(1));
Some(format!(
"?{}",
try_opt!(tref.rewrite(
context,
Shape::legacy(budget, shape.indent + 1),
))
try_opt!(tref.rewrite(context, Shape::legacy(budget, shape.indent + 1)))
))
}
ast::TyParamBound::RegionTyParamBound(ref l) => l.rewrite(context, shape),
@ -609,10 +608,8 @@ impl Rewrite for ast::TyParam {
};
result.push_str(eq_str);
let budget = try_opt!(shape.width.checked_sub(result.len()));
let rewrite = try_opt!(def.rewrite(
context,
Shape::legacy(budget, shape.indent + result.len()),
));
let rewrite =
try_opt!(def.rewrite(context, Shape::legacy(budget, shape.indent + result.len())));
result.push_str(&rewrite);
}

View File

@ -174,13 +174,13 @@ fn struct_field_preix_max_min_width<T: AlignedItem>(
fields
.iter()
.map(|field| {
field.rewrite_prefix(context, shape).and_then(
|field_str| if field_str.contains('\n') {
field
.rewrite_prefix(context, shape)
.and_then(|field_str| if field_str.contains('\n') {
None
} else {
Some(field_str.len())
},
)
})
})
.fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
(Some((max_len, min_len)), Some(len)) => {
@ -219,6 +219,7 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
|field| field.rewrite_aligned_item(context, item_shape, field_prefix_max_width),
span.lo,
span.hi,
false,
).collect::<Vec<_>>();
let tactic = definitive_tactic(

View File

@ -850,6 +850,7 @@ impl Rewrite for ast::MetaItem {
|nested_meta_item| nested_meta_item.rewrite(context, item_shape),
self.span.lo,
hi,
false,
);
let item_vec = items.collect::<Vec<_>>();
let fmt = ListFormatting {
@ -887,8 +888,9 @@ impl Rewrite for ast::MetaItem {
impl Rewrite for ast::Attribute {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
try_opt!(self.meta()).rewrite(context, shape).map(
|rw| if self.is_sugared_doc {
try_opt!(self.meta())
.rewrite(context, shape)
.map(|rw| if self.is_sugared_doc {
rw
} else {
let original = context.snippet(self.span);
@ -901,8 +903,7 @@ impl Rewrite for ast::Attribute {
} else {
format!("{}[{}]", prefix, rw)
}
},
)
})
}
}

View File

@ -1,10 +1,9 @@
// rustfmt-chain_indent: Visual
fn test() {
let x = my_long_function()
.my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
.do_it();
let x = my_long_function().my_even_longer_function()
.my_nested_function()
.some_random_name()
.another_function()
.do_it();
}

View File

@ -32,15 +32,14 @@ fn main() {
x
});
some_fuuuuuuuuunction()
.method_call_a(aaaaa, bbbbb, |c| {
let x = c;
x
})
.method_call_b(aaaaa, bbbbb, |c| {
let x = c;
x
});
some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
let x = c;
x
})
.method_call_b(aaaaa, bbbbb, |c| {
let x = c;
x
});
fffffffffffffffffffffffffffffffffff(a, {
SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
@ -67,16 +66,14 @@ fn floaters() {
let x = Foo {
field1: val1,
field2: val2,
}
.method_call()
}.method_call()
.method_call();
let y = if cond {
val1
} else {
val2
}
.method_call();
}.method_call();
{
match x {
@ -86,8 +83,7 @@ fn floaters() {
mparams[match cur.to_digit(10) {
Some(d) => d as usize - 1,
None => return Err("bad param number".to_owned()),
}]
.clone(),
}].clone(),
);
}
}
@ -97,22 +93,19 @@ fn floaters() {
some();
} else {
none();
}
.bar()
}.bar()
.baz();
Foo { x: val }
.baz(|| {
force();
multiline();
})
.quux();
Foo { x: val }.baz(|| {
force();
multiline();
})
.quux();
Foo {
y: i_am_multi_line,
z: ok,
}
.baz(|| {
}.baz(|| {
force();
multiline();
})
@ -121,8 +114,7 @@ fn floaters() {
a + match x {
true => "yay!",
false => "boo!",
}
.bar()
}.bar()
}
fn is_replaced_content() -> bool {
@ -137,33 +129,30 @@ fn issue587() {
}
fn issue_1389() {
let names = String::from_utf8(names)?
.split('|')
.map(str::to_owned)
.collect();
let names = String::from_utf8(names)?.split('|')
.map(str::to_owned)
.collect();
}
fn issue1217() -> Result<Mnemonic, Error> {
let random_chars: String = OsRng::new()?
.gen_ascii_chars()
.take(self.bit_length)
.collect();
let random_chars: String = OsRng::new()?.gen_ascii_chars()
.take(self.bit_length)
.collect();
Ok(Mnemonic::new(&random_chars))
}
fn issue1236(options: Vec<String>) -> Result<Option<String>> {
let process = Command::new("dmenu")
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.chain_err(|| "failed to spawn dmenu")?;
let process = Command::new("dmenu").stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()
.chain_err(|| "failed to spawn dmenu")?;
}
fn issue1434() {
for _ in 0..100 {
let prototype_id = PrototypeIdData::from_reader::<_, B>(&mut self.file_cursor)
.chain_err(|| {
let prototype_id =
PrototypeIdData::from_reader::<_, B>(&mut self.file_cursor).chain_err(|| {
format!(
"could not read prototype ID at offset {:#010x}",
current_offset

View File

@ -389,9 +389,7 @@ fn issue1395() {
fn issue1456() {
Ok(Recording {
artists: match reader
.evaluate(".//mb:recording/mb:artist-credit/mb:name-credit")?
{
artists: match reader.evaluate(".//mb:recording/mb:artist-credit/mb:name-credit")? {
Nodeset(nodeset) => {
let res: Result<Vec<ArtistRef>, ReadError> = nodeset
.iter()