1
Fork 0

Format source codes

This commit is contained in:
topecongiro 2017-06-14 20:39:07 +09:00
parent c06d487712
commit b8f11a4e3c
14 changed files with 79 additions and 78 deletions

View file

@ -319,8 +319,8 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> &'a str {
} else {
&line[opener.trim_right().len()..]
}
} else if line.starts_with("/* ") || line.starts_with("// ") ||
line.starts_with("//!") || line.starts_with("///") ||
} else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!") ||
line.starts_with("///") ||
line.starts_with("** ") || line.starts_with("/*!") ||
(line.starts_with("/**") && !line.starts_with("/**/"))
{

View file

@ -729,9 +729,10 @@ fn and_one_line(x: Option<String>) -> Option<String> {
fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
debug!("nop_block_collapse {:?} {}", block_str, budget);
block_str.map(|block_str| if block_str.starts_with('{') &&
budget >= 2 &&
(block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2)
block_str.map(|block_str| if block_str.starts_with('{') && budget >= 2 &&
(block_str[1..]
.find(|c: char| !c.is_whitespace())
.unwrap() == block_str.len() - 2)
{
"{}".to_owned()
} else {
@ -1509,8 +1510,8 @@ impl Rewrite for ast::Arm {
let pats_str = format!("{}{}", pats_str, guard_str);
let (mut extend, body) = match body.node {
ast::ExprKind::Block(ref block) if !is_unsafe_block(block) &&
is_simple_block(block, context.codemap) &&
ast::ExprKind::Block(ref block)
if !is_unsafe_block(block) && is_simple_block(block, context.codemap) &&
context.config.wrap_match_arms() => {
if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node {
(false, &**expr)
@ -2539,21 +2540,10 @@ pub fn rewrite_assign_rhs<S: Into<String>>(
// FIXME: DRY!
match (rhs, new_rhs) {
(Some(ref orig_rhs), Some(ref replacement_rhs)) if count_line_breaks(
orig_rhs,
) >
count_line_breaks(
replacement_rhs,
) + 1 ||
(orig_rhs
.rewrite(context, shape)
.is_none() &&
replacement_rhs
.rewrite(
context,
new_shape,
)
.is_some()) => {
(Some(ref orig_rhs), Some(ref replacement_rhs))
if count_line_breaks(orig_rhs) > count_line_breaks(replacement_rhs) + 1 ||
(orig_rhs.rewrite(context, shape).is_none() &&
replacement_rhs.rewrite(context, new_shape).is_some()) => {
result.push_str(&format!("\n{}", new_shape.indent.to_string(context.config)));
result.push_str(replacement_rhs);
}

View file

@ -1468,9 +1468,9 @@ impl Rewrite for ast::StructField {
Some(ref ty) if ty.contains('\n') => {
let new_ty = rewrite_type_in_next_line();
match new_ty {
Some(ref new_ty) if !new_ty.contains('\n') &&
new_ty.len() + type_offset.width() <=
context.config.max_width() => {
Some(ref new_ty)
if !new_ty.contains('\n') &&
new_ty.len() + type_offset.width() <= context.config.max_width() => {
Some(format!(
"{}\n{}{}",
result,
@ -2688,7 +2688,8 @@ fn format_generics(
let same_line_brace = force_same_line_brace ||
(generics.where_clause.predicates.is_empty() && trimmed_last_line_width(&result) == 1);
if !same_line_brace &&
(brace_style == BraceStyle::SameLineWhere || brace_style == BraceStyle::AlwaysNextLine)
(brace_style == BraceStyle::SameLineWhere ||
brace_style == BraceStyle::AlwaysNextLine)
{
result.push('\n');
result.push_str(&offset.block_only().to_string(context.config));

View file

@ -206,8 +206,8 @@ fn rewrite_segment(
let params = if let Some(ref params) = segment.parameters {
match **params {
ast::PathParameters::AngleBracketed(ref data) if !data.lifetimes.is_empty() ||
!data.types.is_empty() ||
ast::PathParameters::AngleBracketed(ref data)
if !data.lifetimes.is_empty() || !data.types.is_empty() ||
!data.bindings.is_empty() => {
let param_list = data.lifetimes
.iter()

View file

@ -546,7 +546,8 @@ impl<'a> FmtVisitor<'a> {
fn push_rewrite(&mut self, span: Span, rewrite: Option<String>) {
self.format_missing_with_indent(source!(self, span).lo);
self.failed = match rewrite {
Some(ref s) if s.rewrite(
Some(ref s)
if s.rewrite(
&self.get_context(),
Shape::indented(self.block_indent, self.config),
).is_none() => true,

View file

@ -7,8 +7,8 @@ fn foo() -> bool {
let referenced = &5;
let very_long_variable_name = (a + first + simple + test);
let very_long_variable_name =
(a + first + simple + test + AAAAAAAAAAAAA + BBBBBBBBBBBBBBBBB + b + c);
let very_long_variable_name = (a + first + simple + test + AAAAAAAAAAAAA +
BBBBBBBBBBBBBBBBB + b + c);
let is_internalxxxx = self.codemap.span_to_filename(s) ==
self.codemap.span_to_filename(m.inner);
@ -20,8 +20,10 @@ fn foo() -> bool {
10000 * 30000000000 + 40000 / 1002200000000 - 50000 * sqrt(-1),
trivial_value,
);
(((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + a +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaa))))))))) ;
(((((((((aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
a +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaa)))))))));
{
for _ in 0..10 {}

View file

@ -96,7 +96,12 @@ fn foo<g: G>() {
foo();
}
fn foo<L: Loooooooooooooooooooooong, G: Geeeeeeeeeeeneric, I: iiiiiiiiis, L: Looooooooooooooooong>() {
fn foo<
L: Loooooooooooooooooooooong,
G: Geeeeeeeeeeeneric,
I: iiiiiiiiis,
L: Looooooooooooooooong,
>() {
foo();
}

View file

@ -67,13 +67,18 @@ fn main() {
vec![a, b; c];
vec![a; b, c];
vec![a;
vec![
a;
(|x| {
let y = x + 1;
let z = y + 1;
z
})(2)];
vec![a; xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx];
})(2)
];
vec![
a;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
];
vec![a; unsafe { x + 1 }];
unknown_bracket_macro__comma_should_not_be_stripped![

View file

@ -37,10 +37,8 @@ fn foo() {
Patternnnnnnnnnnnnnnnnnnnnnnnnn if loooooooooooooooooooooooooooooooooooooooooong_guard => {}
_ => {}
ast::PathParameters::AngleBracketedParameters(ref data) if data.lifetimes.len() >
0 ||
data.types.len() > 0 ||
data.bindings.len() > 0 => {}
ast::PathParameters::AngleBracketedParameters(ref data)
if data.lifetimes.len() > 0 || data.types.len() > 0 || data.bindings.len() > 0 => {}
}
let whatever = match something {
@ -316,16 +314,15 @@ fn issue386() {
fn guards() {
match foo {
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
barrrrrrrrrrrr => {}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
if foooooooooooooo && barrrrrrrrrrrr => {}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if foooooooooooooo &&
barrrrrrrrrrrr => {}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
if foooooooooooooo && barrrrrrrrrrrr => {}
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
if fooooooooooooooooooooo &&
(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb || cccccccccccccccccccccccccccccccccccccccc) => {
{}
}
(bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ||
cccccccccccccccccccccccccccccccccccccccc) => {}
}
}