@@ -15,14 +15,20 @@ use rustc_span::{sym, Span};
1515
1616use super :: MAP_CLONE ;
1717
18+ // If this `map` is called on an `Option` or a `Result` and the previous call is `as_ref`, we don't
19+ // run this lint because it would overlap with `useless_asref` which provides a better suggestion
20+ // in this case.
1821fn should_run_lint ( cx : & LateContext < ' _ > , e : & hir:: Expr < ' _ > , method_id : DefId ) -> bool {
1922 if is_diag_trait_item ( cx, method_id, sym:: Iterator ) {
2023 return true ;
2124 }
22- if !cx. tcx . impl_of_method ( method_id) . map_or ( false , |id| {
25+ // We check if it's an `Option` or a `Result`.
26+ if let Some ( id) = cx. tcx . impl_of_method ( method_id) {
2327 let identity = cx. tcx . type_of ( id) . instantiate_identity ( ) ;
24- is_type_diagnostic_item ( cx, identity, sym:: Option ) || is_type_diagnostic_item ( cx, identity, sym:: Result )
25- } ) {
28+ if !is_type_diagnostic_item ( cx, identity, sym:: Option ) && !is_type_diagnostic_item ( cx, identity, sym:: Result ) {
29+ return false ;
30+ }
31+ } else {
2632 return false ;
2733 }
2834 // We check if the previous method call is `as_ref`.
@@ -32,7 +38,7 @@ fn should_run_lint(cx: &LateContext<'_>, e: &hir::Expr<'_>, method_id: DefId) ->
3238 return path2. ident . name != sym:: as_ref || path1. ident . name != sym:: map;
3339 }
3440
35- return true ;
41+ true
3642}
3743
3844pub ( super ) fn check ( cx : & LateContext < ' _ > , e : & hir:: Expr < ' _ > , recv : & hir:: Expr < ' _ > , arg : & hir:: Expr < ' _ > , msrv : & Msrv ) {
0 commit comments