more fallout

This commit is contained in:
Nick Cameron 2017-02-23 08:52:52 +13:00
parent d9d2423764
commit a7612cc773
27 changed files with 135 additions and 288 deletions

View File

@ -39,10 +39,10 @@ fn git_head_sha1() -> Option<String> {
.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.

View File

@ -335,11 +335,11 @@ fn determine_operation(matches: &Matches) -> FmtResult<Operation> {
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") {

View File

@ -133,9 +133,15 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: 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)));
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
};
@ -286,7 +292,7 @@ fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext) -> (ast::Expr,
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),
}

View File

@ -476,7 +476,6 @@ fn rewrite_closure(capture: ast::CaptureBy,
}
// Either we require a block, or tried without and failed.
let body_shape = shape.block();
return rewrite_closure_block(&block, prefix, context, body_shape);
}
@ -1409,9 +1408,10 @@ fn rewrite_pat_expr(context: &RewriteContext,
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') {
@ -1548,8 +1548,9 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
|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();
@ -1897,9 +1898,9 @@ pub fn rewrite_unary_suffix<R: Rewrite>(context: &RewriteContext,
-> 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,

View File

@ -121,8 +121,9 @@ impl FileLines {
};
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,
}

View File

@ -183,10 +183,10 @@ impl<'a> FmtVisitor<'a> {
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

View File

@ -1668,11 +1668,12 @@ fn rewrite_args(context: &RewriteContext,
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

View File

@ -675,9 +675,9 @@ fn rewrite_bare_fn(bare_fn: &ast::BareFnTy,
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("> ");

View File

@ -23,5 +23,4 @@ report_fixme = "Never"
reorder_imports = false
single_line_if_else_max_width = 0
format_strings = true
chains_overflow_last = true
take_source_hints = true

View File

@ -1,31 +0,0 @@
// 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());
}
}
}
}

View File

@ -1,38 +0,0 @@
// 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)
}

View File

@ -1,7 +1,6 @@
// 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() {

View File

@ -295,11 +295,11 @@ fn read_significant_comments(file_name: &str) -> HashMap<String, String> {
.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()
}

View File

@ -1,32 +0,0 @@
// 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());
}
}
}
}

View File

@ -1,41 +0,0 @@
// 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)
}

View File

@ -1,16 +0,0 @@
// 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();
}

View File

@ -1,7 +1,6 @@
// 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() {
@ -21,15 +20,15 @@ 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;
@ -50,15 +49,15 @@ fn main() {
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)
}
@ -105,9 +104,9 @@ fn floaters() {
Foo { x: val }
.baz(|| {
force();
multiline();
})
force();
multiline();
})
.quux();
Foo {
@ -115,9 +114,9 @@ fn floaters() {
z: ok,
}
.baz(|| {
force();
multiline();
})
force();
multiline();
})
.quux();
a +

View File

@ -19,15 +19,15 @@ 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;
@ -53,9 +53,9 @@ fn main() {
.fold(0, |acc, x| acc + x);
aaaaaaaaaaaaaaaa.map(|x| {
x += 1;
x
})
x += 1;
x
})
.filter(some_mod::some_filter)
}
@ -84,10 +84,10 @@ fn floaters() {
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());
}
}
}
@ -102,9 +102,9 @@ fn floaters() {
Foo { x: val }
.baz(|| {
force();
multiline();
})
force();
multiline();
})
.quux();
Foo {
@ -112,9 +112,9 @@ fn floaters() {
z: ok,
}
.baz(|| {
force();
multiline();
})
force();
multiline();
})
.quux();
a +
@ -173,7 +173,7 @@ fn issue_1004() {
}?;
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))
})?;
}

View File

@ -74,16 +74,16 @@ fn issue863() {
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> {

View File

@ -41,10 +41,10 @@ fn doc_comment() {}
fn chains() {
foo.bar(|| {
let x = 10;
// comment
x
})
let x = 10;
// comment
x
})
}
fn issue_1086() {

View File

@ -74,10 +74,10 @@ fn main() {
}
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); });
@ -87,7 +87,7 @@ fn main() {
.d();
x().y(|| match cond() {
true => (),
false => (),
});
true => (),
false => (),
});
}

View File

@ -14,9 +14,9 @@ impl ISizeAndMarginsComputer for AbsoluteNonReplaced {
// 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)
}
};
@ -30,9 +30,9 @@ impl ISizeAndMarginsComputer for AbsoluteNonReplaced {
// 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)
}
};

View File

@ -7,10 +7,7 @@ fn main() {
{
aaaaaaaa::Bbbbb::Ccccccccccccc(_, Some(ref x)) if x ==
"aaaaaaaaaaa \
aaaaaaa aaaaaa" =>
{
Ok(())
}
aaaaaaa aaaaaa" => Ok(()),
_ => Err(x),
}
}

View File

@ -1,4 +1,4 @@
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;
}

View File

@ -276,12 +276,14 @@ fn issue494() {
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(),
},
})))
}
}
}

View File

@ -49,11 +49,11 @@ fn main() {
};
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

View File

@ -59,11 +59,11 @@ fn main() {
};
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