@@ -15,14 +15,20 @@ use rustc_span::{sym, Span};
15
15
16
16
use super :: MAP_CLONE ;
17
17
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.
18
21
fn should_run_lint ( cx : & LateContext < ' _ > , e : & hir:: Expr < ' _ > , method_id : DefId ) -> bool {
19
22
if is_diag_trait_item ( cx, method_id, sym:: Iterator ) {
20
23
return true ;
21
24
}
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) {
23
27
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 {
26
32
return false ;
27
33
}
28
34
// 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) ->
32
38
return path2. ident . name != sym:: as_ref || path1. ident . name != sym:: map;
33
39
}
34
40
35
- return true ;
41
+ true
36
42
}
37
43
38
44
pub ( super ) fn check ( cx : & LateContext < ' _ > , e : & hir:: Expr < ' _ > , recv : & hir:: Expr < ' _ > , arg : & hir:: Expr < ' _ > , msrv : & Msrv ) {
0 commit comments