Skip to content

Commit 6bfb524

Browse files
committed
Remove is_trait_item
1 parent e69d88b commit 6bfb524

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

clippy_lints/src/useless_conversion.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
2-
use clippy_utils::res::{MaybeDef, MaybeResPath, MaybeTypeckRes};
2+
use clippy_utils::res::{MaybeDef, MaybeQPath, MaybeResPath, MaybeTypeckRes};
33
use clippy_utils::source::{snippet, snippet_with_context};
44
use clippy_utils::sugg::{DiagExt as _, Sugg};
55
use clippy_utils::ty::{is_copy, same_type_modulo_regions};
6-
use clippy_utils::{get_parent_expr, is_trait_item, is_ty_alias, sym};
6+
use clippy_utils::{get_parent_expr, is_ty_alias, sym};
77
use rustc_errors::Applicability;
88
use rustc_hir::def_id::DefId;
99
use rustc_hir::{BindingMode, Expr, ExprKind, HirId, MatchSource, Mutability, Node, PatKind};
@@ -180,7 +180,10 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
180180
path.ident.name,
181181
sym::map | sym::map_err | sym::map_break | sym::map_continue
182182
) && has_eligible_receiver(cx, recv, e)
183-
&& (is_trait_item(cx, arg, sym::Into) || is_trait_item(cx, arg, sym::From))
183+
&& matches!(
184+
arg.res(cx).assoc_parent(cx).opt_diag_name(cx),
185+
Some(sym::Into | sym::From)
186+
)
184187
&& let ty::FnDef(_, args) = cx.typeck_results().expr_ty(arg).kind()
185188
&& let &[from_ty, to_ty] = args.into_type_list(cx.tcx).as_slice()
186189
&& same_type_modulo_regions(from_ty, to_ty)

clippy_utils/src/lib.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,25 +358,6 @@ pub fn is_def_id_trait_method(cx: &LateContext<'_>, def_id: LocalDefId) -> bool
358358
}
359359
}
360360

361-
/// Checks if the given expression is a path referring an item on the trait
362-
/// that is marked with the given diagnostic item.
363-
///
364-
/// For checking method call expressions instead of path expressions, use
365-
/// [`is_trait_method`].
366-
///
367-
/// For example, this can be used to find if an expression like `u64::default`
368-
/// refers to an item of the trait `Default`, which is associated with the
369-
/// `diag_item` of `sym::Default`.
370-
pub fn is_trait_item(cx: &LateContext<'_>, expr: &Expr<'_>, diag_item: Symbol) -> bool {
371-
if let ExprKind::Path(ref qpath) = expr.kind {
372-
cx.qpath_res(qpath, expr.hir_id)
373-
.assoc_parent(cx)
374-
.is_diag_item(cx, diag_item)
375-
} else {
376-
false
377-
}
378-
}
379-
380361
pub fn last_path_segment<'tcx>(path: &QPath<'tcx>) -> &'tcx PathSegment<'tcx> {
381362
match *path {
382363
QPath::Resolved(_, path) => path.segments.last().expect("A path must have at least one segment"),

0 commit comments

Comments
 (0)