Merge pull request #457 from sanxiyn/match-block-comma

Remove trailing commas in match arms with blocks
This commit is contained in:
Manish Goregaokar 2015-11-17 10:27:07 +05:30
commit 51a25295fd
16 changed files with 53 additions and 53 deletions

View File

@ -185,7 +185,7 @@ fn fetch_int_literal(cx: &LateContext, lit : &Expr) -> Option<u64> {
if let &LitInt(value, _) = &lit_ptr.node { if let &LitInt(value, _) = &lit_ptr.node {
Option::Some(value) //TODO: Handle sign Option::Some(value) //TODO: Handle sign
} else { Option::None } } else { Option::None }
}, }
ExprPath(_, _) => { ExprPath(_, _) => {
// Important to let the borrow expire before the const lookup to avoid double // Important to let the borrow expire before the const lookup to avoid double
// borrowing. // borrowing.

View File

@ -246,7 +246,7 @@ fn constant_not(o: Constant) -> Option<Constant> {
SignedIntLit(ity, Plus) => { SignedIntLit(ity, Plus) => {
if value == ::std::u64::MAX { return None; } if value == ::std::u64::MAX { return None; }
(value + 1, SignedIntLit(ity, Minus)) (value + 1, SignedIntLit(ity, Minus))
}, }
SignedIntLit(ity, Minus) => { SignedIntLit(ity, Minus) => {
if value == 0 { if value == 0 {
(1, SignedIntLit(ity, Minus)) (1, SignedIntLit(ity, Minus))
@ -267,7 +267,7 @@ fn constant_not(o: Constant) -> Option<Constant> {
UnsuffixedIntLit(_) => { return None; } // refuse to guess UnsuffixedIntLit(_) => { return None; } // refuse to guess
}; };
ConstantInt(nvalue, nty) ConstantInt(nvalue, nty)
}, }
_ => { return None; } _ => { return None; }
}) })
} }
@ -279,11 +279,11 @@ fn constant_negate(o: Constant) -> Option<Constant> {
SignedIntLit(ity, sign) => SignedIntLit(ity, sign) =>
SignedIntLit(ity, neg_sign(sign)), SignedIntLit(ity, neg_sign(sign)),
UnsuffixedIntLit(sign) => UnsuffixedIntLit(neg_sign(sign)), UnsuffixedIntLit(sign) => UnsuffixedIntLit(neg_sign(sign)),
_ => { return None; }, _ => { return None; }
}), }),
ConstantFloat(is, ty) => ConstantFloat(is, ty) =>
ConstantFloat(neg_float_str(is), ty), ConstantFloat(neg_float_str(is), ty),
_ => { return None; }, _ => { return None; }
}) })
} }
@ -461,7 +461,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
add_neg_int(l64, lty, r64, rty) add_neg_int(l64, lty, r64, rty)
} }
} }
}, }
// TODO: float (would need bignum library?) // TODO: float (would need bignum library?)
_ => None _ => None
}), }),
@ -513,7 +513,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
unify_int_type(lty, rty, if is_negative(lty) == unify_int_type(lty, rty, if is_negative(lty) ==
is_negative(rty) { Plus } else { Minus }) is_negative(rty) { Plus } else { Minus })
.map(|ty| ConstantInt(value, ty))) .map(|ty| ConstantInt(value, ty)))
}, }
_ => None, _ => None,
}) })
} }

View File

@ -26,7 +26,7 @@ impl LateLintPass for EtaPass {
for arg in args { for arg in args {
check_closure(cx, arg) check_closure(cx, arg)
} }
}, }
_ => (), _ => (),
} }
} }

View File

