mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-02 01:52:51 +00:00
Merge pull request #457 from sanxiyn/match-block-comma
Remove trailing commas in match arms with blocks
This commit is contained in:
commit
51a25295fd
@ -185,7 +185,7 @@ fn fetch_int_literal(cx: &LateContext, lit : &Expr) -> Option<u64> {
|
||||
if let &LitInt(value, _) = &lit_ptr.node {
|
||||
Option::Some(value) //TODO: Handle sign
|
||||
} else { Option::None }
|
||||
},
|
||||
}
|
||||
ExprPath(_, _) => {
|
||||
// Important to let the borrow expire before the const lookup to avoid double
|
||||
// borrowing.
|
||||
|
@ -246,7 +246,7 @@ fn constant_not(o: Constant) -> Option<Constant> {
|
||||
SignedIntLit(ity, Plus) => {
|
||||
if value == ::std::u64::MAX { return None; }
|
||||
(value + 1, SignedIntLit(ity, Minus))
|
||||
},
|
||||
}
|
||||
SignedIntLit(ity, Minus) => {
|
||||
if value == 0 {
|
||||
(1, SignedIntLit(ity, Minus))
|
||||
@ -267,7 +267,7 @@ fn constant_not(o: Constant) -> Option<Constant> {
|
||||
UnsuffixedIntLit(_) => { return None; } // refuse to guess
|
||||
};
|
||||
ConstantInt(nvalue, nty)
|
||||
},
|
||||
}
|
||||
_ => { return None; }
|
||||
})
|
||||
}
|
||||
@ -279,11 +279,11 @@ fn constant_negate(o: Constant) -> Option<Constant> {
|
||||
SignedIntLit(ity, sign) =>
|
||||
SignedIntLit(ity, neg_sign(sign)),
|
||||
UnsuffixedIntLit(sign) => UnsuffixedIntLit(neg_sign(sign)),
|
||||
_ => { return None; },
|
||||
_ => { return None; }
|
||||
}),
|
||||
ConstantFloat(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)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
// TODO: float (would need bignum library?)
|
||||
_ => None
|
||||
}),
|
||||
@ -513,7 +513,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
||||
unify_int_type(lty, rty, if is_negative(lty) ==
|
||||
is_negative(rty) { Plus } else { Minus })
|
||||
.map(|ty| ConstantInt(value, ty)))
|
||||
},
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ impl LateLintPass for EtaPass {
|
||||
for arg in args {
|
||||
check_closure(cx, arg)
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
@ -26,19 +26,19 @@ impl LateLintPass for IdentityOp {
|
||||
BiAdd | BiBitOr | BiBitXor => {
|
||||
check(cx, left, 0, e.span, right.span);
|
||||
check(cx, right, 0, e.span, left.span);
|
||||
},
|
||||
}
|
||||
BiShl | BiShr | BiSub =>
|
||||
check(cx, right, 0, e.span, left.span),
|
||||
BiMul => {
|
||||
check(cx, left, 1, e.span, right.span);
|
||||
check(cx, right, 1, e.span, left.span);
|
||||
},
|
||||
}
|
||||
BiDiv =>
|
||||
check(cx, right, 1, e.span, left.span),
|
||||
BiBitAnd => {
|
||||
check(cx, left, -1, e.span, right.span);
|
||||
check(cx, right, -1, e.span, left.span);
|
||||
},
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
@ -196,13 +196,13 @@ impl <'v, 't> RefVisitor<'v, 't> {
|
||||
self.record(&None);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Some(DefTrait(def_id)) => {
|
||||
let trait_def = self.cx.tcx.trait_defs.borrow()[&def_id];
|
||||
for _ in &trait_def.generics.regions {
|
||||
self.record(&None);
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
@ -221,10 +221,10 @@ impl<'v, 't> Visitor<'v> for RefVisitor<'v, 't> {
|
||||
match ty.node {
|
||||
TyRptr(None, _) => {
|
||||
self.record(&None);
|
||||
},
|
||||
}
|
||||
TyPath(_, ref path) => {
|
||||
self.collect_anonymous_lifetimes(path, ty);
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
walk_ty(self, ty);
|
||||
|
@ -545,13 +545,13 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> {
|
||||
match parent.node {
|
||||
ExprAssignOp(_, ref lhs, _) if lhs.id == expr.id => {
|
||||
self.state = VarState::DontWarn;
|
||||
},
|
||||
}
|
||||
ExprAssign(ref lhs, ref rhs) if lhs.id == expr.id => {
|
||||
self.state = if is_integer_literal(rhs, 0) && self.depth == 0 {
|
||||
VarState::Warn
|
||||
} else {
|
||||
VarState::DontWarn
|
||||
}},
|
||||
}}
|
||||
ExprAddrOf(mutability,_) if mutability == MutMutable => self.state = VarState::DontWarn,
|
||||
_ => ()
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ impl LateLintPass for MapClonePass {
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
ExprPath(_, ref path) => {
|
||||
if match_path(path, &CLONE_PATH) {
|
||||
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) => {
|
||||
let arg_segment = [PathSegment { identifier: id, parameters: PathParameters::none() }];
|
||||
!path.global && path.segments == arg_segment
|
||||
},
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -104,7 +104,7 @@ fn only_derefs(cx: &LateContext, expr: &Expr, id: Ident) -> bool {
|
||||
match expr.node {
|
||||
ExprUnary(UnDeref, ref subexpr) if !is_adjusted(cx, subexpr) => {
|
||||
only_derefs(cx, subexpr, id)
|
||||
},
|
||||
}
|
||||
_ => expr_eq_ident(expr, id),
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ impl LateLintPass for MinMaxPass {
|
||||
_ => {
|
||||
span_lint(cx, MIN_MAX, expr.span,
|
||||
"this min/max combination leads to constant result")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -187,7 +187,7 @@ fn check_to_owned(cx: &LateContext, expr: &Expr, other_span: Span, left: bool, o
|
||||
} else {
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
ExprCall(ref path, ref v) if v.len() == 1 => {
|
||||
if let &ExprPath(None, ref path) = &path.node {
|
||||
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 {
|
||||
return
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => return
|
||||
};
|
||||
if left {
|
||||
|
@ -32,14 +32,14 @@ impl LateLintPass for UnnecessaryMutPassed {
|
||||
check_arguments(cx, &arguments, function_type,
|
||||
&format!("{}", path));
|
||||
}
|
||||
},
|
||||
}
|
||||
None => unreachable!(), // A function with unknown type is called.
|
||||
// If this happened the compiler would have aborted the
|
||||
// compilation long ago.
|
||||
};
|
||||
|
||||
|
||||
},
|
||||
}
|
||||
ExprMethodCall(ref name, _, ref arguments) => {
|
||||
let method_call = MethodCall::expr(e.id);
|
||||
match borrowed_table.method_map.get(&method_call) {
|
||||
@ -47,7 +47,7 @@ impl LateLintPass for UnnecessaryMutPassed {
|
||||
&format!("{}", name.node.as_str())),
|
||||
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",
|
||||
name));
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ impl LateLintPass for NeedlessBool {
|
||||
match (fetch_bool_block(then_block), fetch_bool_expr(else_expr)) {
|
||||
(Some(true), Some(true)) => {
|
||||
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)) => {
|
||||
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)) => {
|
||||
let pred_snip = snippet(cx, pred.span, "..");
|
||||
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!(
|
||||
"you can reduce this if-then-else expression to just {}", hint));
|
||||
},
|
||||
}
|
||||
(Some(false), Some(true)) => {
|
||||
let pred_snip = snippet(cx, pred.span, "..");
|
||||
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!(
|
||||
"you can reduce this if-then-else expression to just {}", hint));
|
||||
},
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
// possible, but not very likely.
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => {
|
||||
Argument::Unknown
|
||||
}
|
||||
@ -74,19 +74,19 @@ fn get_open_options(cx: &LateContext, argument: &Expr, options: &mut Vec<(OpenOp
|
||||
match &*name.node.as_str() {
|
||||
"create" => {
|
||||
options.push((OpenOption::Create, argument_option));
|
||||
},
|
||||
}
|
||||
"append" => {
|
||||
options.push((OpenOption::Append, argument_option));
|
||||
},
|
||||
}
|
||||
"truncate" => {
|
||||
options.push((OpenOption::Truncate, argument_option));
|
||||
},
|
||||
}
|
||||
"read" => {
|
||||
options.push((OpenOption::Read, argument_option));
|
||||
},
|
||||
}
|
||||
"write" => {
|
||||
options.push((OpenOption::Write, argument_option));
|
||||
},
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
@ -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); }
|
||||
},
|
||||
}
|
||||
//PatEnum(Path, Option<Vec<P<Pat>>>),
|
||||
PatStruct(_, ref pfields, _) =>
|
||||
if let Some(ref init_struct) = *init {
|
||||
@ -149,7 +149,7 @@ fn check_pat(cx: &LateContext, pat: &Pat, init: &Option<&Expr>, span: Span,
|
||||
} else {
|
||||
check_pat(cx, inner, init, span, bindings);
|
||||
}
|
||||
},
|
||||
}
|
||||
PatRegion(ref inner, _) =>
|
||||
check_pat(cx, inner, init, span, bindings),
|
||||
//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 {
|
||||
ExprUnary(_, ref e) | ExprField(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, _) =>
|
||||
{ check_block(cx, block, bindings) },
|
||||
{ check_block(cx, block, bindings) }
|
||||
//ExprCall
|
||||
//ExprMethodCall
|
||||
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_block(cx, then, bindings);
|
||||
if let &Some(ref o) = otherwise { check_expr(cx, o, bindings); }
|
||||
},
|
||||
}
|
||||
ExprWhile(ref cond, ref block, _) => {
|
||||
check_expr(cx, cond, bindings);
|
||||
check_block(cx, block, bindings);
|
||||
},
|
||||
}
|
||||
ExprMatch(ref init, ref arms, _) => {
|
||||
check_expr(cx, init, bindings);
|
||||
let len = bindings.len();
|
||||
@ -230,7 +230,7 @@ fn check_expr(cx: &LateContext, expr: &Expr, bindings: &mut Vec<(Name, Span)>) {
|
||||
bindings.truncate(len);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
@ -242,10 +242,10 @@ fn check_ty(cx: &LateContext, ty: &Ty, bindings: &mut Vec<(Name, Span)>) {
|
||||
TyFixedLengthVec(ref fty, ref expr) => {
|
||||
check_ty(cx, fty, bindings);
|
||||
check_expr(cx, expr, bindings);
|
||||
},
|
||||
}
|
||||
TyPtr(MutTy{ ty: ref mty, .. }) |
|
||||
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),
|
||||
_ => (),
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ impl LateLintPass for CastPass {
|
||||
if is_isize_or_usize(cast_from) || from_nbits >= to_nbits {
|
||||
span_precision_loss_lint(cx, expr, cast_from, to_nbits == 64);
|
||||
}
|
||||
},
|
||||
}
|
||||
(false, true) => {
|
||||
span_lint(cx, CAST_POSSIBLE_TRUNCATION, expr.span,
|
||||
&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",
|
||||
cast_from, cast_to));
|
||||
}
|
||||
},
|
||||
}
|
||||
(true, true) => {
|
||||
if cast_from.is_signed() && !cast_to.is_signed() {
|
||||
span_lint(cx, CAST_SIGN_LOSS, expr.span,
|
||||
|
@ -167,7 +167,7 @@ pub fn get_item_name(cx: &LateContext, expr: &Expr) -> Option<Name> {
|
||||
Some(NodeTraitItem(&TraitItem{ id: _, ref name, .. })) |
|
||||
Some(NodeImplItem(&ImplItem{ id: _, ref name, .. })) => {
|
||||
Some(*name)
|
||||
},
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -54,17 +54,17 @@ fn match_bool() {
|
||||
|
||||
match test { //~ ERROR you seem to be trying to match on a boolean expression
|
||||
true => (),
|
||||
false => { println!("Noooo!"); },
|
||||
false => { println!("Noooo!"); }
|
||||
};
|
||||
|
||||
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
|
||||
false => { println!("Noooo!"); },
|
||||
true => { println!("Yes!"); },
|
||||
false => { println!("Noooo!"); }
|
||||
true => { println!("Yes!"); }
|
||||
};
|
||||
|
||||
// Not linted
|
||||
|
Loading…
Reference in New Issue
Block a user