Skip to content

Commit f79c4af

Browse files
author
Michael Wright
committed
Fix invalid paths
1 parent 66d56fe commit f79c4af

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

clippy_lints/src/derive.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::utils::paths;
22
use crate::utils::{
3-
get_trait_def_id, is_allowed, is_automatically_derived, is_copy, match_path, span_lint_and_help,
3+
get_trait_def_id, is_allowed, is_automatically_derived, is_copy, match_def_path, match_path, span_lint_and_help,
44
span_lint_and_note, span_lint_and_then,
55
};
66
use if_chain::if_chain;
@@ -193,10 +193,9 @@ fn check_hash_peq<'tcx>(
193193
hash_is_automatically_derived: bool,
194194
) {
195195
if_chain! {
196-
if match_path(&trait_ref.path, &paths::HASH);
197196
if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait();
198-
if let Some(def_id) = &trait_ref.trait_def_id();
199-
if !def_id.is_local();
197+
if let Some(def_id) = trait_ref.trait_def_id();
198+
if match_def_path(cx, def_id, &paths::HASH);
200199
then {
201200
// Look for the PartialEq implementations for `ty`
202201
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {
@@ -352,7 +351,8 @@ fn check_unsafe_derive_deserialize<'tcx>(
352351
}
353352

354353
if_chain! {
355-
if match_path(&trait_ref.path, &paths::SERDE_DESERIALIZE);
354+
if let Some(trait_def_id) = trait_ref.trait_def_id();
355+
if match_def_path(cx, trait_def_id, &paths::SERDE_DESERIALIZE);
356356
if let ty::Adt(def, _) = ty.kind();
357357
if let Some(local_def_id) = def.did.as_local();
358358
let adt_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_def_id);

clippy_lints/src/float_equality_without_abs.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::utils::{match_qpath, paths, span_lint_and_then, sugg};
1+
use crate::utils::{match_def_path, paths, span_lint_and_then, sugg};
22
use if_chain::if_chain;
33
use rustc_ast::util::parser::AssocOp;
44
use rustc_errors::Applicability;
5+
use rustc_hir::def::{DefKind, Res};
56
use rustc_hir::{BinOpKind, Expr, ExprKind};
67
use rustc_lint::{LateContext, LateLintPass};
78
use rustc_middle::ty;
@@ -76,7 +77,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatEqualityWithoutAbs {
7677

7778
// right hand side matches either f32::EPSILON or f64::EPSILON
7879
if let ExprKind::Path(ref epsilon_path) = rhs.kind;
79-
if match_qpath(epsilon_path, &paths::F32_EPSILON) || match_qpath(epsilon_path, &paths::F64_EPSILON);
80+
if let Res::Def(DefKind::AssocConst, def_id) = cx.qpath_res(epsilon_path, rhs.hir_id);
81+
if match_def_path(cx, def_id, &paths::F32_EPSILON) || match_def_path(cx, def_id, &paths::F64_EPSILON);
8082

8183
// values of the substractions on the left hand side are of the type float
8284
let t_val_l = cx.typeck_results().expr_ty(val_l);

clippy_lints/src/utils/paths.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ pub const DISPLAY_TRAIT: [&str; 3] = ["core", "fmt", "Display"];
3232
pub const DOUBLE_ENDED_ITERATOR: [&str; 4] = ["core", "iter", "traits", "DoubleEndedIterator"];
3333
pub const DROP: [&str; 3] = ["core", "mem", "drop"];
3434
pub const DURATION: [&str; 3] = ["core", "time", "Duration"];
35-
pub const EARLY_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "EarlyContext"];
35+
pub const EARLY_CONTEXT: [&str; 2] = ["rustc_lint", "EarlyContext"];
3636
pub const EXIT: [&str; 3] = ["std", "process", "exit"];
37-
pub const F32_EPSILON: [&str; 2] = ["f32", "EPSILON"];
38-
pub const F64_EPSILON: [&str; 2] = ["f64", "EPSILON"];
37+
pub const F32_EPSILON: [&str; 4] = ["core", "f32", "<impl f32>", "EPSILON"];
38+
pub const F64_EPSILON: [&str; 4] = ["core", "f64", "<impl f64>", "EPSILON"];
3939
pub const FILE: [&str; 3] = ["std", "fs", "File"];
4040
pub const FILE_TYPE: [&str; 3] = ["std", "fs", "FileType"];
4141
pub const FMT_ARGUMENTS_NEW_V1: [&str; 4] = ["core", "fmt", "Arguments", "new_v1"];
@@ -47,7 +47,7 @@ pub const FN_ONCE: [&str; 3] = ["core", "ops", "FnOnce"];
4747
pub const FROM_FROM: [&str; 4] = ["core", "convert", "From", "from"];
4848
pub const FROM_TRAIT: [&str; 3] = ["core", "convert", "From"];
4949
pub const FUTURE_FROM_GENERATOR: [&str; 3] = ["core", "future", "from_generator"];
50-
pub const HASH: [&str; 2] = ["hash", "Hash"];
50+
pub const HASH: [&str; 3] = ["core", "hash", "Hash"];
5151
pub const HASHMAP: [&str; 5] = ["std", "collections", "hash", "map", "HashMap"];
5252
pub const HASHMAP_ENTRY: [&str; 5] = ["std", "collections", "hash", "map", "Entry"];
5353
pub const HASHSET: [&str; 5] = ["std", "collections", "hash", "set", "HashSet"];
@@ -58,7 +58,7 @@ pub const INTO_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "Into
5858
pub const IO_READ: [&str; 3] = ["std", "io", "Read"];
5959
pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"];
6060
pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator"];
61-
pub const LATE_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "LateContext"];
61+
pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"];
6262
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
6363
pub const LINT: [&str; 3] = ["rustc_session", "lint", "Lint"];
6464
pub const MEM_DISCRIMINANT: [&str; 3] = ["core", "mem", "discriminant"];
@@ -86,8 +86,8 @@ pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"];
8686
pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"];
8787
pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"];
8888
pub const PTR_EQ: [&str; 3] = ["core", "ptr", "eq"];
89-
pub const PTR_NULL: [&str; 2] = ["ptr", "null"];
90-
pub const PTR_NULL_MUT: [&str; 2] = ["ptr", "null_mut"];
89+
pub const PTR_NULL: [&str; 3] = ["core", "ptr", "null"];
90+
pub const PTR_NULL_MUT: [&str; 3] = ["core", "ptr", "null_mut"];
9191
pub const PUSH_STR: [&str; 4] = ["alloc", "string", "String", "push_str"];
9292
pub const RANGE_ARGUMENT_TRAIT: [&str; 3] = ["core", "ops", "RangeBounds"];
9393
pub const RC: [&str; 3] = ["alloc", "rc", "Rc"];
@@ -107,7 +107,7 @@ pub const RESULT_ERR: [&str; 4] = ["core", "result", "Result", "Err"];
107107
pub const RESULT_OK: [&str; 4] = ["core", "result", "Result", "Ok"];
108108
pub const RWLOCK_READ_GUARD: [&str; 4] = ["std", "sync", "rwlock", "RwLockReadGuard"];
109109
pub const RWLOCK_WRITE_GUARD: [&str; 4] = ["std", "sync", "rwlock", "RwLockWriteGuard"];
110-
pub const SERDE_DESERIALIZE: [&str; 2] = ["_serde", "Deserialize"];
110+
pub const SERDE_DESERIALIZE: [&str; 3] = ["serde", "de", "Deserialize"];
111111
pub const SERDE_DE_VISITOR: [&str; 3] = ["serde", "de", "Visitor"];
112112
pub const SLICE_INTO_VEC: [&str; 4] = ["alloc", "slice", "<impl [T]>", "into_vec"];
113113
pub const SLICE_ITER: [&str; 4] = ["core", "slice", "iter", "Iter"];

0 commit comments

Comments
 (0)