impl TargetKind {
fn should_format(&self) -> bool {
match *self {
- TargetKind::Lib | TargetKind::Bin | TargetKind::Example | TargetKind::Test |
- TargetKind::Bench | TargetKind::CustomBuild | TargetKind::ProcMacro => true,
+ TargetKind::Lib |
+ TargetKind::Bin |
+ TargetKind::Example |
+ TargetKind::Test |
+ TargetKind::Bench |
+ TargetKind::CustomBuild |
+ TargetKind::ProcMacro => true,
_ => false,
}
}
// parens, braces, and brackets in its idiomatic formatting.
fn is_block_expr(context: &RewriteContext, expr: &ast::Expr, repr: &str) -> bool {
match expr.node {
- ast::ExprKind::Mac(..) |
- ast::ExprKind::Call(..) => context.use_block_indent() && repr.contains('\n'),
+ ast::ExprKind::Mac(..) | ast::ExprKind::Call(..) => {
+ context.use_block_indent() && repr.contains('\n')
+ }
ast::ExprKind::Struct(..) |
ast::ExprKind::While(..) |
ast::ExprKind::WhileLet(..) |
CommentStyle::Custom(..) |
CommentStyle::Doc => "",
CommentStyle::DoubleBullet => " **/",
- CommentStyle::SingleBullet |
- CommentStyle::Exclamation => " */",
+ CommentStyle::SingleBullet | CommentStyle::Exclamation => " */",
}
}
CommentStyle::DoubleSlash => "// ",
CommentStyle::TripleSlash => "/// ",
CommentStyle::Doc => "//! ",
- CommentStyle::SingleBullet |
- CommentStyle::Exclamation => " * ",
+ CommentStyle::SingleBullet | CommentStyle::Exclamation => " * ",
CommentStyle::DoubleBullet => " ** ",
CommentStyle::Custom(opener) => opener,
}
pub fn line_with_same_comment_style(&self, line: &str, normalize_comments: bool) -> bool {
match *self {
- CommentStyle::DoubleSlash |
- CommentStyle::TripleSlash |
- CommentStyle::Doc => {
+ CommentStyle::DoubleSlash | CommentStyle::TripleSlash | CommentStyle::Doc => {
line.trim_left().starts_with(self.line_start().trim_left()) ||
comment_style(line, normalize_comments) == *self
}
- CommentStyle::DoubleBullet |
- CommentStyle::SingleBullet |
- CommentStyle::Exclamation => {
+ CommentStyle::DoubleBullet | CommentStyle::SingleBullet | CommentStyle::Exclamation => {
line.trim_left().starts_with(self.closer().trim_left()) ||
line.trim_left().starts_with(self.line_start().trim_left()) ||
comment_style(line, normalize_comments) == *self
pub fn to_list_tactic(self) -> ListTactic {
match self {
Density::Compressed => ListTactic::Mixed,
- Density::Tall |
- Density::CompressedIfEmpty => ListTactic::HorizontalVertical,
+ Density::Tall | Density::CompressedIfEmpty => ListTactic::HorizontalVertical,
Density::Vertical => ListTactic::Vertical,
}
}
}
// We do not format these expressions yet, but they should still
// satisfy our width restrictions.
- ast::ExprKind::InPlace(..) |
- ast::ExprKind::InlineAsm(..) => {
+ ast::ExprKind::InPlace(..) | ast::ExprKind::InlineAsm(..) => {
wrap_str(
context.snippet(expr.span),
context.config.max_width(),
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
let result = match self.node {
ast::StmtKind::Local(ref local) => local.rewrite(context, shape),
- ast::StmtKind::Expr(ref ex) |
- ast::StmtKind::Semi(ref ex) => {
+ ast::StmtKind::Expr(ref ex) | ast::StmtKind::Semi(ref ex) => {
let suffix = if semicolon_for_stmt(self) { ";" } else { "" };
format_expr(
try_opt!(shape.sub_width(suffix.len())),
).map(|s| s + suffix)
}
- ast::StmtKind::Mac(..) |
- ast::StmtKind::Item(..) => None,
+ ast::StmtKind::Mac(..) | ast::StmtKind::Item(..) => None,
};
result.and_then(|res| {
recover_comment_removed(res, self.span, context, shape)
let after_else_comment = extract_comment(after_else, context, shape);
let between_sep = match context.config.control_brace_style() {
- ControlBraceStyle::AlwaysNextLine |
- ControlBraceStyle::ClosingNextLine => &*alt_block_sep,
+ ControlBraceStyle::AlwaysNextLine | ControlBraceStyle::ClosingNextLine => {
+ &*alt_block_sep
+ }
ControlBraceStyle::AlwaysSameLine => " ",
};
let after_sep = match context.config.control_brace_style() {
}
}
ast::ExprKind::Call(_, ref args) => (args.len() == 1, &**body),
- ast::ExprKind::Closure(..) |
- ast::ExprKind::Struct(..) |
- ast::ExprKind::Tup(..) => (true, &**body),
+ ast::ExprKind::Closure(..) | ast::ExprKind::Struct(..) | ast::ExprKind::Tup(..) => (
+ true,
+ &**body,
+ ),
_ => (false, &**body),
};
extend &= context.use_block_indent();
ast::ExprKind::WhileLet(..) => {
context.config.combine_control_expr() && context.use_block_indent() && args_len == 1
}
- ast::ExprKind::Block(..) |
- ast::ExprKind::Closure(..) => {
+ ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => {
context.use_block_indent() ||
context.config.fn_call_style() == IndentStyle::Visual && args_len > 1
}
}
let variant_body = match field.node.data {
- ast::VariantData::Tuple(..) |
- ast::VariantData::Struct(..) => {
+ ast::VariantData::Tuple(..) | ast::VariantData::Struct(..) => {
// FIXME: Should limit the width, as we have a trailing comma
format_struct(
&context,
if let Some(ref trait_ref) = *trait_ref {
let result_len = result.len();
- if let Some(trait_ref_str) =
- rewrite_trait_ref(
- context,
- &trait_ref,
- offset,
- &generics_str,
- true,
- polarity_str,
- result_len,
- ) {
+ if let Some(trait_ref_str) = rewrite_trait_ref(
+ context,
+ &trait_ref,
+ offset,
+ &generics_str,
+ true,
+ polarity_str,
+ result_len,
+ ) {
result.push_str(&trait_ref_str);
} else {
let generics_str = try_opt!(rewrite_generics_inner(
.max_width()
.checked_sub(last_line_width(&result))
);
- if let Some(where_clause_str) =
- rewrite_where_clause(
- context,
- where_clause,
- context.config.fn_brace_style(),
- Shape::legacy(budget, indent),
- Density::Compressed,
- "{",
- !has_braces,
- put_args_in_block && ret_str.is_empty(),
- Some(span.hi),
- ) {
+ if let Some(where_clause_str) = rewrite_where_clause(
+ context,
+ where_clause,
+ context.config.fn_brace_style(),
+ Shape::legacy(budget, indent),
+ Density::Compressed,
+ "{",
+ !has_braces,
+ put_args_in_block && ret_str.is_empty(),
+ Some(span.hi),
+ ) {
if !where_clause_str.contains('\n') {
if last_line_width(&result) + where_clause_str.len() > context.config.max_width() {
result.push('\n');
// If the brace is on the next line we don't need to count it otherwise it needs two
// characters " {"
match brace_style {
- BraceStyle::AlwaysNextLine |
- BraceStyle::SameLineWhere => 0,
+ BraceStyle::AlwaysNextLine | BraceStyle::SameLineWhere => 0,
BraceStyle::PreferSameLine => 2,
}
} else if terminator == "=" {
impl FormattingError {
fn msg_prefix(&self) -> &str {
match self.kind {
- ErrorKind::LineOverflow(..) |
- ErrorKind::TrailingWhitespace => "Rustfmt failed at",
+ ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace => "Rustfmt failed at",
ErrorKind::BadIssue(_) => "WARNING:",
}
}
fn msg_suffix(&self) -> &str {
match self.kind {
- ErrorKind::LineOverflow(..) |
- ErrorKind::TrailingWhitespace => "(sorry)",
+ ErrorKind::LineOverflow(..) | ErrorKind::TrailingWhitespace => "(sorry)",
ErrorKind::BadIssue(_) => "",
}
}
match pat {
&TuplePatField::Pat(ref pat) => {
match pat.node {
- ast::PatKind::Path(..) |
- ast::PatKind::Tuple(..) |
- ast::PatKind::Struct(..) => context.use_block_indent() && len == 1,
- ast::PatKind::Ref(ref p, _) |
- ast::PatKind::Box(ref p) => {
+ ast::PatKind::Path(..) | ast::PatKind::Tuple(..) | ast::PatKind::Struct(..) => {
+ context.use_block_indent() && len == 1
+ }
+ ast::PatKind::Ref(ref p, _) | ast::PatKind::Box(ref p) => {
can_be_overflowed_pat(context, &TuplePatField::Pat(p), len)
}
ast::PatKind::Lit(ref expr) => can_be_overflowed_expr(context, expr, len),
it.rewrite(context, shape)
.map(|it_str| format!("impl {}", it_str))
}
- ast::TyKind::Err |
- ast::TyKind::Typeof(..) => unreachable!(),
+ ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
}
}
}
pub fn can_be_overflowed_type(context: &RewriteContext, ty: &ast::Ty, len: usize) -> bool {
match ty.node {
- ast::TyKind::Path(..) |
- ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
- ast::TyKind::Rptr(_, ref mutty) |
- ast::TyKind::Ptr(ref mutty) => can_be_overflowed_type(context, &*mutty.ty, len),
+ ast::TyKind::Path(..) | ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
+ ast::TyKind::Rptr(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
+ can_be_overflowed_type(context, &*mutty.ty, len)
+ }
_ => false,
}
}
#[inline]
pub fn semicolon_for_expr(expr: &ast::Expr) -> bool {
match expr.node {
- ast::ExprKind::Ret(..) |
- ast::ExprKind::Continue(..) |
- ast::ExprKind::Break(..) => true,
+ ast::ExprKind::Ret(..) | ast::ExprKind::Continue(..) | ast::ExprKind::Break(..) => true,
_ => false,
}
}
let where_span_end = snippet
.find_uncommented("{")
.map(|x| (BytePos(x as u32)) + source!(self, item.span).lo);
- if let Some(impl_str) = format_impl(
- &self.get_context(),
- item,
- self.block_indent,
- where_span_end,
- ) {
+ if let Some(impl_str) =
+ format_impl(&self.get_context(), item, self.block_indent, where_span_end)
+ {
self.buffer.push_str(&impl_str);
self.last_pos = source!(self, item.span).hi;
}
}
ast::ItemKind::Trait(..) => {
self.format_missing_with_indent(item.span.lo);
- if let Some(trait_str) = format_trait(
- &self.get_context(),
- item,
- self.block_indent,
- ) {
+ if let Some(trait_str) =
+ format_trait(&self.get_context(), item, self.block_indent)
+ {
self.buffer.push_str(&trait_str);
self.last_pos = source!(self, item.span).hi;
}