2021-03-06 02:28:14 -06:00
|
|
|
use crate::methods::get_hint_if_single_char_arg;
|
2021-03-15 19:55:45 -05:00
|
|
|
use clippy_utils::diagnostics::span_lint_and_sugg;
|
2021-03-06 02:28:14 -06:00
|
|
|
use rustc_errors::Applicability;
|
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_lint::LateContext;
|
|
|
|
|
|
|
|
use super::SINGLE_CHAR_PATTERN;
|
|
|
|
|
|
|
|
/// lint for length-1 `str`s for methods in `PATTERN_METHODS`
|
|
|
|
pub(super) fn check(cx: &LateContext<'_>, _expr: &hir::Expr<'_>, arg: &hir::Expr<'_>) {
|
|
|
|
let mut applicability = Applicability::MachineApplicable;
|
|
|
|
if let Some(hint) = get_hint_if_single_char_arg(cx, arg, &mut applicability) {
|
|
|
|
span_lint_and_sugg(
|
|
|
|
cx,
|
|
|
|
SINGLE_CHAR_PATTERN,
|
|
|
|
arg.span,
|
|
|
|
"single-character string constant used as pattern",
|
|
|
|
"try using a `char` instead",
|
|
|
|
hint,
|
|
|
|
applicability,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|