about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-25 23:09:33 +0000
committerbors <bors@rust-lang.org>2024-03-25 23:09:33 +0000
commit805ef35ca14b265f5ee9b5ea3f06a12736ec14f9 (patch)
tree18c75fd5cb7635699c17d550b77c4927fe2f011c
parentca6a6474904fc7d3e4519a3b5506294b33a12ea8 (diff)
parent94fe2fac633e4a17f9ba63ee74689beae62d24b6 (diff)
downloadrust-805ef35ca14b265f5ee9b5ea3f06a12736ec14f9.tar.gz
rust-805ef35ca14b265f5ee9b5ea3f06a12736ec14f9.zip
Auto merge of #12540 - m-rph:12366, r=blyxyas
Remove `unwrap` from `match_trait_method`

Unused_IO_amount relies on `match_trait_method` in order to match trait methods that exist in Tokio traits as the corresponding symbols don't exist.

With this commit we remove the unwrap that caused #12366.
Note: author (`@m-rph)` and `@GuillaumeGomez` couldn't replicate #12366.

changelog:none

r? `@blyxyas`
-rw-r--r--clippy_utils/src/lib.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs
index 5babc024a6e..5e356f554ef 100644
--- a/clippy_utils/src/lib.rs
+++ b/clippy_utils/src/lib.rs
@@ -300,9 +300,10 @@ pub fn is_ty_alias(qpath: &QPath<'_>) -> bool {
 /// Checks if the method call given in `expr` belongs to the given trait.
 /// This is a deprecated function, consider using [`is_trait_method`].
 pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool {
-    let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
-    let trt_id = cx.tcx.trait_of_item(def_id);
-    trt_id.map_or(false, |trt_id| match_def_path(cx, trt_id, path))
+    cx.typeck_results()
+        .type_dependent_def_id(expr.hir_id)
+        .and_then(|defid| cx.tcx.trait_of_item(defid))
+        .map_or(false, |trt_id| match_def_path(cx, trt_id, path))
 }
 
 /// Checks if a method is defined in an impl of a diagnostic item