Skip to content

Commit

Permalink
Move concat macro path into clippy_utils::paths
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 29, 2024
1 parent 2351a53 commit 8e6092c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clippy_lints/src/useless_concat.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::macros::macro_backtrace;
use clippy_utils::paths::CONCAT;
use clippy_utils::source::snippet_opt;
use clippy_utils::{match_def_path, tokenize_with_text};
use rustc_ast::LitKind;
Expand Down Expand Up @@ -42,7 +43,7 @@ impl LateLintPass<'_> for UselessConcat {
// Get the direct parent of the expression.
&& let Some(macro_call) = macro_backtrace(expr.span).next()
// Check if the `concat` macro from the `core` library.
&& match_def_path(cx, macro_call.def_id, &["core", "macros", "builtin", "concat"])
&& match_def_path(cx, macro_call.def_id, &CONCAT)
// We get the original code to parse it.
&& let Some(original_code) = snippet_opt(cx, macro_call.span)
// This check allows us to ensure that the code snippet:
Expand Down
5 changes: 5 additions & 0 deletions clippy_lints/src/utils/internal_lints/invalid_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
if !def_path_res(cx.tcx, path).is_empty() {
return true;
}
// `builtin` macros don't seem to be found in `def_path_res`...
if path == ["core", "macros", "builtin", "concat"] {
return true;
}

// Some implementations can't be found by `path_to_res`, particularly inherent
// implementations of native types. Check lang items.
Expand All @@ -77,6 +81,7 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
.iter()
.flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter())
.copied();

for item_def_id in lang_items.iter().map(|(_, def_id)| def_id).chain(incoherent_impls) {
let lang_item_path = cx.get_def_path(item_def_id);
if path_syms.starts_with(&lang_item_path) {
Expand Down
1 change: 1 addition & 0 deletions clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub const CHILD: [&str; 3] = ["std", "process", "Child"];
pub const CHILD_ID: [&str; 4] = ["std", "process", "Child", "id"];
pub const CHILD_KILL: [&str; 4] = ["std", "process", "Child", "kill"];
pub const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"];
pub const CONCAT: [&str; 4] = ["core", "macros", "builtin", "concat"];

// Paths in clippy itself
pub const MSRV: [&str; 3] = ["clippy_utils", "msrvs", "Msrv"];
Expand Down

0 comments on commit 8e6092c

Please sign in to comment.