Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Clippy] Get rid of most std match_def_path usage, swap to diagnostic items. #130553

Merged
merged 20 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a786be5
[Clippy] Swap `map_entry` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
3ebff28
[Clippy] Swap `lines_filter_map_ok` to use a diagnostic item instead …
GnomedDev Sep 18, 2024
5e47168
[Clippy] Swap `option_as_ref_deref` to use diagnostic items instead o…
GnomedDev Sep 18, 2024
c891082
[Clippy] Swap `float_equality_without_abs` to use diagnostic items in…
GnomedDev Sep 18, 2024
afe7907
[Clippy] Swap `redundant_clone` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
037b978
[Clippy] Swap `manual_main_separator_str` to use diagnostic item inst…
GnomedDev Sep 18, 2024
28f4c82
[Clippy] Swap `single_char_add_str`/`format_push_string` to use diagn…
GnomedDev Sep 18, 2024
846ae57
[Clippy] Swap `VecArgs::hir` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
15240a9
[Clippy] Swap `repeat_vec_with_capacity` to use diagnostic item inste…
GnomedDev Sep 18, 2024
25da0e2
[Clippy] Swap `manual_while_let_some` to use diagnostic items instead…
GnomedDev Sep 18, 2024
5b55270
[Clippy] Swap `filter_map_bool_then` to use diagnostic item instead o…
GnomedDev Sep 18, 2024
372f68b
[Clippy] Swap `waker_clone_wake` to use diagnostic item instead of path
GnomedDev Sep 18, 2024
1890620
[Clippy] Swap `instant_subtraction` to use diagnostic item instead of…
GnomedDev Sep 18, 2024
89532c0
[Clippy] Swap `unnecessary_to_owned` to use diagnostic item instead o…
GnomedDev Sep 18, 2024
5f42ae1
[Clippy] Swap `manual_strip` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
5f85f73
[Clippy] Swap `unnecessary_owned_empty_strings` to use diagnostic ite…
GnomedDev Sep 18, 2024
43b8e04
[Clippy] Swap `non_octal_unix_permissions` to use diagnostic item ins…
GnomedDev Sep 18, 2024
364e552
[Clippy] Swap `iter_over_hash_type` to use diagnostic items instead o…
GnomedDev Sep 18, 2024
b2eebee
[Clippy] Swap `open_options` to use diagnostic items instead of paths
GnomedDev Sep 19, 2024
13d5732
Categorise paths in `clippy_utils::paths`
GnomedDev Sep 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Clippy] Swap manual_strip to use diagnostic items instead of paths
  • Loading branch information
GnomedDev committed Sep 19, 2024
commit 5f42ae13c1f5b99cb35aadb4c20376ba64e69ffb
3 changes: 3 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1876,11 +1876,14 @@ symbols! {
store,
str,
str_chars,
str_ends_with,
str_from_utf8,
str_from_utf8_mut,
str_from_utf8_unchecked,
str_from_utf8_unchecked_mut,
str_len,
str_split_whitespace,
str_starts_with,
str_trim,
str_trim_end,
str_trim_start,
Expand Down
3 changes: 3 additions & 0 deletions library/core/src/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl str {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_stable(feature = "const_str_len", since = "1.39.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "str_len")]
#[must_use]
#[inline]
pub const fn len(&self) -> usize {
Expand Down Expand Up @@ -1157,6 +1158,7 @@ impl str {
/// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
/// ```
#[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 {
pat.is_prefix_of(self)
}
Expand All @@ -1181,6 +1183,7 @@ impl str {
/// assert!(!bananas.ends_with("nana"));
/// ```
#[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
where
for<'a> P::Searcher<'a>: ReverseSearcher<'a>,
Expand Down
10 changes: 5 additions & 5 deletions src/tools/clippy/clippy_lints/src/manual_strip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clippy_utils::consts::{ConstEvalCtxt, Constant};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::snippet;
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_errors::Applicability;
use rustc_hir::def::Res;
Expand All @@ -14,7 +14,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::impl_lint_pass;
use rustc_span::source_map::Spanned;
use rustc_span::Span;
use rustc_span::{sym, Span};
use std::iter;

declare_clippy_lint! {
Expand Down Expand Up @@ -76,9 +76,9 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
&& self.msrv.meets(msrvs::STR_STRIP_PREFIX)
&& 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
} 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
} else {
return;
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualStrip {
fn len_arg<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
if let ExprKind::MethodCall(_, arg, [], _) = expr.kind
&& 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)
} else {
Expand Down
3 changes: 0 additions & 3 deletions src/tools/clippy/clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
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 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_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Symbol", "as_str"];
pub const SYMBOL_INTERN: [&str; 4] = ["rustc_span", "symbol", "Symbol", "intern"];
Expand Down