Skip to content

Commit 94fe2fa

Browse files
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 may have caused 12366. Note: author (@m-rph) and @GuillaumeGomez couldn't replicate 12366.
1 parent 660b058 commit 94fe2fa

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

clippy_utils/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,10 @@ pub fn is_ty_alias(qpath: &QPath<'_>) -> bool {
298298
/// Checks if the method call given in `expr` belongs to the given trait.
299299
/// This is a deprecated function, consider using [`is_trait_method`].
300300
pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str]) -> bool {
301-
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
302-
let trt_id = cx.tcx.trait_of_item(def_id);
303-
trt_id.map_or(false, |trt_id| match_def_path(cx, trt_id, path))
301+
cx.typeck_results()
302+
.type_dependent_def_id(expr.hir_id)
303+
.and_then(|defid| cx.tcx.trait_of_item(defid))
304+
.map_or(false, |trt_id| match_def_path(cx, trt_id, path))
304305
}
305306

306307
/// Checks if a method is defined in an impl of a diagnostic item

0 commit comments

Comments
 (0)