@ -26,19 +26,19 @@ impl LateLintPass for IdentityOp {
BiAdd | BiBitOr | BiBitXor => { BiAdd | BiBitOr | BiBitXor => {
check(cx, left, 0, e.span, right.span); check(cx, left, 0, e.span, right.span);
check(cx, right, 0, e.span, left.span); check(cx, right, 0, e.span, left.span);
}, }
BiShl | BiShr | BiSub => BiShl | BiShr | BiSub =>
check(cx, right, 0, e.span, left.span), check(cx, right, 0, e.span, left.span),
BiMul => { BiMul => {
check(cx, left, 1, e.span, right.span); check(cx, left, 1, e.span, right.span);
check(cx, right, 1, e.span, left.span); check(cx, right, 1, e.span, left.span);
}, }
BiDiv => BiDiv =>
check(cx, right, 1, e.span, left.span), check(cx, right, 1, e.span, left.span),
BiBitAnd => { BiBitAnd => {
check(cx, left, -1, e.span, right.span); check(cx, left, -1, e.span, right.span);
check(cx, right, -1, e.span, left.span); check(cx, right, -1, e.span, left.span);
}, }
_ => () _ => ()
} }
} }

View File

@ -196,13 +196,13 @@ impl <'v, 't> RefVisitor<'v, 't> {
self.record(&None); self.record(&None);
} }
} }
}, }
Some(DefTrait(def_id)) => { Some(DefTrait(def_id)) => {
let trait_def = self.cx.tcx.trait_defs.borrow()[&def_id]; let trait_def = self.cx.tcx.trait_defs.borrow()[&def_id];
for _ in &trait_def.generics.regions { for _ in &trait_def.generics.regions {
self.record(&None); self.record(&None);
} }
}, }
_ => {} _ => {}
} }
} }
@ -221,10 +221,10 @@ impl<'v, 't> Visitor<'v> for RefVisitor<'v, 't> {
match ty.node { match ty.node {
TyRptr(None, _) => { TyRptr(None, _) => {
self.record(&None); self.record(&None);
}, }
TyPath(_, ref path) => { TyPath(_, ref path) => {
self.collect_anonymous_lifetimes(path, ty); self.collect_anonymous_lifetimes(path, ty);
}, }
_ => {} _ => {}
} }
walk_ty(self, ty); walk_ty(self, ty);

View File

@ -545,13 +545,13 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
match parent.node { match parent.node {
ExprAssignOp(_, ref lhs, _) if lhs.id == expr.id => { ExprAssignOp(_, ref lhs, _) if lhs.id == expr.id => {
self.state = VarState::DontWarn; self.state = VarState::DontWarn;
}, }
ExprAssign(ref lhs, ref rhs) if lhs.id == expr.id => { ExprAssign(ref lhs, ref rhs) if lhs.id == expr.id => {
self.state = if is_integer_literal(rhs, 0) && self.depth == 0 { self.state = if is_integer_literal(rhs, 0) && self.depth == 0 {
VarState::Warn VarState::Warn
} else { } else {
VarState::DontWarn VarState::DontWarn
}}, }}
ExprAddrOf(mutability,_) if mutability == MutMutable => self.state = VarState::DontWarn, ExprAddrOf(mutability,_) if mutability == MutMutable => self.state = VarState::DontWarn,
_ => () _ => ()
} }

View File

@ -55,7 +55,7 @@ impl LateLintPass for MapClonePass {
} }
} }
} }
}, }
ExprPath(_, ref path) => { ExprPath(_, ref path) => {
if match_path(path, &CLONE_PATH) { if match_path(path, &CLONE_PATH) {
let type_name = get_type_name(cx, expr, &args[0]).unwrap_or("_"); let type_name = get_type_name(cx, expr, &args[0]).unwrap_or("_");
@ -77,7 +77,7 @@ fn expr_eq_ident(expr: &Expr, id: Ident) -> bool {
ExprPath(None, ref path) => { ExprPath(None, ref path) => {
let arg_segment = [PathSegment { identifier: id, parameters: PathParameters::none() }]; let arg_segment = [PathSegment { identifier: id, parameters: PathParameters::none() }];
!path.global && path.segments == arg_segment !path.global && path.segments == arg_segment
}, }
_ => false, _ => false,
} }
} }
@ -104,7 +104,7 @@ fn only_derefs(cx: &LateContext, expr: &Expr, id: Ident) -> bool {
match expr.node { match expr.node {
ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => { ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => {
only_derefs(cx, subexpr, id) only_derefs(cx, subexpr, id)
}, }
_ => expr_eq_ident(expr, id), _ => expr_eq_ident(expr, id),
} }
} }

View File

