&-matches: dogfood fixes!
This commit is contained in:
parent
017dac2301
commit
8f1a237493
@ -37,10 +37,10 @@ impl LintPass for ApproxConstant {
|
||||
}
|
||||
|
||||
fn check_lit(cx: &Context, lit: &Lit, span: Span) {
|
||||
match &lit.node {
|
||||
&LitFloat(ref str, TyF32) => check_known_consts(cx, span, str, "f32"),
|
||||
&LitFloat(ref str, TyF64) => check_known_consts(cx, span, str, "f64"),
|
||||
&LitFloatUnsuffixed(ref str) => check_known_consts(cx, span, str, "f{32, 64}"),
|
||||
match lit.node {
|
||||
LitFloat(ref str, TyF32) => check_known_consts(cx, span, str, "f32"),
|
||||
LitFloat(ref str, TyF64) => check_known_consts(cx, span, str, "f64"),
|
||||
LitFloatUnsuffixed(ref str) => check_known_consts(cx, span, str, "f{32, 64}"),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
@ -82,9 +82,9 @@ fn invert_cmp(cmp : BinOp_) -> BinOp_ {
|
||||
|
||||
|
||||
fn check_compare(cx: &Context, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u64, span: &Span) {
|
||||
match &bit_op.node {
|
||||
&ExprParen(ref subexp) => check_compare(cx, subexp, cmp_op, cmp_value, span),
|
||||
&ExprBinary(ref op, ref left, ref right) => {
|
||||
match bit_op.node {
|
||||
ExprParen(ref subexp) => check_compare(cx, subexp, cmp_op, cmp_value, span),
|
||||
ExprBinary(ref op, ref left, ref right) => {
|
||||
if op.node != BiBitAnd && op.node != BiBitOr { return; }
|
||||
fetch_int_literal(cx, right).or_else(|| fetch_int_literal(
|
||||
cx, left)).map_or((), |mask| check_bit_mask(cx, op.node,
|
||||
@ -182,13 +182,13 @@ fn check_ineffective_gt(cx: &Context, span: Span, m: u64, c: u64, op: &str) {
|
||||
}
|
||||
|
||||
fn fetch_int_literal(cx: &Context, lit : &Expr) -> Option<u64> {
|
||||
match &lit.node {
|
||||
&ExprLit(ref lit_ptr) => {
|
||||
match lit.node {
|
||||
ExprLit(ref lit_ptr) => {
|
||||
if let &LitInt(value, _) = &lit_ptr.node {
|
||||
Option::Some(value) //TODO: Handle sign
|
||||
} else { Option::None }
|
||||
},
|
||||
&ExprPath(_, _) => {
|
||||
ExprPath(_, _) => {
|
||||
// Important to let the borrow expire before the const lookup to avoid double
|
||||
// borrowing.
|
||||
let def_map = cx.tcx.def_map.borrow();
|
||||
|
@ -18,9 +18,9 @@ impl LintPass for EtaPass {
|
||||
}
|
||||
|
||||
fn check_expr(&mut self, cx: &Context, expr: &Expr) {
|
||||
match &expr.node {
|
||||
&ExprCall(_, ref args) |
|
||||
&ExprMethodCall(_, _, ref args) => {
|
||||
match expr.node {
|
||||
ExprCall(_, ref args) |
|
||||
ExprMethodCall(_, _, ref args) => {
|
||||
for arg in args {
|
||||
check_closure(cx, &*arg)
|
||||
}
|
||||
|
@ -22,10 +22,10 @@ impl LintPass for LenZero {
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &Context, item: &Item) {
|
||||
match &item.node {
|
||||
&ItemTrait(_, _, _, ref trait_items) =>
|
||||
match item.node {
|
||||
ItemTrait(_, _, _, ref trait_items) =>
|
||||
check_trait_items(cx, item, trait_items),
|
||||
&ItemImpl(_, _, _, None, _, ref impl_items) => // only non-trait
|
||||
ItemImpl(_, _, _, None, _, ref impl_items) => // only non-trait
|
||||
check_impl_items(cx, item, impl_items),
|
||||
_ => ()
|
||||
}
|
||||
@ -100,7 +100,7 @@ fn check_cmp(cx: &Context, span: Span, left: &Expr, right: &Expr, op: &str) {
|
||||
|
||||
fn check_len_zero(cx: &Context, span: Span, method: &SpannedIdent,
|
||||
args: &[P<Expr>], lit: &Lit, op: &str) {
|
||||
if let &Spanned{node: LitInt(0, _), ..} = lit {
|
||||
if let Spanned{node: LitInt(0, _), ..} = *lit {
|
||||
if method.node.name == "len" && args.len() == 1 &&
|
||||
has_is_empty(cx, &*args[0]) {
|
||||
span_lint(cx, LEN_ZERO, span, &format!(
|
||||
|
@ -175,8 +175,8 @@ impl LintPass for CmpOwned {
|
||||
}
|
||||
|
||||
fn check_to_owned(cx: &Context, expr: &Expr, other_span: Span) {
|
||||
match &expr.node {
|
||||
&ExprMethodCall(Spanned{node: ref ident, ..}, _, ref args) => {
|
||||
match expr.node {
|
||||
ExprMethodCall(Spanned{node: ref ident, ..}, _, ref args) => {
|
||||
let name = ident.name;
|
||||
if name == "to_string" ||
|
||||
name == "to_owned" && is_str_arg(cx, args) {
|
||||
@ -186,7 +186,7 @@ fn check_to_owned(cx: &Context, expr: &Expr, other_span: Span) {
|
||||
snippet(cx, other_span, "..")))
|
||||
}
|
||||
},
|
||||
&ExprCall(ref path, _) => {
|
||||
ExprCall(ref path, _) => {
|
||||
if let &ExprPath(None, ref path) = &path.node {
|
||||
if match_path(path, &["String", "from_str"]) ||
|
||||
match_path(path, &["String", "from"]) {
|
||||
|
@ -60,9 +60,9 @@ fn fetch_bool_block(block: &Block) -> Option<bool> {
|
||||
}
|
||||
|
||||
fn fetch_bool_expr(expr: &Expr) -> Option<bool> {
|
||||
match &expr.node {
|
||||
&ExprBlock(ref block) => fetch_bool_block(block),
|
||||
&ExprLit(ref lit_ptr) => if let &LitBool(value) = &lit_ptr.node {
|
||||
match expr.node {
|
||||
ExprBlock(ref block) => fetch_bool_block(block),
|
||||
ExprLit(ref lit_ptr) => if let LitBool(value) = lit_ptr.node {
|
||||
Some(value) } else { None },
|
||||
_ => None
|
||||
}
|
||||
|
@ -65,13 +65,13 @@ fn is_string(cx: &Context, e: &Expr) -> bool {
|
||||
}
|
||||
|
||||
fn is_add(cx: &Context, src: &Expr, target: &Expr) -> bool {
|
||||
match &src.node {
|
||||
&ExprBinary(Spanned{ node: BiAdd, .. }, ref left, _) =>
|
||||
match src.node {
|
||||
ExprBinary(Spanned{ node: BiAdd, .. }, ref left, _) =>
|
||||
is_exp_equal(cx, target, left),
|
||||
&ExprBlock(ref block) => block.stmts.is_empty() &&
|
||||
ExprBlock(ref block) => block.stmts.is_empty() &&
|
||||
block.expr.as_ref().map_or(false,
|
||||
|expr| is_add(cx, &*expr, target)),
|
||||
&ExprParen(ref expr) => is_add(cx, &*expr, target),
|
||||
ExprParen(ref expr) => is_add(cx, &*expr, target),
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
16
src/types.rs
16
src/types.rs
@ -116,10 +116,10 @@ declare_lint!(pub CAST_POSSIBLE_TRUNCATION, Allow,
|
||||
/// Returns the size in bits of an integral type.
|
||||
/// Will return 0 if the type is not an int or uint variant
|
||||
fn int_ty_to_nbits(typ: &ty::TyS) -> usize {
|
||||
let n = match &typ.sty {
|
||||
&ty::TyInt(i) => 4 << (i as usize),
|
||||
&ty::TyUint(u) => 4 << (u as usize),
|
||||
_ => 0
|
||||
let n = match typ.sty {
|
||||
ty::TyInt(i) => 4 << (i as usize),
|
||||
ty::TyUint(u) => 4 << (u as usize),
|
||||
_ => 0
|
||||
};
|
||||
// n == 4 is the usize/isize case
|
||||
if n == 4 { ::std::usize::BITS } else { n }
|
||||
@ -139,16 +139,16 @@ impl LintPass for CastPass {
|
||||
match (cast_from.is_integral(), cast_to.is_integral()) {
|
||||
(true, false) => {
|
||||
let from_nbits = int_ty_to_nbits(cast_from);
|
||||
let to_nbits : usize = match &cast_to.sty {
|
||||
&ty::TyFloat(ast::TyF32) => 32,
|
||||
&ty::TyFloat(ast::TyF64) => 64,
|
||||
let to_nbits : usize = match cast_to.sty {
|
||||
ty::TyFloat(ast::TyF32) => 32,
|
||||
ty::TyFloat(ast::TyF64) => 64,
|
||||
_ => 0
|
||||
};
|
||||
if from_nbits != 0 {
|
||||
if from_nbits >= to_nbits {
|
||||
span_lint(cx, CAST_PRECISION_LOSS, expr.span,
|
||||
&format!("converting from {0} to {1}, which causes a loss of precision \
|
||||
({0} is {2} bits wide, but {1}'s mantissa is only {3} bits wide)",
|
||||
({0} is {2} bits wide, but {1}'s mantissa is only {3} bits wide)",
|
||||
cast_from, cast_to, from_nbits, if to_nbits == 64 {52} else {23} ));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user