Skip to content

Commit a737ba8

Browse files
committed
Fix and improve internal lint checking for match_type usages
* Check for `const`s and `static`s from external crates * Check for `LangItem`s * Handle inherent functions which have the same name as a field * Also check the following functions: * `match_trait_method` * `match_def_path` * `is_expr_path_def_path` * `is_qpath_def_path` * Handle checking for a constructor to a diagnostic item or `LangItem`
1 parent c736a63 commit a737ba8

34 files changed

+539
-223
lines changed

clippy_lints/src/derive.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_note, span_lint_and_then};
22
use clippy_utils::paths;
33
use clippy_utils::ty::{implements_trait, is_copy};
4-
use clippy_utils::{get_trait_def_id, is_automatically_derived, is_lint_allowed, match_def_path};
4+
use clippy_utils::{get_trait_def_id, is_automatically_derived, is_diagnostic_item, is_lint_allowed, match_def_path};
55
use if_chain::if_chain;
66
use rustc_hir::intravisit::{walk_expr, walk_fn, walk_item, FnKind, NestedVisitorMap, Visitor};
77
use rustc_hir::{
@@ -12,6 +12,7 @@ use rustc_middle::hir::map::Map;
1212
use rustc_middle::ty::{self, Ty};
1313
use rustc_session::{declare_lint_pass, declare_tool_lint};
1414
use rustc_span::source_map::Span;
15+
use rustc_span::sym;
1516

1617
declare_clippy_lint! {
1718
/// ### What it does
@@ -196,7 +197,7 @@ fn check_hash_peq<'tcx>(
196197
if_chain! {
197198
if let Some(peq_trait_def_id) = cx.tcx.lang_items().eq_trait();
198199
if let Some(def_id) = trait_ref.trait_def_id();
199-
if match_def_path(cx, def_id, &paths::HASH);
200+
if is_diagnostic_item(cx, def_id, sym::Hash);
200201
then {
201202
// Look for the PartialEq implementations for `ty`
202203
cx.tcx.for_each_relevant_impl(peq_trait_def_id, ty, |impl_id| {

clippy_lints/src/drop_forget_ref.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use clippy_utils::diagnostics::span_lint_and_note;
2+
use clippy_utils::is_diagnostic_item;
23
use clippy_utils::ty::is_copy;
3-
use clippy_utils::{match_def_path, paths};
44
use if_chain::if_chain;
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::ty;
88
use rustc_session::{declare_lint_pass, declare_tool_lint};
9+
use rustc_span::sym;
910

1011
declare_clippy_lint! {
1112
/// ### What it does
@@ -128,10 +129,10 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
128129
let arg_ty = cx.typeck_results().expr_ty(arg);
129130

130131
if let ty::Ref(..) = arg_ty.kind() {
131-
if match_def_path(cx, def_id, &paths::DROP) {
132+
if is_diagnostic_item(cx, def_id, sym::mem_drop) {
132133
lint = DROP_REF;
133134
msg = DROP_REF_SUMMARY.to_string();
134-
} else if match_def_path(cx, def_id, &paths::MEM_FORGET) {
135+
} else if is_diagnostic_item(cx, def_id, sym::mem_forget) {
135136
lint = FORGET_REF;
136137
msg = FORGET_REF_SUMMARY.to_string();
137138
} else {
@@ -144,10 +145,10 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef {
144145
Some(arg.span),
145146
&format!("argument has type `{}`", arg_ty));
146147
} else if is_copy(cx, arg_ty) {
147-
if match_def_path(cx, def_id, &paths::DROP) {
148+
if is_diagnostic_item(cx, def_id, sym::mem_drop) {
148149
lint = DROP_COPY;
149150
msg = DROP_COPY_SUMMARY.to_string();
150-
} else if match_def_path(cx, def_id, &paths::MEM_FORGET) {
151+
} else if is_diagnostic_item(cx, def_id, sym::mem_forget) {
151152
lint = FORGET_COPY;
152153
msg = FORGET_COPY_SUMMARY.to_string();
153154
} else {

clippy_lints/src/duration_subsec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use clippy_utils::source::snippet_with_applicability;
2-
use clippy_utils::ty::match_type;
2+
use clippy_utils::ty::is_type_diagnostic_item;
33
use if_chain::if_chain;
44
use rustc_errors::Applicability;
55
use rustc_hir::{BinOpKind, Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
88
use rustc_span::source_map::Spanned;
9+
use rustc_span::sym;
910

1011
use clippy_utils::consts::{constant, Constant};
1112
use clippy_utils::diagnostics::span_lint_and_sugg;
12-
use clippy_utils::paths;
1313

1414
declare_clippy_lint! {
1515
/// ### What it does
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
4646
if_chain! {
4747
if let ExprKind::Binary(Spanned { node: BinOpKind::Div, .. }, left, right) = expr.kind;
4848
if let ExprKind::MethodCall(method_path, _ , args, _) = left.kind;
49-
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION);
49+
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), sym::Duration);
5050
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
5151
then {
5252
let suggested_fn = match (method_path.ident.as_str(), divisor) {

clippy_lints/src/infinite_iter.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint;
22
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
3-
use clippy_utils::{get_trait_def_id, higher, is_qpath_def_path, paths};
3+
use clippy_utils::{get_trait_def_id, higher, is_diagnostic_item, paths};
44
use rustc_hir::{BorrowKind, Expr, ExprKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -169,7 +169,10 @@ fn is_infinite(cx: &LateContext<'_>, expr: &Expr<'_>) -> Finiteness {
169169
ExprKind::Box(e) | ExprKind::AddrOf(BorrowKind::Ref, _, e) => is_infinite(cx, e),
170170
ExprKind::Call(path, _) => {
171171
if let ExprKind::Path(ref qpath) = path.kind {
172-
is_qpath_def_path(cx, qpath, path.hir_id, &paths::ITER_REPEAT).into()
172+
cx.qpath_res(qpath, path.hir_id)
173+
.opt_def_id()
174+
.map_or(false, |id| is_diagnostic_item(cx, id, sym::iter_repeat))
175+
.into()
173176
} else {
174177
Finite
175178
}

clippy_lints/src/lib.register_internal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ store.register_group(true, "clippy::internal", Some("clippy_internal"), vec![
1212
LintId::of(utils::internal_lints::INVALID_CLIPPY_VERSION_ATTRIBUTE),
1313
LintId::of(utils::internal_lints::INVALID_PATHS),
1414
LintId::of(utils::internal_lints::LINT_WITHOUT_LINT_PASS),
15-
LintId::of(utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM),
1615
LintId::of(utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE),
1716
LintId::of(utils::internal_lints::OUTER_EXPN_EXPN_DATA),
1817
LintId::of(utils::internal_lints::PRODUCE_ICE),
18+
LintId::of(utils::internal_lints::UNNECESSARY_DEF_PATH),
1919
LintId::of(utils::internal_lints::UNNECESSARY_SYMBOL_STR),
2020
])

clippy_lints/src/lib.register_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ store.register_lints(&[
2222
#[cfg(feature = "internal-lints")]
2323
utils::internal_lints::LINT_WITHOUT_LINT_PASS,
2424
#[cfg(feature = "internal-lints")]
25-
utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
26-
#[cfg(feature = "internal-lints")]
2725
utils::internal_lints::MISSING_CLIPPY_VERSION_ATTRIBUTE,
2826
#[cfg(feature = "internal-lints")]
2927
utils::internal_lints::OUTER_EXPN_EXPN_DATA,
3028
#[cfg(feature = "internal-lints")]
3129
utils::internal_lints::PRODUCE_ICE,
3230
#[cfg(feature = "internal-lints")]
31+
utils::internal_lints::UNNECESSARY_DEF_PATH,
32+
#[cfg(feature = "internal-lints")]
3333
utils::internal_lints::UNNECESSARY_SYMBOL_STR,
3434
absurd_extreme_comparisons::ABSURD_EXTREME_COMPARISONS,
3535
approx_const::APPROX_CONSTANT,

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
503503
store.register_late_pass(|| Box::new(utils::internal_lints::InvalidPaths));
504504
store.register_late_pass(|| Box::new(utils::internal_lints::InterningDefinedSymbol::default()));
505505
store.register_late_pass(|| Box::new(utils::internal_lints::LintWithoutLintPass::default()));
506-
store.register_late_pass(|| Box::new(utils::internal_lints::MatchTypeOnDiagItem));
506+
store.register_late_pass(|| Box::new(utils::internal_lints::UnnecessaryDefPath));
507507
store.register_late_pass(|| Box::new(utils::internal_lints::OuterExpnDataPass));
508508
}
509509

clippy_lints/src/loops/while_let_on_iterator.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ use super::WHILE_LET_ON_ITERATOR;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::higher;
44
use clippy_utils::source::snippet_with_applicability;
5-
use clippy_utils::{
6-
get_enclosing_loop_or_closure, is_refutable, is_trait_method, match_def_path, paths, visitors::is_res_used,
7-
};
5+
use clippy_utils::{get_enclosing_loop_or_closure, is_lang_item, is_refutable, is_trait_method, visitors::is_res_used};
86
use if_chain::if_chain;
97
use rustc_errors::Applicability;
108
use rustc_hir::intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor};
11-
use rustc_hir::{def::Res, Expr, ExprKind, HirId, Local, PatKind, QPath, UnOp};
9+
use rustc_hir::{def::Res, Expr, ExprKind, HirId, LangItem, Local, PatKind, QPath, UnOp};
1210
use rustc_lint::LateContext;
1311
use rustc_span::{symbol::sym, Span, Symbol};
1412

@@ -18,7 +16,7 @@ pub(super) fn check(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
1816
// check for `Some(..)` pattern
1917
if let PatKind::TupleStruct(QPath::Resolved(None, pat_path), some_pat, _) = let_pat.kind;
2018
if let Res::Def(_, pat_did) = pat_path.res;
21-
if match_def_path(cx, pat_did, &paths::OPTION_SOME);
19+
if is_lang_item(cx, pat_did, LangItem::OptionSome);
2220
// check for call to `Iterator::next`
2321
if let ExprKind::MethodCall(method_name, _, [iter_expr], _) = let_expr.kind;
2422
if method_name.ident.name == sym::next;

clippy_lints/src/mem_forget.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::{match_def_path, paths};
2+
use clippy_utils::is_diagnostic_item;
33
use rustc_hir::{Expr, ExprKind};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_session::{declare_lint_pass, declare_tool_lint};
6+
use rustc_span::sym;
67

78
declare_clippy_lint! {
89
/// ### What it does
@@ -32,7 +33,7 @@ impl<'tcx> LateLintPass<'tcx> for MemForget {
3233
if let ExprKind::Call(path_expr, [ref first_arg, ..]) = e.kind {
3334
if let ExprKind::Path(ref qpath) = path_expr.kind {
3435
if let Some(def_id) = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id() {
35-
if match_def_path(cx, def_id, &paths::MEM_FORGET) {
36+
if is_diagnostic_item(cx, def_id, sym::mem_forget) {
3637
let forgot_ty = cx.typeck_results().expr_ty(first_arg);
3738

3839
if forgot_ty.ty_adt_def().map_or(false, |def| def.has_dtor(cx.tcx)) {

clippy_lints/src/mem_replace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
22
use clippy_utils::source::{snippet, snippet_with_applicability};
33
use clippy_utils::ty::is_non_aggregate_primitive_type;
4-
use clippy_utils::{is_default_equivalent, is_lang_ctor, match_def_path, meets_msrv, msrvs, paths};
4+
use clippy_utils::{is_default_equivalent, is_diagnostic_item, is_lang_ctor, meets_msrv, msrvs};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::LangItem::OptionNone;
@@ -249,7 +249,7 @@ impl<'tcx> LateLintPass<'tcx> for MemReplace {
249249
if let ExprKind::Call(func, func_args) = expr.kind;
250250
if let ExprKind::Path(ref func_qpath) = func.kind;
251251
if let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id();
252-
if match_def_path(cx, def_id, &paths::MEM_REPLACE);
252+
if is_diagnostic_item(cx, def_id, sym::mem_replace);
253253
if let [dest, src] = func_args;
254254
then {
255255
check_replace_option_with_none(cx, src, dest, expr.span);

clippy_lints/src/methods/filetype_is_file.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
2-
use clippy_utils::ty::match_type;
3-
use clippy_utils::{get_parent_expr, paths};
2+
use clippy_utils::get_parent_expr;
3+
use clippy_utils::ty::is_type_diagnostic_item;
44
use if_chain::if_chain;
55
use rustc_hir as hir;
66
use rustc_lint::LateContext;
77
use rustc_span::source_map::Span;
8+
use rustc_span::sym;
89

910
use super::FILETYPE_IS_FILE;
1011

1112
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
1213
let ty = cx.typeck_results().expr_ty(recv);
1314

14-
if !match_type(cx, ty, &paths::FILE_TYPE) {
15+
if !is_type_diagnostic_item(cx, ty, sym::FileType) {
1516
return;
1617
}
1718

clippy_lints/src/methods/inefficient_to_string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::ty::{is_type_diagnostic_item, walk_ptrs_ty_depth};
4-
use clippy_utils::{match_def_path, paths};
4+
use clippy_utils::{is_diagnostic_item, match_def_path, paths};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
@@ -60,7 +60,7 @@ fn specializes_tostring(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
6060
}
6161

6262
if let ty::Adt(adt, substs) = ty.kind() {
63-
match_def_path(cx, adt.did, &paths::COW) && substs.type_at(1).is_str()
63+
is_diagnostic_item(cx, adt.did, sym::Cow) && substs.type_at(1).is_str()
6464
} else {
6565
false
6666
}

clippy_lints/src/methods/manual_str_repeat.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2+
use clippy_utils::is_expr_diagnostic_item;
23
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
34
use clippy_utils::sugg::Sugg;
4-
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item, match_type};
5-
use clippy_utils::{is_expr_path_def_path, paths};
5+
use clippy_utils::ty::{is_type_diagnostic_item, is_type_lang_item};
66
use if_chain::if_chain;
77
use rustc_ast::LitKind;
88
use rustc_errors::Applicability;
@@ -38,7 +38,7 @@ fn parse_repeat_arg(cx: &LateContext<'_>, e: &Expr<'_>) -> Option<RepeatKind> {
3838
let ty = cx.typeck_results().expr_ty(e);
3939
if is_type_diagnostic_item(cx, ty, sym::String)
4040
|| (is_type_lang_item(cx, ty, LangItem::OwnedBox) && get_ty_param(ty).map_or(false, TyS::is_str))
41-
|| (match_type(cx, ty, &paths::COW) && get_ty_param(ty).map_or(false, TyS::is_str))
41+
|| (is_type_diagnostic_item(cx, ty, sym::Cow) && get_ty_param(ty).map_or(false, TyS::is_str))
4242
{
4343
Some(RepeatKind::String)
4444
} else {
@@ -57,7 +57,7 @@ pub(super) fn check(
5757
) {
5858
if_chain! {
5959
if let ExprKind::Call(repeat_fn, [repeat_arg]) = take_self_arg.kind;
60-
if is_expr_path_def_path(cx, repeat_fn, &paths::ITER_REPEAT);
60+
if is_expr_diagnostic_item(cx, repeat_fn, sym::iter_repeat);
6161
if is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(collect_expr), sym::String);
6262
if let Some(collect_id) = cx.typeck_results().type_dependent_def_id(collect_expr.hir_id);
6363
if let Some(take_id) = cx.typeck_results().type_dependent_def_id(take_expr.hir_id);

clippy_lints/src/methods/uninit_assumed_init.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use clippy_utils::diagnostics::span_lint;
2-
use clippy_utils::{is_expr_path_def_path, paths, ty::is_uninit_value_valid_for_ty};
2+
use clippy_utils::{is_expr_diagnostic_item, ty::is_uninit_value_valid_for_ty};
33
use if_chain::if_chain;
44
use rustc_hir as hir;
55
use rustc_lint::LateContext;
6+
use rustc_span::sym;
67

78
use super::UNINIT_ASSUMED_INIT;
89

@@ -11,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr
1112
if_chain! {
1213
if let hir::ExprKind::Call(callee, args) = recv.kind;
1314
if args.is_empty();
14-
if is_expr_path_def_path(cx, callee, &paths::MEM_MAYBEUNINIT_UNINIT);
15+
if is_expr_diagnostic_item(cx, callee, sym::maybe_uninit_uninit);
1516
if !is_uninit_value_valid_for_ty(cx, cx.typeck_results().expr_ty_adjusted(expr));
1617
then {
1718
span_lint(

clippy_lints/src/methods/useless_asref.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::ty::walk_ptrs_ty_depth;
4-
use clippy_utils::{get_parent_expr, match_trait_method, paths};
4+
use clippy_utils::{get_parent_expr, is_trait_method};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
88
use rustc_lint::LateContext;
9+
use rustc_span::sym;
910

1011
use super::USELESS_ASREF;
1112

1213
/// Checks for the `USELESS_ASREF` lint.
1314
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, call_name: &str, recvr: &hir::Expr<'_>) {
1415
// when we get here, we've already checked that the call name is "as_ref" or "as_mut"
1516
// check if the call is to the actual `AsRef` or `AsMut` trait
16-
if match_trait_method(cx, expr, &paths::ASREF_TRAIT) || match_trait_method(cx, expr, &paths::ASMUT_TRAIT) {
17+
if is_trait_method(cx, expr, sym::AsRef) || is_trait_method(cx, expr, sym::AsMut) {
1718
// check if the type after `as_ref` or `as_mut` is the same as before
1819
let rcv_ty = cx.typeck_results().expr_ty(recvr);
1920
let res_ty = cx.typeck_results().expr_ty(expr);

clippy_lints/src/minmax.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use clippy_utils::consts::{constant_simple, Constant};
22
use clippy_utils::diagnostics::span_lint;
3-
use clippy_utils::{match_def_path, match_trait_method, paths};
3+
use clippy_utils::{is_diagnostic_item, is_trait_method};
44
use if_chain::if_chain;
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_session::{declare_lint_pass, declare_tool_lint};
8+
use rustc_span::sym;
89
use std::cmp::Ordering;
910

1011
declare_clippy_lint! {
@@ -74,9 +75,9 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons
7475
.qpath_res(qpath, path.hir_id)
7576
.opt_def_id()
7677
.and_then(|def_id| {
77-
if match_def_path(cx, def_id, &paths::CMP_MIN) {
78+
if is_diagnostic_item(cx, def_id, sym::cmp_min) {
7879
fetch_const(cx, args, MinMax::Min)
79-
} else if match_def_path(cx, def_id, &paths::CMP_MAX) {
80+
} else if is_diagnostic_item(cx, def_id, sym::cmp_max) {
8081
fetch_const(cx, args, MinMax::Max)
8182
} else {
8283
None
@@ -89,7 +90,7 @@ fn min_max<'a>(cx: &LateContext<'_>, expr: &'a Expr<'a>) -> Option<(MinMax, Cons
8990
ExprKind::MethodCall(path, _, args, _) => {
9091
if_chain! {
9192
if let [obj, _] = args;
92-
if cx.typeck_results().expr_ty(obj).is_floating_point() || match_trait_method(cx, expr, &paths::ORD);
93+
if cx.typeck_results().expr_ty(obj).is_floating_point() || is_trait_method(cx, expr, sym::Ord);
9394
then {
9495
if path.ident.name == sym!(max) {
9596
fetch_const(cx, args, MinMax::Max)

clippy_lints/src/non_octal_unix_permissions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::{snippet_opt, snippet_with_applicability};
3-
use clippy_utils::ty::match_type;
3+
use clippy_utils::ty::{is_type_diagnostic_item, match_type};
44
use clippy_utils::{match_def_path, paths};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::{Expr, ExprKind};
88
use rustc_lint::{LateContext, LateLintPass};
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
10+
use rustc_span::sym;
1011

1112
declare_clippy_lint! {
1213
/// ### What it does
@@ -49,7 +50,7 @@ impl LateLintPass<'_> for NonOctalUnixPermissions {
4950
if_chain! {
5051
if (path.ident.name == sym!(mode)
5152
&& (match_type(cx, obj_ty, &paths::OPEN_OPTIONS)
52-
|| match_type(cx, obj_ty, &paths::DIR_BUILDER)))
53+
|| is_type_diagnostic_item(cx, obj_ty, sym::DirBuilder)))
5354
|| (path.ident.name == sym!(set_mode) && match_type(cx, obj_ty, &paths::PERMISSIONS));
5455
if let ExprKind::Lit(_) = param.kind;
5556

0 commit comments

Comments
 (0)