Skip to content

Commit

Permalink
Dogfood new trivially_copy_pass_by_ref lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo157 committed Jun 15, 2018
1 parent 700ece5 commit 621fdcc
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 91 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/approx_const.rs
Expand Up @@ -71,14 +71,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {

fn check_lit(cx: &LateContext, lit: &Lit, e: &Expr) {
match lit.node {
LitKind::Float(ref s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
LitKind::Float(ref s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
LitKind::FloatUnsuffixed(ref s) => check_known_consts(cx, e, s, "f{32, 64}"),
LitKind::Float(s, FloatTy::F32) => check_known_consts(cx, e, s, "f32"),
LitKind::Float(s, FloatTy::F64) => check_known_consts(cx, e, s, "f64"),
LitKind::FloatUnsuffixed(s) => check_known_consts(cx, e, s, "f{32, 64}"),
_ => (),
}
}

fn check_known_consts(cx: &LateContext, e: &Expr, s: &symbol::Symbol, module: &str) {
fn check_known_consts(cx: &LateContext, e: &Expr, s: symbol::Symbol, module: &str) {
let s = s.as_str();
if s.parse::<f64>().is_ok() {
for &(constant, name, min_digits) in KNOWN_CONSTS {
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/attrs.rs
Expand Up @@ -151,7 +151,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {

fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if is_relevant_item(cx.tcx, item) {
check_attrs(cx, item.span, &item.name, &item.attrs)
check_attrs(cx, item.span, item.name, &item.attrs)
}
match item.node {
ItemExternCrate(_) | ItemUse(_, _) => {
Expand Down Expand Up @@ -195,13 +195,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {

fn check_impl_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx ImplItem) {
if is_relevant_impl(cx.tcx, item) {
check_attrs(cx, item.span, &item.name, &item.attrs)
check_attrs(cx, item.span, item.name, &item.attrs)
}
}

fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
if is_relevant_trait(cx.tcx, item) {
check_attrs(cx, item.span, &item.name, &item.attrs)
check_attrs(cx, item.span, item.name, &item.attrs)
}
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ fn is_relevant_expr(tcx: TyCtxt, tables: &ty::TypeckTables, expr: &Expr) -> bool
}
}

fn check_attrs(cx: &LateContext, span: Span, name: &Name, attrs: &[Attribute]) {
fn check_attrs(cx: &LateContext, span: Span, name: Name, attrs: &[Attribute]) {
if in_macro(span) {
return;
}
Expand Down
34 changes: 17 additions & 17 deletions clippy_lints/src/bit_mask.rs
Expand Up @@ -112,9 +112,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BitMask {
if let ExprBinary(ref cmp, ref left, ref right) = e.node {
if cmp.node.is_comparison() {
if let Some(cmp_opt) = fetch_int_literal(cx, right) {
check_compare(cx, left, cmp.node, cmp_opt, &e.span)
check_compare(cx, left, cmp.node, cmp_opt, e.span)
} else if let Some(cmp_val) = fetch_int_literal(cx, left) {
check_compare(cx, right, invert_cmp(cmp.node), cmp_val, &e.span)
check_compare(cx, right, invert_cmp(cmp.node), cmp_val, e.span)
}
}
}
Expand Down Expand Up @@ -156,7 +156,7 @@ fn invert_cmp(cmp: BinOp_) -> BinOp_ {
}


fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u128, span: &Span) {
fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u128, span: Span) {
if let ExprBinary(ref op, ref left, ref right) = bit_op.node {
if op.node != BiBitAnd && op.node != BiBitOr {
return;
Expand All @@ -167,15 +167,15 @@ fn check_compare(cx: &LateContext, bit_op: &Expr, cmp_op: BinOp_, cmp_value: u12
}
}

fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value: u128, cmp_value: u128, span: &Span) {
fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value: u128, cmp_value: u128, span: Span) {
match cmp_op {
BiEq | BiNe => match bit_op {
BiBitAnd => if mask_value & cmp_value != cmp_value {
if cmp_value != 0 {
span_lint(
cx,
BAD_BIT_MASK,
*span,
span,
&format!(
"incompatible bit mask: `_ & {}` can never be equal to `{}`",
mask_value,
Expand All @@ -184,13 +184,13 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
);
}
} else if mask_value == 0 {
span_lint(cx, BAD_BIT_MASK, *span, "&-masking with zero");
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
},
BiBitOr => if mask_value | cmp_value != cmp_value {
span_lint(
cx,
BAD_BIT_MASK,
*span,
span,
&format!(
"incompatible bit mask: `_ | {}` can never be equal to `{}`",
mask_value,
Expand All @@ -205,63 +205,63 @@ fn check_bit_mask(cx: &LateContext, bit_op: BinOp_, cmp_op: BinOp_, mask_value:
span_lint(
cx,
BAD_BIT_MASK,
*span,
span,
&format!(
"incompatible bit mask: `_ & {}` will always be lower than `{}`",
mask_value,
cmp_value
),
);
} else if mask_value == 0 {
span_lint(cx, BAD_BIT_MASK, *span, "&-masking with zero");
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
},
BiBitOr => if mask_value >= cmp_value {
span_lint(
cx,
BAD_BIT_MASK,
*span,
span,
&format!(
"incompatible bit mask: `_ | {}` will never be lower than `{}`",
mask_value,
cmp_value
),
);
} else {
check_ineffective_lt(cx, *span, mask_value, cmp_value, "|");
check_ineffective_lt(cx, span, mask_value, cmp_value, "|");
},
BiBitXor => check_ineffective_lt(cx, *span, mask_value, cmp_value, "^"),
BiBitXor => check_ineffective_lt(cx, span, mask_value, cmp_value, "^"),
_ => (),
},
BiLe | BiGt => match bit_op {
BiBitAnd => if mask_value <= cmp_value {
span_lint(
cx,
BAD_BIT_MASK,
*span,
span,
&format!(
"incompatible bit mask: `_ & {}` will never be higher than `{}`",
mask_value,
cmp_value
),
);
} else if mask_value == 0 {
span_lint(cx, BAD_BIT_MASK, *span, "&-masking with zero");
span_lint(cx, BAD_BIT_MASK, span, "&-masking with zero");
},
BiBitOr => if mask_value > cmp_value {
span_lint(
cx,
BAD_BIT_MASK,
*span,
span,
&format!(
"incompatible bit mask: `_ | {}` will always be higher than `{}`",
mask_value,
cmp_value
),
);
} else {
check_ineffective_gt(cx, *span, mask_value, cmp_value, "|");
check_ineffective_gt(cx, span, mask_value, cmp_value, "|");
},
BiBitXor => check_ineffective_gt(cx, *span, mask_value, cmp_value, "^"),
BiBitXor => check_ineffective_gt(cx, span, mask_value, cmp_value, "^"),
_ => (),
},
_ => (),
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/eq_op.rs
Expand Up @@ -52,7 +52,7 @@ impl LintPass for EqOp {

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) {
if let ExprBinary(ref op, ref left, ref right) = e.node {
if let ExprBinary(op, ref left, ref right) = e.node {
if in_macro(e.span) {
return;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EqOp {
}


fn is_valid_operator(op: &BinOp) -> bool {
fn is_valid_operator(op: BinOp) -> bool {
match op.node {
BiSub | BiDiv | BiEq | BiLt | BiLe | BiGt | BiGe | BiNe | BiAnd | BiOr | BiBitXor | BiBitAnd | BiBitOr => true,
_ => false,
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/excessive_precision.rs
Expand Up @@ -46,9 +46,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
if_chain! {
let ty = cx.tables.expr_ty(expr);
if let TypeVariants::TyFloat(ref fty) = ty.sty;
if let TypeVariants::TyFloat(fty) = ty.sty;
if let hir::ExprLit(ref lit) = expr.node;
if let LitKind::Float(ref sym, _) | LitKind::FloatUnsuffixed(ref sym) = lit.node;
if let LitKind::Float(sym, _) | LitKind::FloatUnsuffixed(sym) = lit.node;
if let Some(sugg) = self.check(sym, fty);
then {
span_lint_and_sugg(
Expand All @@ -66,7 +66,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExcessivePrecision {

impl ExcessivePrecision {
// None if nothing to lint, Some(suggestion) if lint neccessary
fn check(&self, sym: &Symbol, fty: &FloatTy) -> Option<String> {
fn check(&self, sym: Symbol, fty: FloatTy) -> Option<String> {
let max = max_digits(fty);
let sym_str = sym.as_str();
if dot_zero_exclusion(&sym_str) {
Expand All @@ -79,7 +79,7 @@ impl ExcessivePrecision {
let digits = count_digits(&sym_str);
if digits > max as usize {
let formatter = FloatFormat::new(&sym_str);
let sr = match *fty {
let sr = match fty {
FloatTy::F32 => sym_str.parse::<f32>().map(|f| formatter.format(f)),
FloatTy::F64 => sym_str.parse::<f64>().map(|f| formatter.format(f)),
};
Expand Down Expand Up @@ -115,7 +115,7 @@ fn dot_zero_exclusion(s: &str) -> bool {
}
}

fn max_digits(fty: &FloatTy) -> u32 {
fn max_digits(fty: FloatTy) -> u32 {
match fty {
FloatTy::F32 => f32::DIGITS,
FloatTy::F64 => f64::DIGITS,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/functions.rs
Expand Up @@ -126,7 +126,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
}

impl<'a, 'tcx> Functions {
fn check_arg_number(&self, cx: &LateContext, decl: &hir::FnDecl, span: Span) {
fn check_arg_number(self, cx: &LateContext, decl: &hir::FnDecl, span: Span) {
let args = decl.inputs.len() as u64;
if args > self.threshold {
span_lint(
Expand All @@ -139,7 +139,7 @@ impl<'a, 'tcx> Functions {
}

fn check_raw_ptr(
&self,
self,
cx: &LateContext<'a, 'tcx>,
unsafety: hir::Unsafety,
decl: &'tcx hir::FnDecl,
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/inline_fn_without_body.rs
Expand Up @@ -38,12 +38,12 @@ impl LintPass for Pass {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_trait_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx TraitItem) {
if let TraitItemKind::Method(_, TraitMethod::Required(_)) = item.node {
check_attrs(cx, &item.name, &item.attrs);
check_attrs(cx, item.name, &item.attrs);
}
}
}

fn check_attrs(cx: &LateContext, name: &Name, attrs: &[Attribute]) {
fn check_attrs(cx: &LateContext, name: Name, attrs: &[Attribute]) {
for attr in attrs {
if attr.name() != "inline" {
continue;
Expand Down
26 changes: 13 additions & 13 deletions clippy_lints/src/literal_representation.rs
Expand Up @@ -227,36 +227,36 @@ enum WarningType {
}

impl WarningType {
pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: &syntax_pos::Span) {
match *self {
pub fn display(&self, grouping_hint: &str, cx: &EarlyContext, span: syntax_pos::Span) {
match self {
WarningType::UnreadableLiteral => span_lint_and_sugg(
cx,
UNREADABLE_LITERAL,
*span,
span,
"long literal lacking separators",
"consider",
grouping_hint.to_owned(),
),
WarningType::LargeDigitGroups => span_lint_and_sugg(
cx,
LARGE_DIGIT_GROUPS,
*span,
span,
"digit groups should be smaller",
"consider",
grouping_hint.to_owned(),
),
WarningType::InconsistentDigitGrouping => span_lint_and_sugg(
cx,
INCONSISTENT_DIGIT_GROUPING,
*span,
span,
"digits grouped inconsistently by underscores",
"consider",
grouping_hint.to_owned(),
),
WarningType::DecimalRepresentation => span_lint_and_sugg(
cx,
DECIMAL_LITERAL_REPRESENTATION,
*span,
span,
"integer literal has a better hexadecimal representation",
"consider",
grouping_hint.to_owned(),
Expand Down Expand Up @@ -291,7 +291,7 @@ impl EarlyLintPass for LiteralDigitGrouping {
}

impl LiteralDigitGrouping {
fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
match lit.node {
LitKind::Int(..) => {
// Lint integral literals.
Expand All @@ -302,7 +302,7 @@ impl LiteralDigitGrouping {
then {
let digit_info = DigitInfo::new(&src, false);
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)
warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
});
}
}
Expand Down Expand Up @@ -337,15 +337,15 @@ impl LiteralDigitGrouping {
if !consistent {
WarningType::InconsistentDigitGrouping.display(&digit_info.grouping_hint(),
cx,
&lit.span);
lit.span);
}
})
.map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(),
cx,
&lit.span));
lit.span));
}
})
.map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, &lit.span));
.map_err(|warning_type| warning_type.display(&digit_info.grouping_hint(), cx, lit.span));
}
}
},
Expand Down Expand Up @@ -436,7 +436,7 @@ impl LiteralRepresentation {
threshold,
}
}
fn check_lit(&self, cx: &EarlyContext, lit: &Lit) {
fn check_lit(self, cx: &EarlyContext, lit: &Lit) {
// Lint integral literals.
if_chain! {
if let LitKind::Int(..) = lit.node;
Expand All @@ -457,7 +457,7 @@ impl LiteralRepresentation {
let hex = format!("{:#X}", val);
let digit_info = DigitInfo::new(&hex[..], false);
let _ = Self::do_lint(digit_info.digits).map_err(|warning_type| {
warning_type.display(&digit_info.grouping_hint(), cx, &lit.span)
warning_type.display(&digit_info.grouping_hint(), cx, lit.span)
});
}
}
Expand Down

0 comments on commit 621fdcc

Please sign in to comment.