Use symbols instead of &str when possible
This commit is contained in:
parent
82bf659dc8
commit
e16801e68c
86 changed files with 857 additions and 653 deletions
|
|
@ -5,9 +5,9 @@ use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_and_then};
|
|||
use clippy_utils::eager_or_lazy::switch_to_eager_eval;
|
||||
use clippy_utils::macros::matching_root_macro_call;
|
||||
use clippy_utils::msrvs::{self, Msrv};
|
||||
use clippy_utils::path_to_local_id;
|
||||
use clippy_utils::source::{snippet, str_literal_to_char_literal};
|
||||
use clippy_utils::visitors::{Descend, for_each_expr};
|
||||
use clippy_utils::{path_to_local_id, sym};
|
||||
use itertools::Itertools;
|
||||
use rustc_ast::{BinOpKind, LitKind};
|
||||
use rustc_errors::Applicability;
|
||||
|
|
@ -15,7 +15,7 @@ use rustc_hir::{Expr, ExprKind, PatExprKind, PatKind};
|
|||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::impl_lint_pass;
|
||||
use rustc_span::{Span, sym};
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
declare_clippy_lint! {
|
||||
/// ### What it does
|
||||
|
|
@ -83,29 +83,29 @@ impl StringPatterns {
|
|||
|
||||
impl_lint_pass!(StringPatterns => [MANUAL_PATTERN_CHAR_COMPARISON, SINGLE_CHAR_PATTERN]);
|
||||
|
||||
const PATTERN_METHODS: [(&str, usize); 22] = [
|
||||
("contains", 0),
|
||||
("starts_with", 0),
|
||||
("ends_with", 0),
|
||||
("find", 0),
|
||||
("rfind", 0),
|
||||
("split", 0),
|
||||
("split_inclusive", 0),
|
||||
("rsplit", 0),
|
||||
("split_terminator", 0),
|
||||
("rsplit_terminator", 0),
|
||||
("splitn", 1),
|
||||
("rsplitn", 1),
|
||||
("split_once", 0),
|
||||
("rsplit_once", 0),
|
||||
("matches", 0),
|
||||
("rmatches", 0),
|
||||
("match_indices", 0),
|
||||
("rmatch_indices", 0),
|
||||
("trim_start_matches", 0),
|
||||
("trim_end_matches", 0),
|
||||
("replace", 0),
|
||||
("replacen", 0),
|
||||
const PATTERN_METHODS: [(Symbol, usize); 22] = [
|
||||
(sym::contains, 0),
|
||||
(sym::starts_with, 0),
|
||||
(sym::ends_with, 0),
|
||||
(sym::find, 0),
|
||||
(sym::rfind, 0),
|
||||
(sym::split, 0),
|
||||
(sym::split_inclusive, 0),
|
||||
(sym::rsplit, 0),
|
||||
(sym::split_terminator, 0),
|
||||
(sym::rsplit_terminator, 0),
|
||||
(sym::splitn, 1),
|
||||
(sym::rsplitn, 1),
|
||||
(sym::split_once, 0),
|
||||
(sym::rsplit_once, 0),
|
||||
(sym::matches, 0),
|
||||
(sym::rmatches, 0),
|
||||
(sym::match_indices, 0),
|
||||
(sym::rmatch_indices, 0),
|
||||
(sym::trim_start_matches, 0),
|
||||
(sym::trim_end_matches, 0),
|
||||
(sym::replace, 0),
|
||||
(sym::replacen, 0),
|
||||
];
|
||||
|
||||
fn check_single_char_pattern_lint(cx: &LateContext<'_>, arg: &Expr<'_>) {
|
||||
|
|
@ -228,7 +228,7 @@ impl<'tcx> LateLintPass<'tcx> for StringPatterns {
|
|||
&& let ExprKind::MethodCall(method, receiver, args, _) = expr.kind
|
||||
&& let ty::Ref(_, ty, _) = cx.typeck_results().expr_ty_adjusted(receiver).kind()
|
||||
&& ty.is_str()
|
||||
&& let method_name = method.ident.name.as_str()
|
||||
&& let method_name = method.ident.name
|
||||
&& let Some(&(_, pos)) = PATTERN_METHODS
|
||||
.iter()
|
||||
.find(|(array_method_name, _)| *array_method_name == method_name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue