rust/clippy_lints/src/methods/single_char_pattern.rs
2021-03-15 20:06:01 -05:00

24 lines
782 B
Rust

use crate::methods::get_hint_if_single_char_arg;
use clippy_utils::diagnostics::span_lint_and_sugg;
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,
);
}
}