s/cx.span_lint/span_lint(cx, /

This commit is contained in:
mcarton 2016-03-26 01:49:45 +01:00
parent 2d5e3f3118
commit e7158dc8f1
2 changed files with 23 additions and 18 deletions

View file

@ -312,7 +312,7 @@ impl LateLintPass for ModuloOne {
if let ExprBinary(ref cmp, _, ref right) = expr.node { if let ExprBinary(ref cmp, _, ref right) = expr.node {
if let Spanned {node: BinOp_::BiRem, ..} = *cmp { if let Spanned {node: BinOp_::BiRem, ..} = *cmp {
if is_integer_literal(right, 1) { if is_integer_literal(right, 1) {
cx.span_lint(MODULO_ONE, expr.span, "any number modulo 1 will be 0"); span_lint(cx, MODULO_ONE, expr.span, "any number modulo 1 will be 0");
} }
} }
} }
@ -347,11 +347,12 @@ impl LateLintPass for PatternPass {
fn check_pat(&mut self, cx: &LateContext, pat: &Pat) { fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
if let PatKind::Ident(_, ref ident, Some(ref right)) = pat.node { if let PatKind::Ident(_, ref ident, Some(ref right)) = pat.node {
if right.node == PatKind::Wild { if right.node == PatKind::Wild {
cx.span_lint(REDUNDANT_PATTERN, span_lint(cx,
pat.span, REDUNDANT_PATTERN,
&format!("the `{} @ _` pattern can be written as just `{}`", pat.span,
ident.node.name, &format!("the `{} @ _` pattern can be written as just `{}`",
ident.node.name)); ident.node.name,
ident.node.name));
} }
} }
} }
@ -408,10 +409,11 @@ impl LateLintPass for UsedUnderscoreBinding {
_ => false, _ => false,
}; };
if needs_lint { if needs_lint {
cx.span_lint(USED_UNDERSCORE_BINDING, span_lint(cx,
expr.span, USED_UNDERSCORE_BINDING,
"used binding which is prefixed with an underscore. A leading underscore signals that a \ expr.span,
binding will not be used."); "used binding which is prefixed with an underscore. A leading underscore signals that a \
binding will not be used.");
} }
} }
} }

View file

@ -1,7 +1,7 @@
use rustc::lint::*; use rustc::lint::*;
use rustc_front::hir::*; use rustc_front::hir::*;
use syntax::codemap::Spanned; use syntax::codemap::Spanned;
use utils::{is_integer_literal, match_type, snippet, unsugar_range, UnsugaredRange}; use utils::{is_integer_literal, match_type, snippet, span_lint, unsugar_range, UnsugaredRange};
/// **What it does:** This lint checks for iterating over ranges with a `.step_by(0)`, which never terminates. /// **What it does:** This lint checks for iterating over ranges with a `.step_by(0)`, which never terminates.
/// ///
@ -41,10 +41,11 @@ impl LateLintPass for StepByZero {
// Range with step_by(0). // Range with step_by(0).
if name.as_str() == "step_by" && args.len() == 2 && is_range(cx, &args[0]) && if name.as_str() == "step_by" && args.len() == 2 && is_range(cx, &args[0]) &&
is_integer_literal(&args[1], 0) { is_integer_literal(&args[1], 0) {
cx.span_lint(RANGE_STEP_BY_ZERO, span_lint(cx,
expr.span, RANGE_STEP_BY_ZERO,
"Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` \ expr.span,
instead") "Range::step_by(0) produces an infinite iterator. Consider using `std::iter::repeat()` \
instead");
} else if name.as_str() == "zip" && args.len() == 2 { } else if name.as_str() == "zip" && args.len() == 2 {
let iter = &args[0].node; let iter = &args[0].node;
let zip_arg = &args[1]; let zip_arg = &args[1];
@ -64,9 +65,11 @@ impl LateLintPass for StepByZero {
let ExprPath(_, Path { segments: ref len_path, .. }) = len_args[0].node, let ExprPath(_, Path { segments: ref len_path, .. }) = len_args[0].node,
iter_path == len_path iter_path == len_path
], { ], {
cx.span_lint(RANGE_ZIP_WITH_LEN, expr.span, span_lint(cx,
&format!("It is more idiomatic to use {}.iter().enumerate()", RANGE_ZIP_WITH_LEN,
snippet(cx, iter_args[0].span, "_"))); expr.span,
&format!("It is more idiomatic to use {}.iter().enumerate()",
snippet(cx, iter_args[0].span, "_")));
} }
} }
} }