Skip to content

Commit 6e39181

Browse files
Move concat macro path into clippy_utils::paths
1 parent 85f69c6 commit 6e39181

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

clippy_lints/src/useless_concat.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::macros::macro_backtrace;
3+
use clippy_utils::paths::CONCAT;
34
use clippy_utils::source::snippet_opt;
45
use clippy_utils::{match_def_path, tokenize_with_text};
56
use rustc_ast::LitKind;
@@ -42,7 +43,7 @@ impl LateLintPass<'_> for UselessConcat {
4243
// Get the direct parent of the expression.
4344
&& let Some(macro_call) = macro_backtrace(expr.span).next()
4445
// Check if the `concat` macro from the `core` library.
45-
&& match_def_path(cx, macro_call.def_id, &["core", "macros", "builtin", "concat"])
46+
&& match_def_path(cx, macro_call.def_id, &CONCAT)
4647
// We get the original code to parse it.
4748
&& let Some(original_code) = snippet_opt(cx, macro_call.span)
4849
// This check allows us to ensure that the code snippet:

clippy_lints/src/utils/internal_lints/invalid_paths.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
6161
if !def_path_res(cx.tcx, path).is_empty() {
6262
return true;
6363
}
64+
// `builtin` macros don't seem to be found in `def_path_res`...
65+
if path == ["core", "macros", "builtin", "concat"] {
66+
return true;
67+
}
6468

6569
// Some implementations can't be found by `path_to_res`, particularly inherent
6670
// implementations of native types. Check lang items.
@@ -78,6 +82,7 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
7882
.iter()
7983
.flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter())
8084
.copied();
85+
8186
for item_def_id in lang_items.iter().map(|(_, def_id)| def_id).chain(incoherent_impls) {
8287
let lang_item_path = cx.get_def_path(item_def_id);
8388
if path_syms.starts_with(&lang_item_path) {

clippy_utils/src/paths.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub const CHILD: [&str; 3] = ["std", "process", "Child"];
3333
pub const CHILD_ID: [&str; 4] = ["std", "process", "Child", "id"];
3434
pub const CHILD_KILL: [&str; 4] = ["std", "process", "Child", "kill"];
3535
pub const PANIC_ANY: [&str; 3] = ["std", "panic", "panic_any"];
36+
pub const CONCAT: [&str; 4] = ["core", "macros", "builtin", "concat"];
3637
pub const CHAR_IS_ASCII: [&str; 5] = ["core", "char", "methods", "<impl char>", "is_ascii"];
3738
pub const STDIN: [&str; 4] = ["std", "io", "stdio", "Stdin"];
3839

0 commit comments

Comments
 (0)