@ -31,7 +31,7 @@ impl LateLintPass for MinMaxPass {
_ => { _ => {
span_lint(cx, MIN_MAX, expr.span, span_lint(cx, MIN_MAX, expr.span,
"this min/max combination leads to constant result") "this min/max combination leads to constant result")
}, }
} }
} }
} }

View File

@ -187,7 +187,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other_span: Span, left: bool, o
} else { } else {
return return
} }
}, }
ExprCall(ref path, ref v) if v.len() == 1 => { ExprCall(ref path, ref v) if v.len() == 1 => {
if let &ExprPath(None, ref path) = &path.node { if let &ExprPath(None, ref path) = &path.node {
if match_path(path, &["String", "from_str"]) || if match_path(path, &["String", "from_str"]) ||
@ -199,7 +199,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other_span: Span, left: bool, o
} else { } else {
return return
} }
}, }
_ => return _ => return
}; };
if left { if left {

View File

@ -32,14 +32,14 @@ impl LateLintPass for UnnecessaryMutPassed {
check_arguments(cx, &arguments, function_type, check_arguments(cx, &arguments, function_type,
&format!("{}", path)); &format!("{}", path));
} }
}, }
None => unreachable!(), // A function with unknown type is called. None => unreachable!(), // A function with unknown type is called.
// If this happened the compiler would have aborted the // If this happened the compiler would have aborted the
// compilation long ago. // compilation long ago.
}; };
}, }
ExprMethodCall(ref name, _, ref arguments) => { ExprMethodCall(ref name, _, ref arguments) => {
let method_call = MethodCall::expr(e.id); let method_call = MethodCall::expr(e.id);
match borrowed_table.method_map.get(&method_call) { match borrowed_table.method_map.get(&method_call) {
@ -47,7 +47,7 @@ impl LateLintPass for UnnecessaryMutPassed {
&format!("{}", name.node.as_str())), &format!("{}", name.node.as_str())),
None => unreachable!(), // Just like above, this should never happen. None => unreachable!(), // Just like above, this should never happen.
}; };
}, }
_ => {} _ => {}
} }
} }
@ -66,7 +66,7 @@ fn check_arguments(cx: &LateContext, arguments: &[P<Expr>], type_definition: &Ty
doesn't need a mutable reference", doesn't need a mutable reference",
name)); name));
} }
}, }
_ => {} _ => {}
} }
} }

View File

@ -31,10 +31,10 @@ impl LateLintPass for NeedlessBool {
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) { match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
(Some(true), Some(true)) => { (Some(true), Some(true)) => {
span_lint(cx, NEEDLESS_BOOL, e.span, span_lint(cx, NEEDLESS_BOOL, e.span,
"this if-then-else expression will always return true"); }, "this if-then-else expression will always return true"); }
(Some(false), Some(false)) => { (Some(false), Some(false)) => {
span_lint(cx, NEEDLESS_BOOL, e.span, span_lint(cx, NEEDLESS_BOOL, e.span,
"this if-then-else expression will always return false"); }, "this if-then-else expression will always return false"); }
(Some(true), Some(false)) => { (Some(true), Some(false)) => {
let pred_snip = snippet(cx, pred.span, ".."); let pred_snip = snippet(cx, pred.span, "..");
let hint = if pred_snip == ".." { "its predicate".into() } else { let hint = if pred_snip == ".." { "its predicate".into() } else {
@ -42,7 +42,7 @@ impl LateLintPass for NeedlessBool {
}; };
span_lint(cx, NEEDLESS_BOOL, e.span, &format!( span_lint(cx, NEEDLESS_BOOL, e.span, &format!(
"you can reduce this if-then-else expression to just {}", hint)); "you can reduce this if-then-else expression to just {}", hint));
}, }
(Some(false), Some(true)) => { (Some(false), Some(true)) => {
let pred_snip = snippet(cx, pred.span, ".."); let pred_snip = snippet(cx, pred.span, "..");
let hint = if pred_snip == ".." { "`!` and its predicate".into() } else { let hint = if pred_snip == ".." { "`!` and its predicate".into() } else {
@ -50,7 +50,7 @@ impl LateLintPass for NeedlessBool {
}; };
span_lint(cx, NEEDLESS_BOOL, e.span, &format!( span_lint(cx, NEEDLESS_BOOL, e.span, &format!(
"you can reduce this if-then-else expression to just {}", hint)); "you can reduce this if-then-else expression to just {}", hint));
}, }
_ => () _ => ()
} }
} }

