Merge pull request #3036 from topecongiro/issue-2932
Combine chain items only when the item gets orphaned otherwise
This commit is contained in:
commit
cd8549e013
35 changed files with 191 additions and 116 deletions
|
|
@ -229,7 +229,8 @@ impl Rewrite for ast::MetaItem {
|
|||
None,
|
||||
&inner_meta_item.ident,
|
||||
shape,
|
||||
).map_or(false, |s| s.len() + path.len() + 2 <= shape.width),
|
||||
)
|
||||
.map_or(false, |s| s.len() + path.len() + 2 <= shape.width),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -421,7 +421,8 @@ fn determine_operation(matches: &Matches) -> Result<Operation, ErrorKind> {
|
|||
// we will do comparison later, so here tries to canonicalize first
|
||||
// to get the expected behavior.
|
||||
p.canonicalize().unwrap_or(p)
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(Operation::Format {
|
||||
files,
|
||||
|
|
|
|||
|
|
@ -163,7 +163,8 @@ fn format_crate(
|
|||
if verbosity == Verbosity::Verbose {
|
||||
println!("[{}] {:?}", t.kind, t.path)
|
||||
}
|
||||
}).map(|t| t.path)
|
||||
})
|
||||
.map(|t| t.path)
|
||||
.collect();
|
||||
|
||||
run_rustfmt(&files, &rustfmt_args, verbosity)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@ use utils::{
|
|||
|
||||
use std::borrow::Cow;
|
||||
use std::cmp::min;
|
||||
use std::iter;
|
||||
|
||||
use syntax::source_map::{BytePos, Span};
|
||||
use syntax::{ast, ptr};
|
||||
|
|
@ -132,8 +131,8 @@ impl ChainItemKind {
|
|||
fn is_block_like(&self, context: &RewriteContext, reps: &str) -> bool {
|
||||
match self {
|
||||
ChainItemKind::Parent(ref expr) => is_block_expr(context, expr, reps),
|
||||
ChainItemKind::MethodCall(..) => reps.contains('\n'),
|
||||
ChainItemKind::StructField(..)
|
||||
ChainItemKind::MethodCall(..)
|
||||
| ChainItemKind::StructField(..)
|
||||
| ChainItemKind::TupleField(..)
|
||||
| ChainItemKind::Comment(..) => false,
|
||||
}
|
||||
|
|
@ -559,7 +558,8 @@ impl<'a> ChainFormatterShared<'a> {
|
|||
shape.width
|
||||
} else {
|
||||
min(shape.width, context.config.width_heuristics().chain_width)
|
||||
}.saturating_sub(almost_total);
|
||||
}
|
||||
.saturating_sub(almost_total);
|
||||
|
||||
let all_in_one_line = !self.children.iter().any(ChainItem::is_comment)
|
||||
&& self.rewrites.iter().all(|s| !s.contains('\n'))
|
||||
|
|
@ -625,12 +625,7 @@ impl<'a> ChainFormatterShared<'a> {
|
|||
Some(())
|
||||
}
|
||||
|
||||
fn join_rewrites(
|
||||
&self,
|
||||
context: &RewriteContext,
|
||||
child_shape: Shape,
|
||||
block_like_iter: impl Iterator<Item = bool>,
|
||||
) -> Option<String> {
|
||||
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
|
||||
let connector = if self.fits_single_line {
|
||||
// Yay, we can put everything on one line.
|
||||
Cow::from("")
|
||||
|
|
@ -645,17 +640,13 @@ impl<'a> ChainFormatterShared<'a> {
|
|||
let mut rewrite_iter = self.rewrites.iter();
|
||||
let mut result = rewrite_iter.next().unwrap().clone();
|
||||
let children_iter = self.children.iter();
|
||||
let iter = rewrite_iter.zip(block_like_iter).zip(children_iter);
|
||||
let iter = rewrite_iter.zip(children_iter);
|
||||
|
||||
for ((rewrite, prev_is_block_like), chain_item) in iter {
|
||||
for (rewrite, chain_item) in iter {
|
||||
match chain_item.kind {
|
||||
ChainItemKind::Comment(_, CommentPosition::Back) => result.push(' '),
|
||||
ChainItemKind::Comment(_, CommentPosition::Top) => result.push_str(&connector),
|
||||
_ => {
|
||||
if !prev_is_block_like {
|
||||
result.push_str(&connector);
|
||||
}
|
||||
}
|
||||
_ => result.push_str(&connector),
|
||||
}
|
||||
result.push_str(&rewrite);
|
||||
}
|
||||
|
|
@ -667,15 +658,14 @@ impl<'a> ChainFormatterShared<'a> {
|
|||
// Formats a chain using block indent.
|
||||
struct ChainFormatterBlock<'a> {
|
||||
shared: ChainFormatterShared<'a>,
|
||||
// For each rewrite, whether the corresponding item is block-like.
|
||||
is_block_like: Vec<bool>,
|
||||
root_ends_with_block: bool,
|
||||
}
|
||||
|
||||
impl<'a> ChainFormatterBlock<'a> {
|
||||
fn new(chain: &'a Chain) -> ChainFormatterBlock<'a> {
|
||||
ChainFormatterBlock {
|
||||
shared: ChainFormatterShared::new(chain),
|
||||
is_block_like: Vec::with_capacity(chain.children.len() + 1),
|
||||
root_ends_with_block: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -703,33 +693,32 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
|
|||
None => break,
|
||||
}
|
||||
|
||||
root_ends_with_block = item.kind.is_block_like(context, &root_rewrite);
|
||||
root_ends_with_block = last_line_extendable(&root_rewrite);
|
||||
|
||||
self.shared.children = &self.shared.children[1..];
|
||||
if self.shared.children.is_empty() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
self.is_block_like.push(root_ends_with_block);
|
||||
self.shared.rewrites.push(root_rewrite);
|
||||
self.root_ends_with_block = root_ends_with_block;
|
||||
Some(())
|
||||
}
|
||||
|
||||
fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option<Shape> {
|
||||
Some(
|
||||
if self.is_block_like[0] {
|
||||
if self.root_ends_with_block {
|
||||
shape.block_indent(0)
|
||||
} else {
|
||||
shape.block_indent(context.config.tab_spaces())
|
||||
}.with_max_width(context.config),
|
||||
}
|
||||
.with_max_width(context.config),
|
||||
)
|
||||
}
|
||||
|
||||
fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()> {
|
||||
for item in &self.shared.children[..self.shared.children.len() - 1] {
|
||||
let rewrite = item.rewrite(context, child_shape)?;
|
||||
self.is_block_like
|
||||
.push(item.kind.is_block_like(context, &rewrite));
|
||||
self.shared.rewrites.push(rewrite);
|
||||
}
|
||||
Some(())
|
||||
|
|
@ -746,8 +735,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
|
|||
}
|
||||
|
||||
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
|
||||
self.shared
|
||||
.join_rewrites(context, child_shape, self.is_block_like.iter().cloned())
|
||||
self.shared.join_rewrites(context, child_shape)
|
||||
}
|
||||
|
||||
fn pure_root(&mut self) -> Option<String> {
|
||||
|
|
@ -841,8 +829,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
|
|||
}
|
||||
|
||||
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
|
||||
self.shared
|
||||
.join_rewrites(context, child_shape, iter::repeat(false))
|
||||
self.shared.join_rewrites(context, child_shape)
|
||||
}
|
||||
|
||||
fn pure_root(&mut self) -> Option<String> {
|
||||
|
|
|
|||
|
|
@ -198,7 +198,8 @@ fn rewrite_closure_expr(
|
|||
} else {
|
||||
Some(rw)
|
||||
}
|
||||
}).map(|rw| format!("{} {}", prefix, rw))
|
||||
})
|
||||
.map(|rw| format!("{} {}", prefix, rw))
|
||||
}
|
||||
|
||||
// Rewrite closure whose body is block.
|
||||
|
|
@ -367,8 +368,10 @@ where
|
|||
.map(|e| match e.node {
|
||||
ast::ExprKind::Closure(..) => true,
|
||||
_ => false,
|
||||
}).unwrap_or(false)
|
||||
}).count()
|
||||
})
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.count()
|
||||
> 1
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -370,7 +370,8 @@ fn rewrite_comment_inner(
|
|||
}
|
||||
|
||||
line
|
||||
}).map(|s| left_trim_comment_line(s, &style))
|
||||
})
|
||||
.map(|s| left_trim_comment_line(s, &style))
|
||||
.map(|(line, has_leading_whitespace)| {
|
||||
if orig.starts_with("/*") && line_breaks == 0 {
|
||||
(
|
||||
|
|
@ -542,7 +543,8 @@ fn trim_custom_comment_prefix(s: &str) -> String {
|
|||
} else {
|
||||
line
|
||||
}
|
||||
}).collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
}
|
||||
|
||||
|
|
@ -630,7 +632,8 @@ fn light_rewrite_comment(
|
|||
};
|
||||
// Preserve markdown's double-space line break syntax in doc comment.
|
||||
trim_right_unless_two_whitespaces(left_trimmed, is_doc_comment)
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
Some(lines.join(&format!("\n{}", offset.to_string(config))))
|
||||
}
|
||||
|
||||
|
|
@ -1455,7 +1458,8 @@ mod test {
|
|||
.filter_map(|(s, c)| match s {
|
||||
FullCodeCharKind::Normal | FullCodeCharKind::InString => Some(c),
|
||||
_ => None,
|
||||
}).collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -216,7 +216,8 @@ impl FileLines {
|
|||
.map(|(file, range)| JsonSpan {
|
||||
file: file.to_owned(),
|
||||
range: (range.lo, range.hi),
|
||||
}).collect(),
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -394,7 +394,8 @@ impl IgnoreList {
|
|||
path.push(s);
|
||||
path
|
||||
}
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
|
||||
fn skip_file_inner(&self, file: &Path) -> bool {
|
||||
|
|
|
|||
16
src/expr.rs
16
src/expr.rs
|
|
@ -1029,7 +1029,8 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
|||
false,
|
||||
true,
|
||||
mk_sp(else_block.span.lo(), self.span.hi()),
|
||||
).rewrite(context, shape)
|
||||
)
|
||||
.rewrite(context, shape)
|
||||
}
|
||||
ast::ExprKind::If(ref cond, ref if_block, ref next_else_block) => {
|
||||
ControlFlow::new_if(
|
||||
|
|
@ -1040,7 +1041,8 @@ impl<'a> Rewrite for ControlFlow<'a> {
|
|||
false,
|
||||
true,
|
||||
mk_sp(else_block.span.lo(), self.span.hi()),
|
||||
).rewrite(context, shape)
|
||||
)
|
||||
.rewrite(context, shape)
|
||||
}
|
||||
_ => {
|
||||
last_in_chain = true;
|
||||
|
|
@ -1237,7 +1239,8 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
|
|||
new_indent.to_string(context.config),
|
||||
line.trim_left()
|
||||
)
|
||||
}).collect::<Vec<_>>()
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
.trim_left(),
|
||||
);
|
||||
|
|
@ -1486,7 +1489,12 @@ fn rewrite_index(
|
|||
.offset_left(offset)
|
||||
.and_then(|shape| shape.sub_width(1 + rhs_overhead))
|
||||
} else {
|
||||
shape.visual_indent(offset).sub_width(offset + 1)
|
||||
match context.config.indent_style() {
|
||||
IndentStyle::Block => shape
|
||||
.offset_left(offset)
|
||||
.and_then(|shape| shape.sub_width(1)),
|
||||
IndentStyle::Visual => shape.visual_indent(offset).sub_width(offset + 1),
|
||||
}
|
||||
};
|
||||
let orig_index_rw = index_shape.and_then(|s| index.rewrite(context, s));
|
||||
|
||||
|
|
|
|||
|
|
@ -240,7 +240,8 @@ impl FormattingError {
|
|||
fl.file
|
||||
.get_line(fl.lines[0].line_index)
|
||||
.map(|l| l.into_owned())
|
||||
}).unwrap_or_else(String::new),
|
||||
})
|
||||
.unwrap_or_else(String::new),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,8 @@ fn prune_files(files: Vec<&str>) -> Vec<&str> {
|
|||
return true;
|
||||
}
|
||||
pruned_prefixes.iter().all(|pp| !f.starts_with(pp))
|
||||
}).collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn git_diff(commits: &str) -> String {
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ impl<'a> FmtVisitor<'a> {
|
|||
Some(item.vis.clone()),
|
||||
Some(item.span.lo()),
|
||||
Some(item.attrs.clone()),
|
||||
).rewrite_top_level(&self.get_context(), shape);
|
||||
)
|
||||
.rewrite_top_level(&self.get_context(), shape);
|
||||
match rw {
|
||||
Some(ref s) if s.is_empty() => {
|
||||
// Format up to last newline
|
||||
|
|
@ -291,7 +292,8 @@ impl UseTree {
|
|||
} else {
|
||||
Some(item.attrs.clone())
|
||||
},
|
||||
).normalize(),
|
||||
)
|
||||
.normalize(),
|
||||
),
|
||||
_ => None,
|
||||
}
|
||||
|
|
@ -345,13 +347,15 @@ impl UseTree {
|
|||
context.snippet_provider.span_after(a.span, "{"),
|
||||
a.span.hi(),
|
||||
false,
|
||||
).collect();
|
||||
)
|
||||
.collect();
|
||||
result.path.push(UseSegment::List(
|
||||
list.iter()
|
||||
.zip(items.into_iter())
|
||||
.map(|(t, list_item)| {
|
||||
Self::from_ast(context, &t.0, Some(list_item), None, None, None)
|
||||
}).collect(),
|
||||
})
|
||||
.collect(),
|
||||
));
|
||||
}
|
||||
UseTreeKind::Simple(ref rename, ..) => {
|
||||
|
|
|
|||
15
src/items.rs
15
src/items.rs
|
|
@ -460,7 +460,8 @@ impl<'a> FmtVisitor<'a> {
|
|||
self.block_indent,
|
||||
mk_sp(span.lo(), body_start),
|
||||
last_line_width(&enum_header),
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
self.push_str(&generics_str);
|
||||
|
||||
self.last_pos = body_start;
|
||||
|
|
@ -517,7 +518,8 @@ impl<'a> FmtVisitor<'a> {
|
|||
body_lo,
|
||||
body_hi,
|
||||
false,
|
||||
).collect()
|
||||
)
|
||||
.collect()
|
||||
};
|
||||
let mut items: Vec<_> =
|
||||
itemize_list_with(self.config.width_heuristics().struct_variant_width);
|
||||
|
|
@ -1705,7 +1707,8 @@ fn rewrite_static(
|
|||
lhs,
|
||||
&**expr,
|
||||
Shape::legacy(remaining_width, offset.block_only()),
|
||||
).and_then(|res| recover_comment_removed(res, static_parts.span, context))
|
||||
)
|
||||
.and_then(|res| recover_comment_removed(res, static_parts.span, context))
|
||||
.map(|s| if s.ends_with(';') { s } else { s + ";" })
|
||||
} else {
|
||||
Some(format!("{}{};", prefix, ty_str))
|
||||
|
|
@ -2240,7 +2243,8 @@ fn rewrite_args(
|
|||
.map(|arg| {
|
||||
arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent))
|
||||
.unwrap_or_else(|| context.snippet(arg.span()).to_owned())
|
||||
}).collect::<Vec<_>>();
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Account for sugary self.
|
||||
// FIXME: the comment for the self argument is dropped. This is blocked
|
||||
|
|
@ -2822,7 +2826,8 @@ impl Rewrite for ast::ForeignItem {
|
|||
span,
|
||||
false,
|
||||
false,
|
||||
).map(|(s, _)| format!("{};", s)),
|
||||
)
|
||||
.map(|(s, _)| format!("{};", s)),
|
||||
ast::ForeignItemKind::Static(ref ty, is_mutable) => {
|
||||
// FIXME(#21): we're dropping potential comments in between the
|
||||
// function keywords here.
|
||||
|
|
|
|||
|
|
@ -287,7 +287,8 @@ pub fn rewrite_macro_inner(
|
|||
} else {
|
||||
Some(SeparatorTactic::Never)
|
||||
},
|
||||
).map(|rw| match position {
|
||||
)
|
||||
.map(|rw| match position {
|
||||
MacroPosition::Item => format!("{};", rw),
|
||||
_ => rw,
|
||||
})
|
||||
|
|
@ -418,7 +419,8 @@ pub fn rewrite_macro_def(
|
|||
context.snippet_provider.span_after(span, "{"),
|
||||
span.hi(),
|
||||
false,
|
||||
).collect::<Vec<_>>();
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let fmt = ListFormatting::new(arm_shape, context.config)
|
||||
.separator(if def.legacy { ";" } else { "" })
|
||||
|
|
@ -1141,7 +1143,8 @@ fn indent_macro_snippet(
|
|||
FullCodeCharKind::InString | FullCodeCharKind::EndString => None,
|
||||
_ => prefix_space_width,
|
||||
}
|
||||
}).min()?;
|
||||
})
|
||||
.min()?;
|
||||
|
||||
Some(
|
||||
first_line + "\n" + &trimmed_lines
|
||||
|
|
@ -1157,7 +1160,8 @@ fn indent_macro_snippet(
|
|||
}
|
||||
None => String::new(),
|
||||
},
|
||||
).collect::<Vec<_>>()
|
||||
)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
)
|
||||
}
|
||||
|
|
@ -1322,7 +1326,8 @@ impl MacroBranch {
|
|||
}
|
||||
(s + l + "\n", !kind.is_string() || l.ends_with('\\'))
|
||||
},
|
||||
).0;
|
||||
)
|
||||
.0;
|
||||
|
||||
// Undo our replacement of macro variables.
|
||||
// FIXME: this could be *much* more efficient.
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ where
|
|||
item_max_width,
|
||||
force_separator_tactic,
|
||||
None,
|
||||
).rewrite(shape)
|
||||
)
|
||||
.rewrite(shape)
|
||||
}
|
||||
|
||||
pub fn rewrite_with_angle_brackets<T>(
|
||||
|
|
@ -76,7 +77,8 @@ where
|
|||
context.config.max_width(),
|
||||
None,
|
||||
None,
|
||||
).rewrite(shape)
|
||||
)
|
||||
.rewrite(shape)
|
||||
}
|
||||
|
||||
pub fn rewrite_with_square_brackets<T>(
|
||||
|
|
@ -107,7 +109,8 @@ where
|
|||
context.config.width_heuristics().array_width,
|
||||
force_separator_tactic,
|
||||
Some(("[", "]")),
|
||||
).rewrite(shape)
|
||||
)
|
||||
.rewrite(shape)
|
||||
}
|
||||
|
||||
struct Context<'a, T: 'a> {
|
||||
|
|
@ -242,7 +245,8 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
|
|||
list_items,
|
||||
self.one_line_shape,
|
||||
self.item_max_width,
|
||||
).and_then(|arg_shape| {
|
||||
)
|
||||
.and_then(|arg_shape| {
|
||||
self.rewrite_last_item_with_overflow(
|
||||
&mut list_items[self.items.len() - 1],
|
||||
arg_shape,
|
||||
|
|
@ -495,7 +499,8 @@ where
|
|||
Shape {
|
||||
width: min(args_max_width, shape.width),
|
||||
..shape
|
||||
}.offset_left(offset)
|
||||
}
|
||||
.offset_left(offset)
|
||||
}
|
||||
|
||||
fn shape_from_indent_style(
|
||||
|
|
|
|||
|
|
@ -124,7 +124,8 @@ fn rewrite_pairs_multiline<T: Rewrite>(
|
|||
let nested_shape = (match context.config.indent_style() {
|
||||
IndentStyle::Visual => shape.visual_indent(0),
|
||||
IndentStyle::Block => shape.block_indent(context.config.tab_spaces()),
|
||||
}).with_max_width(&context.config)
|
||||
})
|
||||
.with_max_width(&context.config)
|
||||
.sub_width(rhs_offset)?;
|
||||
|
||||
let indent_str = nested_shape.indent.to_string_with_newline(context.config);
|
||||
|
|
|
|||
|
|
@ -397,7 +397,8 @@ fn count_wildcard_suffix_len(
|
|||
context.snippet_provider.span_after(span, "("),
|
||||
span.hi() - BytePos(1),
|
||||
false,
|
||||
).collect();
|
||||
)
|
||||
.collect();
|
||||
|
||||
for item in items.iter().rev().take_while(|i| match i.item {
|
||||
Some(ref internal_string) if internal_string == "_" => true,
|
||||
|
|
|
|||
|
|
@ -140,7 +140,8 @@ fn rewrite_reorderable_items(
|
|||
.map(|use_tree| ListItem {
|
||||
item: use_tree.rewrite_top_level(context, nested_shape),
|
||||
..use_tree.list_item.unwrap_or_else(ListItem::empty)
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
|
||||
wrap_reorderable_items(context, &item_vec, nested_shape)
|
||||
}
|
||||
|
|
@ -237,7 +238,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
last = current;
|
||||
in_same_group
|
||||
})
|
||||
}).count();
|
||||
})
|
||||
.count();
|
||||
let items = &items[..item_length];
|
||||
|
||||
let at_least_one_in_file_lines = items
|
||||
|
|
|
|||
|
|
@ -207,7 +207,8 @@ where
|
|||
out,
|
||||
"{} {} {}",
|
||||
mismatch.line_number_orig, num_removed, num_added
|
||||
).unwrap();
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
for line in mismatch.lines {
|
||||
match line {
|
||||
|
|
|
|||
|
|
@ -514,7 +514,8 @@ fn read_significant_comments(file_name: &Path) -> HashMap<String, String> {
|
|||
.to_owned(),
|
||||
)
|
||||
})
|
||||
}).collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
// Compare output to input.
|
||||
|
|
@ -882,7 +883,8 @@ fn configuration_snippet_tests() {
|
|||
let mut file_iter = BufReader::new(
|
||||
fs::File::open(Path::new(CONFIGURATIONS_FILE_NAME))
|
||||
.expect(&format!("Couldn't read file {}", CONFIGURATIONS_FILE_NAME)),
|
||||
).lines()
|
||||
)
|
||||
.lines()
|
||||
.map(|l| l.unwrap())
|
||||
.enumerate();
|
||||
let mut code_blocks: Vec<ConfigCodeBlock> = Vec::new();
|
||||
|
|
@ -970,6 +972,7 @@ fn verify_check_works() {
|
|||
rustfmt().to_str().unwrap(),
|
||||
"--check",
|
||||
temp_file.path.to_str().unwrap(),
|
||||
]).succeeds()
|
||||
])
|
||||
.succeeds()
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -844,7 +844,8 @@ fn rewrite_lifetime_param(
|
|||
.filter(|p| match p.kind {
|
||||
ast::GenericParamKind::Lifetime => true,
|
||||
_ => false,
|
||||
}).map(|lt| lt.rewrite(context, shape))
|
||||
})
|
||||
.map(|lt| lt.rewrite(context, shape))
|
||||
.collect::<Option<Vec<_>>>()?
|
||||
.join(", ");
|
||||
if result.is_empty() {
|
||||
|
|
|
|||
|
|
@ -200,12 +200,14 @@ fn struct_field_prefix_max_min_width<T: AlignedItem>(
|
|||
Some(field_str.len())
|
||||
}
|
||||
})
|
||||
}).fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
|
||||
})
|
||||
.fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
|
||||
(Some((max_len, min_len)), Some(len)) => {
|
||||
Some((cmp::max(max_len, len), cmp::min(min_len, len)))
|
||||
}
|
||||
_ => None,
|
||||
}).unwrap_or((0, 0))
|
||||
})
|
||||
.unwrap_or((0, 0))
|
||||
}
|
||||
|
||||
fn rewrite_aligned_items_inner<T: AlignedItem>(
|
||||
|
|
@ -236,7 +238,8 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
|
|||
span.lo(),
|
||||
span.hi(),
|
||||
false,
|
||||
).collect::<Vec<_>>();
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let tactic = definitive_tactic(
|
||||
&items,
|
||||
|
|
|
|||
|
|
@ -158,7 +158,8 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
|||
item.attrs.first()
|
||||
} else {
|
||||
first_stmt.attrs().first()
|
||||
}.and_then(|attr| {
|
||||
}
|
||||
.and_then(|attr| {
|
||||
// Some stmts can have embedded attributes.
|
||||
// e.g. `match { #![attr] ... }`
|
||||
let attr_lo = attr.span.lo();
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@ fn main() {
|
|||
.method_call_a(aaaaa, bbbbb, |c| {
|
||||
let x = c;
|
||||
x
|
||||
}).method_call_b(aaaaa, bbbbb, |c| {
|
||||
})
|
||||
.method_call_b(aaaaa, bbbbb, |c| {
|
||||
let x = c;
|
||||
x
|
||||
});
|
||||
|
|
@ -55,7 +56,8 @@ fn main() {
|
|||
body.fold(Body::new(), |mut body, chunk| {
|
||||
body.extend(chunk);
|
||||
Ok(body)
|
||||
}).and_then(move |body| {
|
||||
})
|
||||
.and_then(move |body| {
|
||||
let req = Request::from_parts(parts, body);
|
||||
f(req).map_err(|_| io::Error::new(io::ErrorKind::Other, ""))
|
||||
});
|
||||
|
|
@ -64,7 +66,8 @@ fn main() {
|
|||
.map(|x| {
|
||||
x += 1;
|
||||
x
|
||||
}).filter(some_mod::some_filter)
|
||||
})
|
||||
.filter(some_mod::some_filter)
|
||||
}
|
||||
|
||||
fn floaters() {
|
||||
|
|
@ -76,14 +79,16 @@ 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 {
|
||||
|
|
@ -91,9 +96,10 @@ fn floaters() {
|
|||
// params are 1-indexed
|
||||
stack.push(
|
||||
mparams[match cur.to_digit(10) {
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
}].clone(),
|
||||
Some(d) => d as usize - 1,
|
||||
None => return Err("bad param number".to_owned()),
|
||||
}]
|
||||
.clone(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -103,28 +109,34 @@ fn floaters() {
|
|||
some();
|
||||
} else {
|
||||
none();
|
||||
}.bar()
|
||||
}
|
||||
.bar()
|
||||
.baz();
|
||||
|
||||
Foo {
|
||||
x: val,
|
||||
}.baz(|| {
|
||||
}
|
||||
.baz(|| {
|
||||
force();
|
||||
multiline();
|
||||
}).quux();
|
||||
})
|
||||
.quux();
|
||||
|
||||
Foo {
|
||||
y: i_am_multi_line,
|
||||
z: ok,
|
||||
}.baz(|| {
|
||||
}
|
||||
.baz(|| {
|
||||
force();
|
||||
multiline();
|
||||
}).quux();
|
||||
})
|
||||
.quux();
|
||||
|
||||
a + match x {
|
||||
true => "yay!",
|
||||
false => "boo!",
|
||||
}.bar()
|
||||
}
|
||||
.bar()
|
||||
}
|
||||
|
||||
fn is_replaced_content() -> bool {
|
||||
|
|
@ -184,7 +196,8 @@ fn issue1392() {
|
|||
else {
|
||||
b();
|
||||
}
|
||||
"#.trim(),
|
||||
"#
|
||||
.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -234,7 +247,8 @@ impl Foo {
|
|||
}
|
||||
}
|
||||
})
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -247,8 +261,10 @@ fn issue2415() {
|
|||
Ok((|| {
|
||||
// stuff
|
||||
Some(value.to_string())
|
||||
})().ok_or("")?)
|
||||
})().unwrap_or_else(|_: Box<::std::error::Error>| String::from(""));
|
||||
})()
|
||||
.ok_or("")?)
|
||||
})()
|
||||
.unwrap_or_else(|_: Box<::std::error::Error>| String::from(""));
|
||||
}
|
||||
|
||||
impl issue_2786 {
|
||||
|
|
@ -256,10 +272,12 @@ impl issue_2786 {
|
|||
foo(|a| {
|
||||
println!("a");
|
||||
println!("b");
|
||||
}).bar(|c| {
|
||||
})
|
||||
.bar(|c| {
|
||||
println!("a");
|
||||
println!("b");
|
||||
}).baz(|c| {
|
||||
})
|
||||
.baz(|c| {
|
||||
println!("a");
|
||||
println!("b");
|
||||
})
|
||||
|
|
@ -271,10 +289,12 @@ fn issue_2773() {
|
|||
bar.or_else(|| {
|
||||
// do stuff
|
||||
None
|
||||
}).or_else(|| {
|
||||
})
|
||||
.or_else(|| {
|
||||
// do other stuff
|
||||
None
|
||||
}).and_then(|val| {
|
||||
})
|
||||
.and_then(|val| {
|
||||
// do this stuff
|
||||
None
|
||||
});
|
||||
|
|
|
|||
|
|
@ -171,7 +171,8 @@ fn issue1329() {
|
|||
.map(|x| {
|
||||
x += 1;
|
||||
x
|
||||
}).filter
|
||||
})
|
||||
.filter
|
||||
}
|
||||
|
||||
fn issue325() {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,8 @@ fn issue1420() {
|
|||
# Getting started
|
||||
...
|
||||
"#,
|
||||
).running(waltz)
|
||||
)
|
||||
.running(waltz)
|
||||
}
|
||||
|
||||
// #1563
|
||||
|
|
@ -117,7 +118,8 @@ impl Cursor {
|
|||
debug_assert_eq!(n, -1);
|
||||
None
|
||||
}
|
||||
}).or_else(|| {
|
||||
})
|
||||
.or_else(|| {
|
||||
let canonical = self.canonical();
|
||||
if canonical != *self {
|
||||
canonical.num_template_args()
|
||||
|
|
|
|||
|
|
@ -141,7 +141,8 @@ fn issue_1450() {
|
|||
Relaxed,
|
||||
Release,
|
||||
Relaxed,
|
||||
).is_ok()
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ fn floaters() {
|
|||
let x = Foo {
|
||||
field1: val1,
|
||||
field2: val2,
|
||||
}.method_call()
|
||||
}
|
||||
.method_call()
|
||||
.method_call();
|
||||
|
||||
let y = if cond {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ fn floaters() {
|
|||
let x = Foo {
|
||||
field1: val1,
|
||||
field2: val2,
|
||||
}.method_call()
|
||||
}
|
||||
.method_call()
|
||||
.method_call();
|
||||
|
||||
let y = if cond { val1 } else { val2 }.method_call();
|
||||
|
|
|
|||
|
|
@ -16,5 +16,6 @@ fn foo() {
|
|||
Ok(entry.insert(try!(statement)))
|
||||
}
|
||||
}
|
||||
}).map(MaybeCached::Cached)
|
||||
})
|
||||
.map(MaybeCached::Cached)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ fn bar() {}
|
|||
/// .resource("/", |r| r.f(|r| HttpResponse::Ok()))
|
||||
/// .boxed(),
|
||||
/// ]
|
||||
/// }).bind("127.0.0.1:8080")
|
||||
/// })
|
||||
/// .bind("127.0.0.1:8080")
|
||||
/// .unwrap()
|
||||
/// .run()
|
||||
/// # });
|
||||
|
|
|
|||
|
|
@ -52,7 +52,8 @@ fn main() {
|
|||
assert!(row_sum_a > 0);
|
||||
(item_b, (item_a, num_cooccurrences, row_sum_a))
|
||||
},
|
||||
).join_map(
|
||||
)
|
||||
.join_map(
|
||||
&row_sums,
|
||||
|&item_b, &(item_a, num_cooccurrences, row_sum_a), &row_sum_b| {
|
||||
assert!(row_sum_a > 0);
|
||||
|
|
@ -159,5 +160,6 @@ fn main() {
|
|||
worker.step();
|
||||
}
|
||||
}
|
||||
}).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -173,7 +173,8 @@ fn issue1739() {
|
|||
..,
|
||||
init_size[1] - extreeeeeeeeeeeeeeeeeeeeeeeem..init_size[1],
|
||||
..
|
||||
]).par_map_inplace(|el| *el = 0.);
|
||||
])
|
||||
.par_map_inplace(|el| *el = 0.);
|
||||
}
|
||||
|
||||
fn issue_1885() {
|
||||
|
|
@ -183,7 +184,8 @@ fn issue_1885() {
|
|||
chan_select! {
|
||||
rx.recv() => {}
|
||||
}
|
||||
}).collect::<Vec<_>>();
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
|
||||
fn issue_1917() {
|
||||
|
|
|
|||
|
|
@ -381,7 +381,8 @@ fn issue1456() {
|
|||
.iter()
|
||||
.map(|node| {
|
||||
XPathNodeReader::new(node, &context).and_then(|r| ArtistRef::from_xml(&r))
|
||||
}).collect();
|
||||
})
|
||||
.collect();
|
||||
res?
|
||||
}
|
||||
_ => Vec::new(),
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@ fn main() {
|
|||
expr.rewrite(
|
||||
inner_context,
|
||||
&Constraints::new(try_opt!(v_budget.checked_sub(2)), indent + 2),
|
||||
).map(|s| format!("..{}", s))
|
||||
)
|
||||
.map(|s| format!("..{}", s))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue