Cargo fmt
This commit is contained in:
parent
09d54512da
commit
34c2499029
@ -164,13 +164,13 @@ enum TargetKind {
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
@ -350,19 +350,19 @@ fn is_block_expr(context: &RewriteContext, expr: &ast::Expr, repr: &str) -> bool
|
||||
ast::ExprKind::Mac(..) | ast::ExprKind::Call(..) => {
|
||||
context.use_block_indent() && repr.contains('\n')
|
||||
}
|
||||
ast::ExprKind::Struct(..) |
|
||||
ast::ExprKind::While(..) |
|
||||
ast::ExprKind::WhileLet(..) |
|
||||
ast::ExprKind::If(..) |
|
||||
ast::ExprKind::IfLet(..) |
|
||||
ast::ExprKind::Block(..) |
|
||||
ast::ExprKind::Loop(..) |
|
||||
ast::ExprKind::ForLoop(..) |
|
||||
ast::ExprKind::Match(..) => repr.contains('\n'),
|
||||
ast::ExprKind::Paren(ref expr) |
|
||||
ast::ExprKind::Binary(_, _, ref expr) |
|
||||
ast::ExprKind::Index(_, ref expr) |
|
||||
ast::ExprKind::Unary(_, ref expr) => is_block_expr(context, expr, repr),
|
||||
ast::ExprKind::Struct(..)
|
||||
| ast::ExprKind::While(..)
|
||||
| ast::ExprKind::WhileLet(..)
|
||||
| ast::ExprKind::If(..)
|
||||
| ast::ExprKind::IfLet(..)
|
||||
| ast::ExprKind::Block(..)
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::ForLoop(..)
|
||||
| ast::ExprKind::Match(..) => repr.contains('\n'),
|
||||
ast::ExprKind::Paren(ref expr)
|
||||
| ast::ExprKind::Binary(_, _, ref expr)
|
||||
| ast::ExprKind::Index(_, ref expr)
|
||||
| ast::ExprKind::Unary(_, ref expr) => is_block_expr(context, expr, repr),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -396,9 +396,9 @@ fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext) -> Option<ast::Exp
|
||||
ast::ExprKind::MethodCall(_, ref expressions) => {
|
||||
Some(convert_try(&expressions[0], context))
|
||||
}
|
||||
ast::ExprKind::TupField(ref subexpr, _) |
|
||||
ast::ExprKind::Field(ref subexpr, _) |
|
||||
ast::ExprKind::Try(ref subexpr) => Some(convert_try(subexpr, context)),
|
||||
ast::ExprKind::TupField(ref subexpr, _)
|
||||
| ast::ExprKind::Field(ref subexpr, _)
|
||||
| ast::ExprKind::Try(ref subexpr) => Some(convert_try(subexpr, context)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -328,17 +328,17 @@ where
|
||||
|
||||
fn is_block_closure_forced(expr: &ast::Expr) -> bool {
|
||||
match expr.node {
|
||||
ast::ExprKind::If(..) |
|
||||
ast::ExprKind::IfLet(..) |
|
||||
ast::ExprKind::Loop(..) |
|
||||
ast::ExprKind::While(..) |
|
||||
ast::ExprKind::WhileLet(..) |
|
||||
ast::ExprKind::ForLoop(..) => true,
|
||||
ast::ExprKind::AddrOf(_, ref expr) |
|
||||
ast::ExprKind::Box(ref expr) |
|
||||
ast::ExprKind::Try(ref expr) |
|
||||
ast::ExprKind::Unary(_, ref expr) |
|
||||
ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced(expr),
|
||||
ast::ExprKind::If(..)
|
||||
| ast::ExprKind::IfLet(..)
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::While(..)
|
||||
| ast::ExprKind::WhileLet(..)
|
||||
| ast::ExprKind::ForLoop(..) => true,
|
||||
ast::ExprKind::AddrOf(_, ref expr)
|
||||
| ast::ExprKind::Box(ref expr)
|
||||
| ast::ExprKind::Try(ref expr)
|
||||
| ast::ExprKind::Unary(_, ref expr)
|
||||
| ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced(expr),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -64,10 +64,10 @@ impl<'a> CommentStyle<'a> {
|
||||
|
||||
pub fn closer(&self) -> &'a str {
|
||||
match *self {
|
||||
CommentStyle::DoubleSlash |
|
||||
CommentStyle::TripleSlash |
|
||||
CommentStyle::Custom(..) |
|
||||
CommentStyle::Doc => "",
|
||||
CommentStyle::DoubleSlash
|
||||
| CommentStyle::TripleSlash
|
||||
| CommentStyle::Custom(..)
|
||||
| CommentStyle::Doc => "",
|
||||
CommentStyle::DoubleBullet => " **/",
|
||||
CommentStyle::SingleBullet | CommentStyle::Exclamation => " */",
|
||||
}
|
||||
@ -648,9 +648,9 @@ enum FullCodeCharKind {
|
||||
impl FullCodeCharKind {
|
||||
fn is_comment(&self) -> bool {
|
||||
match *self {
|
||||
FullCodeCharKind::StartComment |
|
||||
FullCodeCharKind::InComment |
|
||||
FullCodeCharKind::EndComment => true,
|
||||
FullCodeCharKind::StartComment
|
||||
| FullCodeCharKind::InComment
|
||||
| FullCodeCharKind::EndComment => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
54
src/expr.rs
54
src/expr.rs
@ -99,12 +99,12 @@ pub fn format_expr(
|
||||
ast::ExprKind::Tup(ref items) => {
|
||||
rewrite_tuple(context, &ptr_vec_to_ref_vec(items), expr.span, shape)
|
||||
}
|
||||
ast::ExprKind::If(..) |
|
||||
ast::ExprKind::IfLet(..) |
|
||||
ast::ExprKind::ForLoop(..) |
|
||||
ast::ExprKind::Loop(..) |
|
||||
ast::ExprKind::While(..) |
|
||||
ast::ExprKind::WhileLet(..) => to_control_flow(expr, expr_type)
|
||||
ast::ExprKind::If(..)
|
||||
| ast::ExprKind::IfLet(..)
|
||||
| ast::ExprKind::ForLoop(..)
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::While(..)
|
||||
| ast::ExprKind::WhileLet(..) => to_control_flow(expr, expr_type)
|
||||
.and_then(|control_flow| control_flow.rewrite(context, shape)),
|
||||
ast::ExprKind::Block(ref block) => {
|
||||
match expr_type {
|
||||
@ -161,10 +161,10 @@ pub fn format_expr(
|
||||
ast::ExprKind::Closure(capture, ref fn_decl, ref body, _) => {
|
||||
closures::rewrite_closure(capture, fn_decl, body, expr.span, context, shape)
|
||||
}
|
||||
ast::ExprKind::Try(..) |
|
||||
ast::ExprKind::Field(..) |
|
||||
ast::ExprKind::TupField(..) |
|
||||
ast::ExprKind::MethodCall(..) => rewrite_chain(expr, context, shape),
|
||||
ast::ExprKind::Try(..)
|
||||
| ast::ExprKind::Field(..)
|
||||
| ast::ExprKind::TupField(..)
|
||||
| ast::ExprKind::MethodCall(..) => rewrite_chain(expr, context, shape),
|
||||
ast::ExprKind::Mac(ref mac) => {
|
||||
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
|
||||
wrap_str(
|
||||
@ -2060,29 +2060,29 @@ pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_l
|
||||
(context.use_block_indent() && args_len == 1)
|
||||
|| (context.config.indent_style() == IndentStyle::Visual && args_len > 1)
|
||||
}
|
||||
ast::ExprKind::If(..) |
|
||||
ast::ExprKind::IfLet(..) |
|
||||
ast::ExprKind::ForLoop(..) |
|
||||
ast::ExprKind::Loop(..) |
|
||||
ast::ExprKind::While(..) |
|
||||
ast::ExprKind::WhileLet(..) => {
|
||||
ast::ExprKind::If(..)
|
||||
| ast::ExprKind::IfLet(..)
|
||||
| ast::ExprKind::ForLoop(..)
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::While(..)
|
||||
| ast::ExprKind::WhileLet(..) => {
|
||||
context.config.combine_control_expr() && context.use_block_indent() && args_len == 1
|
||||
}
|
||||
ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => {
|
||||
context.use_block_indent()
|
||||
|| context.config.indent_style() == IndentStyle::Visual && args_len > 1
|
||||
}
|
||||
ast::ExprKind::Array(..) |
|
||||
ast::ExprKind::Call(..) |
|
||||
ast::ExprKind::Mac(..) |
|
||||
ast::ExprKind::MethodCall(..) |
|
||||
ast::ExprKind::Struct(..) |
|
||||
ast::ExprKind::Tup(..) => context.use_block_indent() && args_len == 1,
|
||||
ast::ExprKind::AddrOf(_, ref expr) |
|
||||
ast::ExprKind::Box(ref expr) |
|
||||
ast::ExprKind::Try(ref expr) |
|
||||
ast::ExprKind::Unary(_, ref expr) |
|
||||
ast::ExprKind::Cast(ref expr, _) => can_be_overflowed_expr(context, expr, args_len),
|
||||
ast::ExprKind::Array(..)
|
||||
| ast::ExprKind::Call(..)
|
||||
| ast::ExprKind::Mac(..)
|
||||
| ast::ExprKind::MethodCall(..)
|
||||
| ast::ExprKind::Struct(..)
|
||||
| ast::ExprKind::Tup(..) => context.use_block_indent() && args_len == 1,
|
||||
ast::ExprKind::AddrOf(_, ref expr)
|
||||
| ast::ExprKind::Box(ref expr)
|
||||
| ast::ExprKind::Try(ref expr)
|
||||
| ast::ExprKind::Unary(_, ref expr)
|
||||
| ast::ExprKind::Cast(ref expr, _) => can_be_overflowed_expr(context, expr, args_len),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ use visitor::{rewrite_extern_crate, FmtVisitor};
|
||||
|
||||
fn path_of(a: &ast::ViewPath_) -> &ast::Path {
|
||||
match *a {
|
||||
ast::ViewPath_::ViewPathSimple(_, ref p) |
|
||||
ast::ViewPath_::ViewPathGlob(ref p) |
|
||||
ast::ViewPath_::ViewPathList(ref p, _) => p,
|
||||
ast::ViewPath_::ViewPathSimple(_, ref p)
|
||||
| ast::ViewPath_::ViewPathGlob(ref p)
|
||||
| ast::ViewPath_::ViewPathList(ref p, _) => p,
|
||||
}
|
||||
}
|
||||
|
||||
@ -366,10 +366,10 @@ impl<'a> ImportItem<'a> {
|
||||
|
||||
fn to_str(&self) -> Option<&str> {
|
||||
match *self {
|
||||
ImportItem::SelfImport(s) |
|
||||
ImportItem::SnakeCase(s) |
|
||||
ImportItem::CamelCase(s) |
|
||||
ImportItem::AllCaps(s) => Some(s),
|
||||
ImportItem::SelfImport(s)
|
||||
| ImportItem::SnakeCase(s)
|
||||
| ImportItem::CamelCase(s)
|
||||
| ImportItem::AllCaps(s) => Some(s),
|
||||
ImportItem::Invalid => None,
|
||||
}
|
||||
}
|
||||
|
@ -245,10 +245,10 @@ impl<'a> Spanned for TuplePatField<'a> {
|
||||
pub fn can_be_overflowed_pat(context: &RewriteContext, pat: &TuplePatField, len: usize) -> bool {
|
||||
match *pat {
|
||||
TuplePatField::Pat(pat) => match pat.node {
|
||||
ast::PatKind::Path(..) |
|
||||
ast::PatKind::Tuple(..) |
|
||||
ast::PatKind::Struct(..) |
|
||||
ast::PatKind::TupleStruct(..) => context.use_block_indent() && len == 1,
|
||||
ast::PatKind::Path(..)
|
||||
| ast::PatKind::Tuple(..)
|
||||
| ast::PatKind::Struct(..)
|
||||
| ast::PatKind::TupleStruct(..) => 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)
|
||||
}
|
||||
|
32
src/utils.rs
32
src/utils.rs
@ -240,10 +240,10 @@ pub fn semicolon_for_expr(context: &RewriteContext, expr: &ast::Expr) -> bool {
|
||||
pub fn semicolon_for_stmt(context: &RewriteContext, stmt: &ast::Stmt) -> bool {
|
||||
match stmt.node {
|
||||
ast::StmtKind::Semi(ref expr) => match expr.node {
|
||||
ast::ExprKind::While(..) |
|
||||
ast::ExprKind::WhileLet(..) |
|
||||
ast::ExprKind::Loop(..) |
|
||||
ast::ExprKind::ForLoop(..) => false,
|
||||
ast::ExprKind::While(..)
|
||||
| ast::ExprKind::WhileLet(..)
|
||||
| ast::ExprKind::Loop(..)
|
||||
| ast::ExprKind::ForLoop(..) => false,
|
||||
ast::ExprKind::Break(..) | ast::ExprKind::Continue(..) | ast::ExprKind::Ret(..) => {
|
||||
context.config.trailing_semicolon()
|
||||
}
|
||||
@ -450,18 +450,18 @@ pub fn paren_overhead(context: &RewriteContext) -> usize {
|
||||
|
||||
pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr {
|
||||
match e.node {
|
||||
ast::ExprKind::InPlace(ref e, _) |
|
||||
ast::ExprKind::Call(ref e, _) |
|
||||
ast::ExprKind::Binary(_, ref e, _) |
|
||||
ast::ExprKind::Cast(ref e, _) |
|
||||
ast::ExprKind::Type(ref e, _) |
|
||||
ast::ExprKind::Assign(ref e, _) |
|
||||
ast::ExprKind::AssignOp(_, ref e, _) |
|
||||
ast::ExprKind::Field(ref e, _) |
|
||||
ast::ExprKind::TupField(ref e, _) |
|
||||
ast::ExprKind::Index(ref e, _) |
|
||||
ast::ExprKind::Range(Some(ref e), _, _) |
|
||||
ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
|
||||
ast::ExprKind::InPlace(ref e, _)
|
||||
| ast::ExprKind::Call(ref e, _)
|
||||
| ast::ExprKind::Binary(_, ref e, _)
|
||||
| ast::ExprKind::Cast(ref e, _)
|
||||
| ast::ExprKind::Type(ref e, _)
|
||||
| ast::ExprKind::Assign(ref e, _)
|
||||
| ast::ExprKind::AssignOp(_, ref e, _)
|
||||
| ast::ExprKind::Field(ref e, _)
|
||||
| ast::ExprKind::TupField(ref e, _)
|
||||
| ast::ExprKind::Index(ref e, _)
|
||||
| ast::ExprKind::Range(Some(ref e), _, _)
|
||||
| ast::ExprKind::Try(ref e) => left_most_sub_expr(e),
|
||||
_ => e,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user