Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit be49f86

Browse files
authored
Move more def paths into clippy_utils::paths (rust-lang#13903)
I discovered that there were paths declared in `clippy_utils::paths` in rust-lang/rust-clippy#13829 so moving a few remaining hardcoded ones in one place. changelog: Move more def paths into `clippy_utils::paths` r? @y21
2 parents b57d98b + b515064 commit be49f86

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

clippy_lints/src/methods/needless_character_iteration.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_span::Span;
77
use super::NEEDLESS_CHARACTER_ITERATION;
88
use super::utils::get_last_chain_binding_hir_id;
99
use clippy_utils::diagnostics::span_lint_and_sugg;
10+
use clippy_utils::paths::CHAR_IS_ASCII;
1011
use clippy_utils::source::SpanRangeExt;
1112
use clippy_utils::{match_def_path, path_to_local_id, peel_blocks};
1213

@@ -77,7 +78,7 @@ fn handle_expr(
7778
if revert != is_all
7879
&& let ExprKind::Path(path) = fn_path.kind
7980
&& let Some(fn_def_id) = cx.qpath_res(&path, fn_path.hir_id).opt_def_id()
80-
&& match_def_path(cx, fn_def_id, &["core", "char", "methods", "<impl char>", "is_ascii"])
81+
&& match_def_path(cx, fn_def_id, &CHAR_IS_ASCII)
8182
&& path_to_local_id(peels_expr_ref(arg), first_param)
8283
&& let Some(snippet) = before_chars.get_source_text(cx)
8384
{

clippy_lints/src/methods/read_line_without_trim.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::ops::ControlFlow;
22

33
use clippy_utils::diagnostics::span_lint_and_then;
4+
use clippy_utils::paths::STDIN;
45
use clippy_utils::source::snippet;
56
use clippy_utils::ty::is_type_diagnostic_item;
67
use clippy_utils::visitors::for_each_local_use_after_expr;
@@ -33,7 +34,7 @@ fn parse_fails_on_trailing_newline(ty: Ty<'_>) -> bool {
3334

3435
pub fn check(cx: &LateContext<'_>, call: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) {
3536
if let Some(recv_adt) = cx.typeck_results().expr_ty(recv).ty_adt_def()
36-
&& match_def_path(cx, recv_adt.did(), &["std", "io", "stdio", "Stdin"])
37+
&& match_def_path(cx, recv_adt.did(), &STDIN)
3738
&& let ExprKind::Path(QPath::Resolved(_, path)) = arg.peel_borrows().kind
3839
&& let Res::Local(local_id) = path.res
3940
{

clippy_lints/src/utils/internal_lints/invalid_paths.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
7373
SimplifiedType::Slice,
7474
SimplifiedType::Str,
7575
SimplifiedType::Bool,
76+
SimplifiedType::Char,
7677
]
7778
.iter()
7879
.flat_map(|&ty| cx.tcx.incoherent_impls(ty).iter())

clippy_utils/src/paths.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ 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 CHAR_IS_ASCII: [&str; 5] = ["core", "char", "methods", "<impl char>", "is_ascii"];
37+
pub const STDIN: [&str; 4] = ["std", "io", "stdio", "Stdin"];
3638

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

0 commit comments

Comments
 (0)