.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|mut s| {
- let len = s.trim_right().len();
- s.truncate(len);
- s
- })
+ let len = s.trim_right().len();
+ s.truncate(len);
+ s
+ })
}
// Returns `None` if git is not available.
let config_path: Option<PathBuf> = matches.opt_str("config-path")
.map(PathBuf::from)
.and_then(|dir| {
- if dir.is_file() {
- return dir.parent().map(|v| v.into());
- }
- Some(dir)
- });
+ if dir.is_file() {
+ return dir.parent().map(|v| v.into());
+ }
+ Some(dir)
+ });
// if no file argument is supplied and `--file-lines` is not specified, read from stdin
if matches.free.is_empty() && !matches.opt_present("file-lines") {
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)));
- shape.offset = shape.offset.checked_sub(context.config.tab_spaces).unwrap_or(0);
- shape.indent.block_indent += context.config.tab_spaces;
- shape
+ match context.config.chain_indent {
+ BlockIndentStyle::Visual => other_child_shape,
+ BlockIndentStyle::Inherit => shape,
+ BlockIndentStyle::Tabbed => {
+ shape.offset = shape.offset.checked_sub(context.config.tab_spaces).unwrap_or(0);
+ shape.indent.block_indent += context.config.tab_spaces;
+ shape
+ }
+ }
} else {
other_child_shape
};
fn chain_indent(context: &RewriteContext, shape: Shape) -> Shape {
match context.config.chain_indent {
- BlockIndentStyle::Visual => shape,
+ BlockIndentStyle::Visual => shape.visual_indent(0),
BlockIndentStyle::Inherit => shape.block_indent(0),
BlockIndentStyle::Tabbed => shape.block_indent(context.config.tab_spaces),
}
}
// Either we require a block, or tried without and failed.
- let body_shape = shape.block();
return rewrite_closure_block(&block, prefix, context, body_shape);
}
if let Some(expr_string) = expr_rewrite {
let pat_simple = pat.and_then(|p| {
- p.rewrite(context,
- Shape::legacy(context.config.max_width, Indent::empty()))
- })
+ p.rewrite(context,
+ Shape::legacy(context.config.max_width,
+ Indent::empty()))
+ })
.map(|s| pat_is_simple(&s));
if pat.is_none() || pat_simple.unwrap_or(false) || !expr_string.contains('\n') {
|item| item.span.lo,
|item| item.span.hi,
|item| {
- item.rewrite(context, Shape { width: remaining_width, ..nested_shape })
- },
+ item.rewrite(context,
+ Shape { width: remaining_width, ..nested_shape })
+ },
span.lo,
span.hi);
let mut item_vec: Vec<_> = items.collect();
-> Option<String> {
rewrite.rewrite(context, try_opt!(shape.sub_width(suffix.len())))
.map(|mut r| {
- r.push_str(suffix);
- r
- })
+ r.push_str(suffix);
+ r
+ })
}
fn rewrite_unary_op(context: &RewriteContext,
};
match canonicalize_path_string(range.file_name()).and_then(|canonical| {
- map.get_vec(&canonical).ok_or(())
- }) {
+ map.get_vec(&canonical)
+ .ok_or(())
+ }) {
Ok(ranges) => ranges.iter().any(|r| r.contains(Range::from(range))),
Err(_) => false,
}
let mut last_pos_of_prev_use_item = pos_before_first_use_item;
let mut ordered_use_items = use_items.iter()
.map(|p_i| {
- let new_item = (&*p_i, last_pos_of_prev_use_item);
- last_pos_of_prev_use_item = p_i.span.hi;
- new_item
- })
+ let new_item = (&*p_i, last_pos_of_prev_use_item);
+ last_pos_of_prev_use_item = p_i.span.hi;
+ new_item
+ })
.collect::<Vec<_>>();
let pos_after_last_use_item = last_pos_of_prev_use_item;
// Order the imports by view-path & other import path properties
span: Span,
variadic: bool)
-> Option<String> {
- let mut arg_item_strs = try_opt!(args.iter()
- .map(|arg| {
- arg.rewrite(&context, Shape::legacy(multi_line_budget, arg_indent))
- })
- .collect::<Option<Vec<_>>>());
+ let mut arg_item_strs =
+ try_opt!(args.iter()
+ .map(|arg| {
+ arg.rewrite(&context, Shape::legacy(multi_line_budget, arg_indent))
+ })
+ .collect::<Option<Vec<_>>>());
// Account for sugary self.
// FIXME: the comment for the self argument is dropped. This is blocked
result.push_str(&try_opt!(bare_fn.lifetimes
.iter()
.map(|l| {
- l.rewrite(context,
+ l.rewrite(context,
Shape::legacy(try_opt!(shape.width.checked_sub(6)), shape.indent + 4))
- })
+ })
.intersperse(Some(", ".to_string()))
.collect::<Option<String>>()));
result.push_str("> ");
reorder_imports = false
single_line_if_else_max_width = 0
format_strings = true
-chains_overflow_last = true
take_source_hints = true
+++ /dev/null
-// rustfmt-single_line_if_else_max_width: 0
-// rustfmt-chain_base_indent: Inherit
-// Test chain formatting with block indented base
-
-fn floaters() {
- let x = Foo {
- field1: val1,
- field2: val2,
- }
- .method_call().method_call();
-
- let y = if cond {
- val1
- } else {
- val2
- }
- .method_call();
-
- {
- match x {
- PushParam => {
- // 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());
- }
- }
- }
-}
+++ /dev/null
-// rustfmt-single_line_if_else_max_width: 0
-// rustfmt-chains_overflow_last: false
-// Test chain formatting without overflowing the last item.
-
-fn main() {
- bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
- .ddddddddddddddddddddddddddd();
-
- bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc.ddddddddddddddddddddddddddd.eeeeeeee();
-
- x()
- .y(|| match cond() { true => (), false => () });
-
- loong_func()
- .quux(move || if true {
- 1
- } else {
- 2
- });
-
- fffffffffffffffffffffffffffffffffff(a,
- {
- SCRIPT_TASK_ROOT
- .with(|root| {
- *root.borrow_mut() = Some(&script_task);
- });
- });
-
- let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx
- .map(|x| x + 5)
- .map(|x| x / 2)
- .fold(0, |acc, x| acc + x);
-
- aaaaaaaaaaaaaaaa.map(|x| {
- x += 1;
- x
- }).filter(some_mod::some_filter)
-}
// rustfmt-normalize_comments: true
// rustfmt-single_line_if_else_max_width: 0
// rustfmt-chain_indent: Visual
-// rustfmt-chain_base_indent: Visual
// Test chain formatting.
fn main() {
.map(|line| line.expect("Failed getting line"))
.take_while(|line| line_regex.is_match(&line))
.filter_map(|line| {
- regex.captures_iter(&line).next().map(|capture| {
+ regex.captures_iter(&line).next().map(|capture| {
(capture.at(1).expect("Couldn't unwrap capture").to_owned(),
capture.at(2).expect("Couldn't unwrap capture").to_owned())
})
- })
+ })
.collect()
}
+++ /dev/null
-// rustfmt-single_line_if_else_max_width: 0
-// rustfmt-chain_base_indent: Inherit
-// Test chain formatting with block indented base
-
-fn floaters() {
- let x = Foo {
- field1: val1,
- field2: val2,
- }
- .method_call()
- .method_call();
-
- let y = if cond {
- val1
- } else {
- val2
- }
- .method_call();
-
- {
- match x {
- PushParam => {
- // 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());
- }
- }
- }
-}
+++ /dev/null
-// rustfmt-single_line_if_else_max_width: 0
-// rustfmt-chains_overflow_last: false
-// Test chain formatting without overflowing the last item.
-
-fn main() {
- bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
- .ddddddddddddddddddddddddddd();
-
- bbbbbbbbbbbbbbbbbbb.ccccccccccccccccccccccccccccccccccccc
- .ddddddddddddddddddddddddddd
- .eeeeeeee();
-
- x().y(|| match cond() {
- true => (),
- false => (),
- });
-
- loong_func()
- .quux(move || if true {
- 1
- } else {
- 2
- });
-
- fffffffffffffffffffffffffffffffffff(a,
- {
- SCRIPT_TASK_ROOT.with(|root| {
- *root.borrow_mut() = Some(&script_task);
- });
- });
-
- let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5)
- .map(|x| x / 2)
- .fold(0, |acc, x| acc + x);
-
- aaaaaaaaaaaaaaaa.map(|x| {
- x += 1;
- x
- })
- .filter(some_mod::some_filter)
-}
+++ /dev/null
-// rustfmt-chains_overflow_last: false
-
-fn main() {
- reader.lines()
- .map(|line| line.expect("Failed getting line"))
- .take_while(|line| line_regex.is_match(&line))
- .filter_map(|line| {
- regex.captures_iter(&line)
- .next()
- .map(|capture| {
- (capture.at(1).expect("Couldn\'t unwrap capture").to_owned(),
- capture.at(2).expect("Couldn\'t unwrap capture").to_owned())
- })
- })
- .collect();
-}
// rustfmt-normalize_comments: true
// rustfmt-single_line_if_else_max_width: 0
// rustfmt-chain_indent: Visual
-// rustfmt-chain_base_indent: Visual
// Test chain formatting.
fn main() {
// Test case where first chain element isn't a path, but is shorter than
// the size of a tab.
x().y(|| match cond() {
- true => (),
- false => (),
- });
+ true => (),
+ false => (),
+ });
loong_func().quux(move || if true {
- 1
- } else {
- 2
- });
+ 1
+ } else {
+ 2
+ });
some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
let x = c;
SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
});
- let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum = xxxxxxx.map(|x| x + 5)
- .map(|x| x / 2)
- .fold(0,
- |acc, x| acc + x);
+ let suuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuum =
+ xxxxxxx.map(|x| x + 5)
+ .map(|x| x / 2)
+ .fold(0, |acc, x| acc + x);
aaaaaaaaaaaaaaaa.map(|x| {
- x += 1;
- x
- })
+ x += 1;
+ x
+ })
.filter(some_mod::some_filter)
}
Foo { x: val }
.baz(|| {
- force();
- multiline();
- })
+ force();
+ multiline();
+ })
.quux();
Foo {
z: ok,
}
.baz(|| {
- force();
- multiline();
- })
+ force();
+ multiline();
+ })
.quux();
a +
// Test case where first chain element isn't a path, but is shorter than
// the size of a tab.
x().y(|| match cond() {
- true => (),
- false => (),
- });
+ true => (),
+ false => (),
+ });
loong_func().quux(move || if true {
- 1
- } else {
- 2
- });
+ 1
+ } else {
+ 2
+ });
some_fuuuuuuuuunction().method_call_a(aaaaa, bbbbb, |c| {
let x = c;
.fold(0, |acc, x| acc + x);
aaaaaaaaaaaaaaaa.map(|x| {
- x += 1;
- x
- })
+ x += 1;
+ x
+ })
.filter(some_mod::some_filter)
}
PushParam => {
// 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());
}
}
}
Foo { x: val }
.baz(|| {
- force();
- multiline();
- })
+ force();
+ multiline();
+ })
.quux();
Foo {
z: ok,
}
.baz(|| {
- force();
- multiline();
- })
+ force();
+ multiline();
+ })
.quux();
a +
}?;
ty::tls::with(|tcx| {
- let tap = ty::Binder(TraitAndProjections(principal, projections));
- in_binder(f, tcx, &ty::Binder(""), Some(tap))
- })?;
+ let tap = ty::Binder(TraitAndProjections(principal, projections));
+ in_binder(f, tcx, &ty::Binder(""), Some(tap))
+ })?;
}
fn issue934() {
let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
- let mut h = SpanlessHash::new(cx);
- h.hash_block(block);
- h.finish()
- };
+ let mut h = SpanlessHash::new(cx);
+ h.hash_block(block);
+ h.finish()
+ };
let hash: &Fn(&&Block) -> u64 = &|block| -> u64 {
- let mut h = SpanlessHash::new(cx);
- h.hash_block(block);
- h.finish();
- };
+ let mut h = SpanlessHash::new(cx);
+ h.hash_block(block);
+ h.finish();
+ };
}
impl<'a, 'tcx: 'a> SpanlessEq<'a, 'tcx> {
fn chains() {
foo.bar(|| {
- let x = 10;
- // comment
- x
- })
+ let x = 10;
+ // comment
+ x
+ })
}
fn issue_1086() {
}
loong_func().quux(move || if true {
- 1
- } else {
- 2
- });
+ 1
+ } else {
+ 2
+ });
fffffffffffffffffffffffffffffffffff(a, {
SCRIPT_TASK_ROOT.with(|root| { *root.borrow_mut() = Some(&script_task); });
.d();
x().y(|| match cond() {
- true => (),
- false => (),
- });
+ true => (),
+ false => (),
+ });
}
// and inline-size Auto.
//
// Set inline-end to zero to calculate inline-size.
- let inline_size = block.get_shrink_to_fit_inline_size(available_inline_size -
- (margin_start +
- margin_end));
+ let inline_size =
+ block.get_shrink_to_fit_inline_size(available_inline_size -
+ (margin_start + margin_end));
(Au(0), inline_size, margin_start, margin_end)
}
};
// and inline-size Auto.
//
// Set inline-end to zero to calculate inline-size.
- let inline_size = block.get_shrink_to_fit_inline_size(available_inline_size -
- (margin_start +
- margin_end));
+ let inline_size =
+ block.get_shrink_to_fit_inline_size(available_inline_size -
+ (margin_start + margin_end));
(Au(0), inline_size, margin_start, margin_end)
}
};
{
aaaaaaaa::Bbbbb::Ccccccccccccc(_, Some(ref x)) if x ==
"aaaaaaaaaaa \
- aaaaaaa aaaaaa" =>
- {
- Ok(())
- }
+ aaaaaaa aaaaaa" => Ok(()),
_ => Err(x),
}
}
fn f() {
- block_flow.base.stacking_relative_position_of_display_port = self.base
- .stacking_relative_position_of_display_port;
+ block_flow.base.stacking_relative_position_of_display_port =
+ self.base.stacking_relative_position_of_display_port;
}
hir::StmtExpr(ref expr, id) |
hir::StmtSemi(ref expr, id) => {
result.push(StmtRef::Mirror(Box::new(Stmt {
- span: stmt.span,
- kind: StmtKind::Expr {
- scope: cx.tcx.region_maps.node_extent(id),
- expr: expr.to_ref(),
- },
- })))
+ span: stmt.span,
+ kind: StmtKind::Expr {
+ scope: cx.tcx
+ .region_maps
+ .node_extent(id),
+ expr: expr.to_ref(),
+ },
+ })))
}
}
}
};
Some(Data::MethodCallData(MethodCallData {
- span: sub_span.unwrap(),
- scope: self.enclosing_scope(id),
- ref_id: def_id,
- decl_id: Some(decl_id),
- }));
+ span: sub_span.unwrap(),
+ scope: self.enclosing_scope(id),
+ ref_id: def_id,
+ decl_id: Some(decl_id),
+ }));
Diagram {
// o This graph demonstrates how
};
Some(Data::MethodCallData(MethodCallData {
- span: sub_span.unwrap(),
- scope: self.enclosing_scope(id),
- ref_id: def_id,
- decl_id: Some(decl_id),
- }));
+ span: sub_span.unwrap(),
+ scope: self.enclosing_scope(id),
+ ref_id: def_id,
+ decl_id: Some(decl_id),
+ }));
Diagram {
// o This graph demonstrates how