Format source codes and update tests
This commit is contained in:
parent
04a6d16c7b
commit
f9239dd630
7 changed files with 62 additions and 80 deletions
22
src/expr.rs
22
src/expr.rs
|
|
@ -1130,10 +1130,8 @@ 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 +1244,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);
|
||||
|
|
@ -2253,15 +2249,17 @@ where
|
|||
_ => (),
|
||||
}
|
||||
}
|
||||
last_arg_shape(&context, &item_vec, shape, args_max_width)
|
||||
.map_or((None, None), |arg_shape| {
|
||||
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,
|
||||
)
|
||||
})
|
||||
},
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
11
src/types.rs
11
src/types.rs
|
|
@ -553,10 +553,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 +606,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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)) => {
|
||||
|
|
|
|||
|
|
@ -855,8 +855,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);
|
||||
|
|
@ -869,8 +870,7 @@ impl Rewrite for ast::Attribute {
|
|||
} else {
|
||||
format!("{}[{}]", prefix, rw)
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue