[Clippy] Swap manual_strip
to use diagnostic items instead of paths
This commit is contained in:
parent
89532c0f30
commit
5f42ae13c1
@ -1876,11 +1876,14 @@
|
|||||||
store,
|
store,
|
||||||
str,
|
str,
|
||||||
str_chars,
|
str_chars,
|
||||||
|
str_ends_with,
|
||||||
str_from_utf8,
|
str_from_utf8,
|
||||||
str_from_utf8_mut,
|
str_from_utf8_mut,
|
||||||
str_from_utf8_unchecked,
|
str_from_utf8_unchecked,
|
||||||
str_from_utf8_unchecked_mut,
|
str_from_utf8_unchecked_mut,
|
||||||
|
str_len,
|
||||||
str_split_whitespace,
|
str_split_whitespace,
|
||||||
|
str_starts_with,
|
||||||
str_trim,
|
str_trim,
|
||||||
str_trim_end,
|
str_trim_end,
|
||||||
str_trim_start,
|
str_trim_start,
|
||||||
|
@ -134,6 +134,7 @@ impl str {
|
|||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
|
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "str_len")]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub const fn len(&self) -> usize {
|
pub const fn len(&self) -> usize {
|
||||||
@ -1157,6 +1158,7 @@ pub fn contains<P: Pattern>(&self, pat: P) -> bool {
|
|||||||
/// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
|
/// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "str_starts_with")]
|
||||||
pub fn starts_with<P: Pattern>(&self, pat: P) -> bool {
|
pub fn starts_with<P: Pattern>(&self, pat: P) -> bool {
|
||||||
pat.is_prefix_of(self)
|
pat.is_prefix_of(self)
|
||||||
}
|
}
|
||||||
@ -1181,6 +1183,7 @@ pub fn starts_with<P: Pattern>(&self, pat: P) -> bool {
|
|||||||
/// assert!(!bananas.ends_with("nana"));
|
/// assert!(!bananas.ends_with("nana"));
|
||||||
/// ```
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "str_ends_with")]
|
||||||
pub fn ends_with<P: Pattern>(&self, pat: P) -> bool
|
pub fn ends_with<P: Pattern>(&self, pat: P) -> bool
|
||||||
where
|
where
|
||||||
for<'a> P::Searcher<'a>: ReverseSearcher<'a>,
|
for<'a> P::Searcher<'a>: ReverseSearcher<'a>,
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
use clippy_utils::diagnostics::span_lint_and_then;
|
use clippy_utils::diagnostics::span_lint_and_then;
|
||||||
use clippy_utils::source::snippet;
|
use clippy_utils::source::snippet;
|
||||||
use clippy_utils::usage::mutated_variables;
|
use clippy_utils::usage::mutated_variables;
|
||||||
use clippy_utils::{eq_expr_value, higher, match_def_path, paths};
|
use clippy_utils::{eq_expr_value, higher};
|
||||||
use rustc_ast::ast::LitKind;
|
use rustc_ast::ast::LitKind;
|
||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir::def::Res;
|
use rustc_hir::def::Res;
|
||||||
@ -14,7 +14,7 @@
|
|||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::impl_lint_pass;
|
use rustc_session::impl_lint_pass;
|
||||||
use rustc_span::source_map::Spanned;
|
use rustc_span::source_map::Spanned;
|
||||||
use rustc_span::Span;
|
use rustc_span::{sym, Span};
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
@ -76,9 +76,9 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
|||||||
&& self.msrv.meets(msrvs::STR_STRIP_PREFIX)
|
&& self.msrv.meets(msrvs::STR_STRIP_PREFIX)
|
||||||
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id)
|
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(cond.hir_id)
|
||||||
{
|
{
|
||||||
let strip_kind = if match_def_path(cx, method_def_id, &paths::STR_STARTS_WITH) {
|
let strip_kind = if cx.tcx.is_diagnostic_item(sym::str_starts_with, method_def_id) {
|
||||||
StripKind::Prefix
|
StripKind::Prefix
|
||||||
} else if match_def_path(cx, method_def_id, &paths::STR_ENDS_WITH) {
|
} else if cx.tcx.is_diagnostic_item(sym::str_ends_with, method_def_id) {
|
||||||
StripKind::Suffix
|
StripKind::Suffix
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
@ -137,7 +137,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
|
|||||||
fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
|
fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
|
||||||
if let ExprKind::MethodCall(_, arg, [], _) = expr.kind
|
if let ExprKind::MethodCall(_, arg, [], _) = expr.kind
|
||||||
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||||
&& match_def_path(cx, method_def_id, &paths::STR_LEN)
|
&& cx.tcx.is_diagnostic_item(sym::str_len, method_def_id)
|
||||||
{
|
{
|
||||||
Some(arg)
|
Some(arg)
|
||||||
} else {
|
} else {
|
||||||
|
@ -52,9 +52,6 @@
|
|||||||
pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"];
|
pub const STD_IO_SEEK_FROM_CURRENT: [&str; 4] = ["std", "io", "SeekFrom", "Current"];
|
||||||
pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"];
|
pub const STD_IO_SEEKFROM_START: [&str; 4] = ["std", "io", "SeekFrom", "Start"];
|
||||||
pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"];
|
pub const STRING_NEW: [&str; 4] = ["alloc", "string", "String", "new"];
|
||||||
pub const STR_ENDS_WITH: [&str; 4] = ["core", "str", "<impl str>", "ends_with"];
|
|
||||||
pub const STR_LEN: [&str; 4] = ["core", "str", "<impl str>", "len"];
|
|
||||||
pub const STR_STARTS_WITH: [&str; 4] = ["core", "str", "<impl str>", "starts_with"];
|
|
||||||
pub const SYMBOL: [&str; 3] = ["rustc_span", "symbol", "Symbol"];
|
pub const SYMBOL: [&str; 3] = ["rustc_span", "symbol", "Symbol"];
|
||||||
pub const SYMBOL_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Symbol", "as_str"];
|
pub const SYMBOL_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Symbol", "as_str"];
|
||||||
pub const SYMBOL_INTERN: [&str; 4] = ["rustc_span", "symbol", "Symbol", "intern"];
|
pub const SYMBOL_INTERN: [&str; 4] = ["rustc_span", "symbol", "Symbol", "intern"];
|
||||||
|
Loading…
Reference in New Issue
Block a user