Format source codes

This commit is contained in:
topecongiro 2017-08-16 00:48:12 +09:00 committed by Seiichi Uchida
parent 89bf00986d
commit 22c9025027
9 changed files with 99 additions and 73 deletions

View File

@ -94,11 +94,13 @@ fn execute() -> i32 {
print_usage_to_stderr(&opts, &e.to_string());
failure
}
Ok(status) => if status.success() {
success
} else {
status.code().unwrap_or(failure)
},
Ok(status) => {
if status.success() {
success
} else {
status.code().unwrap_or(failure)
}
}
}
}

View File

@ -568,9 +568,11 @@ pub fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
Ok(ref md) if md.is_file() => return Ok(Some(config_file)),
// Return the error if it's something other than `NotFound`; otherwise we didn't
// find the project file yet, and continue searching.
Err(e) => if e.kind() != ErrorKind::NotFound {
return Err(e);
},
Err(e) => {
if e.kind() != ErrorKind::NotFound {
return Err(e);
}
}
_ => {}
}
}

View File

@ -462,18 +462,20 @@ where
None => DefinitiveListTactic::Vertical,
}
}
IndentStyle::Visual => if has_long_item || items.iter().any(ListItem::is_multiline) {
definitive_tactic(
&items,
ListTactic::LimitedHorizontalVertical(
context.config.width_heuristics().array_width,
),
Separator::Comma,
nested_shape.width,
)
} else {
DefinitiveListTactic::Mixed
},
IndentStyle::Visual => {
if has_long_item || items.iter().any(ListItem::is_multiline) {
definitive_tactic(
&items,
ListTactic::LimitedHorizontalVertical(
context.config.width_heuristics().array_width,
),
Separator::Comma,
nested_shape.width,
)
} else {
DefinitiveListTactic::Mixed
}
}
};
let ends_with_newline = tactic.ends_with_newline(context.config.indent_style());
@ -1501,8 +1503,8 @@ fn flatten_arm_body<'a>(context: &'a RewriteContext, body: &'a ast::Expr) -> (bo
if let ast::StmtKind::Expr(ref expr) = block.stmts[0].node {
(
!context.config.force_multiline_blocks()
&& (can_extend_match_arm_body(expr), &**expr),
&**expr,
&& can_extend_match_arm_body(expr),
&*expr,
)
} else {
(false, &*body)

View File

@ -190,19 +190,25 @@ impl BadIssueSeeker {
}
match part {
NumberPart::OpenParen => if c != '(' {
return IssueClassification::Bad(issue);
} else {
part = NumberPart::Pound;
},
NumberPart::Pound => if c == '#' {
part = NumberPart::Number;
},
NumberPart::Number => if c >= '0' && c <= '9' {
part = NumberPart::CloseParen;
} else {
return IssueClassification::Bad(issue);
},
NumberPart::OpenParen => {
if c != '(' {
return IssueClassification::Bad(issue);
} else {
part = NumberPart::Pound;
}
}
NumberPart::Pound => {
if c == '#' {
part = NumberPart::Number;
}
}
NumberPart::Number => {
if c >= '0' && c <= '9' {
part = NumberPart::CloseParen;
} else {
return IssueClassification::Bad(issue);
}
}
NumberPart::CloseParen => {}
}

View File

@ -550,12 +550,14 @@ impl<'a> FmtVisitor<'a> {
self.block_indent,
Some(one_line_width),
)?,
ast::VariantData::Unit(..) => if let Some(ref expr) = field.node.disr_expr {
let lhs = format!("{} =", field.node.name);
rewrite_assign_rhs(&context, lhs, &**expr, shape)?
} else {
field.node.name.to_string()
},
ast::VariantData::Unit(..) => {
if let Some(ref expr) = field.node.disr_expr {
let lhs = format!("{} =", field.node.name);
rewrite_assign_rhs(&context, lhs, &**expr, shape)?
} else {
field.node.name.to_string()
}
}
};
let attrs_extendable = attrs_str.is_empty()
@ -643,11 +645,13 @@ pub fn format_impl(
_ if last_line_contains_single_line_comment(&result) => result.push_str(&sep),
BraceStyle::AlwaysNextLine => result.push_str(&sep),
BraceStyle::PreferSameLine => result.push(' '),
BraceStyle::SameLineWhere => if !where_clause_str.is_empty() {
result.push_str(&sep);
} else {
result.push(' ');
},
BraceStyle::SameLineWhere => {
if !where_clause_str.is_empty() {
result.push_str(&sep);
} else {
result.push(' ');
}
}
}
result.push('{');
@ -1039,14 +1043,16 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
result.push_str(&offset.to_string(context.config));
}
BraceStyle::PreferSameLine => result.push(' '),
BraceStyle::SameLineWhere => if !where_clause_str.is_empty()
&& (!trait_items.is_empty() || result.contains('\n'))
{
result.push('\n');
result.push_str(&offset.to_string(context.config));
} else {
result.push(' ');
},
BraceStyle::SameLineWhere => {
if !where_clause_str.is_empty()
&& (!trait_items.is_empty() || result.contains('\n'))
{
result.push('\n');
result.push_str(&offset.to_string(context.config));
} else {
result.push(' ');
}
}
}
result.push('{');

View File

@ -126,11 +126,13 @@ pub fn rewrite_macro(
let macro_name = match extra_ident {
None => format!("{}!", mac.node.path),
Some(ident) => if ident == symbol::keywords::Invalid.ident() {
format!("{}!", mac.node.path)
} else {
format!("{}! {}", mac.node.path, ident)
},
Some(ident) => {
if ident == symbol::keywords::Invalid.ident() {
format!("{}!", mac.node.path)
} else {
format!("{}! {}", mac.node.path, ident)
}
}
};
let style = if FORCED_BRACKET_MACROS.contains(&&macro_name[..]) {

View File

@ -51,11 +51,13 @@ impl Rewrite for Pat {
Some(format!("{}{}{}{}", prefix, mut_infix, id_str, sub_pat))
}
PatKind::Wild => if 1 <= shape.width {
Some("_".to_owned())
} else {
None
},
PatKind::Wild => {
if 1 <= shape.width {
Some("_".to_owned())
} else {
None
}
}
PatKind::Range(ref lhs, ref rhs, ref end_kind) => {
let infix = match *end_kind {
RangeEnd::Included(RangeSyntax::DotDotDot) => "...",

View File

@ -720,11 +720,13 @@ impl Rewrite for ast::Ty {
SeparatorPlace::Back,
)
}
ast::TyKind::Infer => if shape.width >= 1 {
Some("_".to_owned())
} else {
None
},
ast::TyKind::Infer => {
if shape.width >= 1 {
Some("_".to_owned())
} else {
None
}
}
ast::TyKind::BareFn(ref bare_fn) => rewrite_bare_fn(bare_fn, self.span, context, shape),
ast::TyKind::Never => Some(String::from("!")),
ast::TyKind::Mac(..) => None,

View File

@ -321,10 +321,12 @@ impl<'a> FmtVisitor<'a> {
attrs = &filtered_attrs;
}
}
_ => if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) {
self.push_rewrite(item.span, None);
return;
},
_ => {
if self.visit_attrs(&item.attrs, ast::AttrStyle::Outer) {
self.push_rewrite(item.span, None);
return;
}
}
}
match item.node {