about summary refs log tree commit diff
path: root/clippy_utils/src/lib.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-10-21 11:48:55 +0000
committerbors <bors@rust-lang.org>2023-10-21 11:48:55 +0000
commit2b030eb03d9e5837440b1ee0b98c50b97c0c5889 (patch)
treec0b8be611ed80c6db3c754980d646c647e57edd1 /clippy_utils/src/lib.rs
parent23af253face1d23bdd5a51f7f29b251ad7094f8b (diff)
parenta585cda701581a16894858dc088eacd5a02fc78b (diff)
Auto merge of #11694 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: none
Diffstat (limited to 'clippy_utils/src/lib.rs')
-rw-r--r--clippy_utils/src/lib.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index dc1b5a0a324..93b37022822 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -2048,21 +2048,33 @@ fn is_body_identity_function(cx: &LateContext<'_>, func: &Body<'_>) -> bool {
     let mut expr = func.value;
     loop {
         match expr.kind {
-            #[rustfmt::skip]
-                ExprKind::Block(&Block { stmts: [], expr: Some(e), .. }, _, )
-                | ExprKind::Ret(Some(e)) => expr = e,
-            #[rustfmt::skip]
-                ExprKind::Block(&Block { stmts: [stmt], expr: None, .. }, _) => {
-                    if_chain! {
-                        if let StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind;
-                        if let ExprKind::Ret(Some(ret_val)) = e.kind;
-                        then {
-                            expr = ret_val;
-                        } else {
-                            return false;
-                        }
-                    }
+            ExprKind::Block(
+                &Block {
+                    stmts: [],
+                    expr: Some(e),
+                    ..
+                },
+                _,
+            )
+            | ExprKind::Ret(Some(e)) => expr = e,
+            ExprKind::Block(
+                &Block {
+                    stmts: [stmt],
+                    expr: None,
+                    ..
                 },
+                _,
+            ) => {
+                if_chain! {
+                    if let StmtKind::Semi(e) | StmtKind::Expr(e) = stmt.kind;
+                    if let ExprKind::Ret(Some(ret_val)) = e.kind;
+                    then {
+                        expr = ret_val;
+                    } else {
+                        return false;
+                    }
+                }
+            },
             _ => return path_to_local_id(expr, id) && cx.typeck_results().expr_adjustments(expr).is_empty(),
         }
     }
@@ -2081,9 +2093,8 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>)
         },
         ExprKind::Path(QPath::Resolved(_, path))
             if path.segments.iter().all(|seg| seg.infer_args)
-                && let Some(did) = path.res.opt_def_id() =>
-        {
-            match_def_path(cx, did, &paths::CONVERT_IDENTITY)
+                && let Some(did) = path.res.opt_def_id() => {
+            cx.tcx.is_diagnostic_item(sym::convert_identity, did)
         },
         _ => false,
     }
@@ -2100,7 +2111,7 @@ pub fn is_expr_untyped_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>)
 pub fn is_expr_identity_function(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
     match expr.kind {
         ExprKind::Closure(&Closure { body, .. }) => is_body_identity_function(cx, cx.tcx.hir().body(body)),
-        _ => path_def_id(cx, expr).map_or(false, |id| match_def_path(cx, id, &paths::CONVERT_IDENTITY)),
+        _ => path_def_id(cx, expr).map_or(false, |id| cx.tcx.is_diagnostic_item(sym::convert_identity, id)),
     }
 }