Skip to content

Commit 06e7590

Browse files
authored
Refactor function after adding a new diagnostic item (rust-lang#14306)
The `has_eligible_receiver()` function had been adapted *a minima* when the `sym::ControlFlow` diagnostic item has been added to rustc. This refactors the function content to make its meaning clearer. changelog: none
2 parents ad633be + 3a39629 commit 06e7590

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

clippy_lints/src/useless_conversion.rs

Lines changed: 9 additions & 19 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_context};
33
use clippy_utils::sugg::{DiagExt as _, Sugg};
4-
use clippy_utils::ty::{is_copy, is_type_diagnostic_item, same_type_and_consts};
4+
use clippy_utils::ty::{get_type_diagnostic_name, is_copy, is_type_diagnostic_item, same_type_and_consts};
55
use clippy_utils::{
66
get_parent_expr, is_inherent_method_call, is_trait_item, is_trait_method, is_ty_alias, path_to_local,
77
};
@@ -13,7 +13,7 @@ use rustc_infer::traits::Obligation;
1313
use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::traits::ObligationCause;
1515
use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability};
16-
use rustc_middle::ty::{self, AdtDef, EarlyBinder, GenericArg, GenericArgsRef, Ty, TypeVisitableExt};
16+
use rustc_middle::ty::{self, EarlyBinder, GenericArg, GenericArgsRef, Ty, TypeVisitableExt};
1717
use rustc_session::impl_lint_pass;
1818
use rustc_span::{Span, sym};
1919
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
@@ -412,24 +412,14 @@ pub fn check_function_application(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &
412412
}
413413

414414
fn has_eligible_receiver(cx: &LateContext<'_>, recv: &Expr<'_>, expr: &Expr<'_>) -> bool {
415-
let recv_ty = cx.typeck_results().expr_ty(recv);
416-
if is_inherent_method_call(cx, expr)
417-
&& let Some(recv_ty_defid) = recv_ty.ty_adt_def().map(AdtDef::did)
418-
{
419-
if let Some(diag_name) = cx.tcx.get_diagnostic_name(recv_ty_defid)
420-
&& matches!(diag_name, sym::Option | sym::Result)
421-
{
422-
return true;
423-
}
424-
425-
if cx.tcx.is_diagnostic_item(sym::ControlFlow, recv_ty_defid) {
426-
return true;
427-
}
428-
}
429-
if is_trait_method(cx, expr, sym::Iterator) {
430-
return true;
415+
if is_inherent_method_call(cx, expr) {
416+
matches!(
417+
get_type_diagnostic_name(cx, cx.typeck_results().expr_ty(recv)),
418+
Some(sym::Option | sym::Result | sym::ControlFlow)
419+
)
420+
} else {
421+
is_trait_method(cx, expr, sym::Iterator)
431422
}
432-
false
433423
}
434424

435425
fn adjustments(cx: &LateContext<'_>, expr: &Expr<'_>) -> String {

0 commit comments

Comments
 (0)