replace lints and lint with check

This commit is contained in:
Takayuki Maeda 2021-03-03 01:16:16 +09:00
parent 45ee914df0
commit 6376da70be
8 changed files with 18 additions and 18 deletions

View file

@ -158,7 +158,7 @@ pub(crate) trait BindInsteadOfMap {
}
/// Lint use of `_.and_then(|x| Some(y))` for `Option`s
fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) -> bool {
fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) -> bool {
if !match_type(cx, cx.typeck_results().expr_ty(&args[0]), Self::TYPE_QPATH) {
return false;
}

View file

@ -7,7 +7,7 @@ use rustc_span::sym;
use super::BYTES_NTH;
pub(super) fn lints<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, iter_args: &'tcx [Expr<'tcx>]) {
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, iter_args: &'tcx [Expr<'tcx>]) {
if_chain! {
if let ExprKind::MethodCall(_, _, ref args, _) = expr.kind;
let ty = cx.typeck_results().expr_ty(&iter_args[0]).peel_refs();

View file

@ -10,7 +10,7 @@ use rustc_middle::ty::{self, Ty};
use rustc_span::sym;
/// Checks for the `INEFFICIENT_TO_STRING` lint
pub fn lint<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) {
pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, arg: &hir::Expr<'_>, arg_ty: Ty<'tcx>) {
if_chain! {
if let Some(to_string_meth_did) = cx.typeck_results().type_dependent_def_id(expr.hir_id);
if match_def_path(cx, to_string_meth_did, &paths::TO_STRING_METHOD);

View file

@ -7,7 +7,7 @@ use crate::utils::{match_trait_method, paths, span_lint_and_help};
use super::INSPECT_FOR_EACH;
/// lint use of `inspect().for_each()` for `Iterators`
pub(super) fn lint<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, inspect_span: Span) {
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>, inspect_span: Span) {
if match_trait_method(cx, expr, &paths::ITERATOR) {
let msg = "called `inspect(..).for_each(..)` on an `Iterator`";
let hint = "move the code from `inspect(..)` to `for_each(..)` and remove the `inspect(..)`";

View file

@ -8,7 +8,7 @@ use rustc_span::sym;
use super::ITER_COUNT;
pub(crate) fn lints<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, iter_args: &'tcx [Expr<'tcx>], iter_method: &str) {
pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, iter_args: &'tcx [Expr<'tcx>], iter_method: &str) {
let ty = cx.typeck_results().expr_ty(&iter_args[0]);
let caller_type = if derefs_to_slice(cx, &iter_args[0], ty).is_some() {
"slice"

View file

@ -6,7 +6,7 @@ use rustc_hir as hir;
use rustc_lint::LateContext;
use rustc_target::abi::LayoutOf;
pub fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]], arith: &str) {
pub fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[&[hir::Expr<'_>]], arith: &str) {
let unwrap_arg = &args[0][1];
let arith_lhs = &args[1][0];
let arith_rhs = &args[1][1];

View file

@ -1673,14 +1673,14 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
},
["map_or", ..] => lint_map_or_none(cx, expr, arg_lists[0]),
["and_then", ..] => {
let biom_option_linted = bind_instead_of_map::OptionAndThenSome::lint(cx, expr, arg_lists[0]);
let biom_result_linted = bind_instead_of_map::ResultAndThenOk::lint(cx, expr, arg_lists[0]);
let biom_option_linted = bind_instead_of_map::OptionAndThenSome::check(cx, expr, arg_lists[0]);
let biom_result_linted = bind_instead_of_map::ResultAndThenOk::check(cx, expr, arg_lists[0]);
if !biom_option_linted && !biom_result_linted {
unnecessary_lazy_eval::check(cx, expr, arg_lists[0], "and");
}
},
["or_else", ..] => {
if !bind_instead_of_map::ResultOrElseErrInfo::lint(cx, expr, arg_lists[0]) {
if !bind_instead_of_map::ResultOrElseErrInfo::check(cx, expr, arg_lists[0]) {
unnecessary_lazy_eval::check(cx, expr, arg_lists[0], "or");
}
},
@ -1703,12 +1703,12 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
lint_search_is_some(cx, expr, "rposition", arg_lists[1], arg_lists[0], method_spans[1])
},
["extend", ..] => lint_extend(cx, expr, arg_lists[0]),
["count", "into_iter"] => iter_count::lints(cx, expr, &arg_lists[1], "into_iter"),
["count", "iter"] => iter_count::lints(cx, expr, &arg_lists[1], "iter"),
["count", "iter_mut"] => iter_count::lints(cx, expr, &arg_lists[1], "iter_mut"),
["count", "into_iter"] => iter_count::check(cx, expr, &arg_lists[1], "into_iter"),
["count", "iter"] => iter_count::check(cx, expr, &arg_lists[1], "iter"),
["count", "iter_mut"] => iter_count::check(cx, expr, &arg_lists[1], "iter_mut"),
["nth", "iter"] => lint_iter_nth(cx, expr, &arg_lists, false),
["nth", "iter_mut"] => lint_iter_nth(cx, expr, &arg_lists, true),
["nth", "bytes"] => bytes_nth::lints(cx, expr, &arg_lists[1]),
["nth", "bytes"] => bytes_nth::check(cx, expr, &arg_lists[1]),
["nth", ..] => lint_iter_nth_zero(cx, expr, arg_lists[0]),
["step_by", ..] => lint_step_by(cx, expr, arg_lists[0]),
["next", "skip"] => lint_iter_skip_next(cx, expr, arg_lists[1]),
@ -1717,13 +1717,13 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
["as_mut"] => lint_asref(cx, expr, "as_mut", arg_lists[0]),
["fold", ..] => lint_unnecessary_fold(cx, expr, arg_lists[0], method_spans[0]),
["filter_map", ..] => {
unnecessary_filter_map::lint(cx, expr, arg_lists[0]);
unnecessary_filter_map::check(cx, expr, arg_lists[0]);
filter_map_identity::check(cx, expr, arg_lists[0], method_spans[0]);
},
["count", "map"] => suspicious_map::check(cx, expr),
["assume_init"] => uninit_assumed_init::check(cx, &arg_lists[0][0], expr),
["unwrap_or", arith @ ("checked_add" | "checked_sub" | "checked_mul")] => {
manual_saturating_arithmetic::lint(cx, expr, &arg_lists, &arith["checked_".len()..])
manual_saturating_arithmetic::check(cx, expr, &arg_lists, &arith["checked_".len()..])
},
["add" | "offset" | "sub" | "wrapping_offset" | "wrapping_add" | "wrapping_sub"] => {
check_pointer_offset(cx, expr, arg_lists[0])
@ -1739,7 +1739,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
["get_or_insert_with", ..] => unnecessary_lazy_eval::check(cx, expr, arg_lists[0], "get_or_insert"),
["ok_or_else", ..] => unnecessary_lazy_eval::check(cx, expr, arg_lists[0], "ok_or"),
["collect", "map"] => lint_map_collect(cx, expr, arg_lists[1], arg_lists[0]),
["for_each", "inspect"] => inspect_for_each::lint(cx, expr, method_spans[1]),
["for_each", "inspect"] => inspect_for_each::check(cx, expr, method_spans[1]),
["to_owned", ..] => implicit_clone::check(cx, expr, sym::ToOwned),
["to_os_string", ..] => implicit_clone::check(cx, expr, sym::OsStr),
["to_path_buf", ..] => implicit_clone::check(cx, expr, sym::Path),
@ -1765,7 +1765,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
lint_clone_on_ref_ptr(cx, expr, &args[0]);
}
if args.len() == 1 && method_call.ident.name == sym!(to_string) {
inefficient_to_string::lint(cx, expr, &args[0], self_ty);
inefficient_to_string::check(cx, expr, &args[0], self_ty);
}
if let Some(fn_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) {

View file

@ -9,7 +9,7 @@ use if_chain::if_chain;
use super::UNNECESSARY_FILTER_MAP;
pub(super) fn lint(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, args: &[hir::Expr<'_>]) {
if !match_trait_method(cx, expr, &paths::ITERATOR) {
return;
}