View File

@ -65,7 +65,7 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOp
// which is not a boolean literal. This is theoretically // which is not a boolean literal. This is theoretically
// possible, but not very likely. // possible, but not very likely.
} }
}, }
_ => { _ => {
Argument::Unknown Argument::Unknown
} }
@ -74,19 +74,19 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOp
match &*name.node.as_str() { match &*name.node.as_str() {
"create" => { "create" => {
options.push((OpenOption::Create, argument_option)); options.push((OpenOption::Create, argument_option));
}, }
"append" => { "append" => {
options.push((OpenOption::Append, argument_option)); options.push((OpenOption::Append, argument_option));
}, }
"truncate" => { "truncate" => {
options.push((OpenOption::Truncate, argument_option)); options.push((OpenOption::Truncate, argument_option));
}, }
"read" => { "read" => {
options.push((OpenOption::Read, argument_option)); options.push((OpenOption::Read, argument_option));
}, }
"write" => { "write" => {
options.push((OpenOption::Write, argument_option)); options.push((OpenOption::Write, argument_option));
}, }
_ => {} _ => {}
} }

View File

@ -101,7 +101,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span,
} }
} }
if let Some(ref p) = *inner { check_pat(cx, p, init, span, bindings); } if let Some(ref p) = *inner { check_pat(cx, p, init, span, bindings); }
}, }
//PatEnum(Path, Option<Vec<P<Pat>>>), //PatEnum(Path, Option<Vec<P<Pat>>>),
PatStruct(_, ref pfields, _) => PatStruct(_, ref pfields, _) =>
if let Some(ref init_struct) = *init { if let Some(ref init_struct) = *init {
@ -149,7 +149,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span,
} else { } else {
check_pat(cx, inner, init, span, bindings); check_pat(cx, inner, init, span, bindings);
} }
}, }
PatRegion(ref inner, _) => PatRegion(ref inner, _) =>
check_pat(cx, inner, init, span, bindings), check_pat(cx, inner, init, span, bindings),
//PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>), //PatVec(Vec<P<Pat>>, Option<P<Pat>>, Vec<P<Pat>>),
@ -200,9 +200,9 @@ fn check_expr(cx: &LateContext, expr: &Expr, bindings: &mut Vec<(Name, Span)>) {
match expr.node { match expr.node {
ExprUnary(_, ref e) | ExprField(ref e, _) | ExprUnary(_, ref e) | ExprField(ref e, _) |
ExprTupField(ref e, _) | ExprAddrOf(_, ref e) | ExprBox(ref e) ExprTupField(ref e, _) | ExprAddrOf(_, ref e) | ExprBox(ref e)
=> { check_expr(cx, e, bindings) }, => { check_expr(cx, e, bindings) }
ExprBlock(ref block) | ExprLoop(ref block, _) => ExprBlock(ref block) | ExprLoop(ref block, _) =>
{ check_block(cx, block, bindings) }, { check_block(cx, block, bindings) }
//ExprCall //ExprCall
//ExprMethodCall //ExprMethodCall
ExprVec(ref v) | ExprTup(ref v) => ExprVec(ref v) | ExprTup(ref v) =>
@ -211,11 +211,11 @@ fn check_expr(cx: &LateContext, expr: &Expr, bindings: &mut Vec<(Name, Span)>) {
check_expr(cx, cond, bindings); check_expr(cx, cond, bindings);
check_block(cx, then, bindings); check_block(cx, then, bindings);
if let &Some(ref o) = otherwise { check_expr(cx, o, bindings); } if let &Some(ref o) = otherwise { check_expr(cx, o, bindings); }
}, }
ExprWhile(ref cond, ref block, _) => { ExprWhile(ref cond, ref block, _) => {
check_expr(cx, cond, bindings); check_expr(cx, cond, bindings);
check_block(cx, block, bindings); check_block(cx, block, bindings);
}, }
ExprMatch(ref init, ref arms, _) => { ExprMatch(ref init, ref arms, _) => {
check_expr(cx, init, bindings); check_expr(cx, init, bindings);
let len = bindings.len(); let len = bindings.len();
@ -230,7 +230,7 @@ fn check_expr(cx: &LateContext, expr: &Expr, bindings: &mut Vec<(Name, Span)>) {
bindings.truncate(len); bindings.truncate(len);
} }
} }
}, }
_ => () _ => ()
} }
} }
@ -242,10 +242,10 @@ fn check_ty(cx: &LateContext, ty: &Ty, bindings: &mut Vec<(Name, Span)>) {
TyFixedLengthVec(ref fty, ref expr) => { TyFixedLengthVec(ref fty, ref expr) => {
check_ty(cx, fty, bindings); check_ty(cx, fty, bindings);
check_expr(cx, expr, bindings); check_expr(cx, expr, bindings);
}, }
TyPtr(MutTy{ ty: ref mty, .. }) | TyPtr(MutTy{ ty: ref mty, .. }) |
TyRptr(_, MutTy{ ty: ref mty, .. }) => check_ty(cx, mty, bindings), TyRptr(_, MutTy{ ty: ref mty, .. }) => check_ty(cx, mty, bindings),
TyTup(ref tup) => { for ref t in tup { check_ty(cx, t, bindings) } }, TyTup(ref tup) => { for ref t in tup { check_ty(cx, t, bindings) } }
TyTypeof(ref expr) => check_expr(cx, expr, bindings), TyTypeof(ref expr) => check_expr(cx, expr, bindings),
_ => (), _ => (),
} }

View File

@ -229,7 +229,7 @@ impl LateLintPass for CastPass {
if is_isize_or_usize(cast_from) || from_nbits >= to_nbits { if is_isize_or_usize(cast_from) || from_nbits >= to_nbits {
span_precision_loss_lint(cx, expr, cast_from, to_nbits == 64); span_precision_loss_lint(cx, expr, cast_from, to_nbits == 64);
} }
}, }
(false, true) => { (false, true) => {
span_lint(cx, CAST_POSSIBLE_TRUNCATION, expr.span, span_lint(cx, CAST_POSSIBLE_TRUNCATION, expr.span,
&format!("casting {} to {} may truncate the value", &format!("casting {} to {} may truncate the value",
@ -239,7 +239,7 @@ impl LateLintPass for CastPass {
&format!("casting {} to {} may lose the sign of the value", &format!("casting {} to {} may lose the sign of the value",
cast_from, cast_to)); cast_from, cast_to));
} }
}, }
(true, true) => { (true, true) => {
if cast_from.is_signed() && !cast_to.is_signed() { if cast_from.is_signed() && !cast_to.is_signed() {
span_lint(cx, CAST_SIGN_LOSS, expr.span, span_lint(cx, CAST_SIGN_LOSS, expr.span,

View File

@ -167,7 +167,7 @@ pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> {
Some(NodeTraitItem(&TraitItem{ id: _, ref name, .. })) | Some(NodeTraitItem(&TraitItem{ id: _, ref name, .. })) |
Some(NodeImplItem(&ImplItem{ id: _, ref name, .. })) => { Some(NodeImplItem(&ImplItem{ id: _, ref name, .. })) => {
Some(*name) Some(*name)
}, }
_ => None, _ => None,
} }
} }

View File

@ -54,17 +54,17 @@ fn match_bool() {
match test { //~ ERROR you seem to be trying to match on a boolean expression match test { //~ ERROR you seem to be trying to match on a boolean expression
true => (), true => (),
false => { println!("Noooo!"); }, false => { println!("Noooo!"); }
}; };
match test { //~ ERROR you seem to be trying to match on a boolean expression match test { //~ ERROR you seem to be trying to match on a boolean expression
false => { println!("Noooo!"); }, false => { println!("Noooo!"); }
_ => (), _ => (),
}; };
match test { //~ ERROR you seem to be trying to match on a boolean expression match test { //~ ERROR you seem to be trying to match on a boolean expression
false => { println!("Noooo!"); }, false => { println!("Noooo!"); }
true => { println!("Yes!"); }, true => { println!("Yes!"); }
}; };
// Not linted // Not linted