1
1
use crate :: utils:: {
2
- in_macro, is_type_diagnostic_item, match_path , match_qpath, paths, return_ty, snippet, span_lint_and_then,
3
- trait_ref_of_method , visitors:: find_all_ret_expressions,
2
+ in_macro, is_type_diagnostic_item, match_qpath, paths, return_ty, snippet, span_lint_and_then,
3
+ visitors:: find_all_ret_expressions,
4
4
} ;
5
5
use if_chain:: if_chain;
6
6
use rustc_errors:: Applicability ;
7
7
use rustc_hir:: intravisit:: FnKind ;
8
- use rustc_hir:: { Body , ExprKind , FnDecl , HirId } ;
8
+ use rustc_hir:: { Body , ExprKind , FnDecl , HirId , ItemKind , Node } ;
9
9
use rustc_lint:: { LateContext , LateLintPass } ;
10
10
use rustc_middle:: ty:: subst:: GenericArgKind ;
11
11
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -63,14 +63,6 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
63
63
span : Span ,
64
64
hir_id : HirId ,
65
65
) {
66
- if_chain ! {
67
- if let Some ( trait_ref) = trait_ref_of_method( cx, hir_id) ;
68
- if match_path( trait_ref. path, & paths:: PARTIAL_ORD ) ;
69
- then {
70
- return ;
71
- }
72
- }
73
-
74
66
match fn_kind {
75
67
FnKind :: ItemFn ( .., visibility, _) | FnKind :: Method ( .., Some ( visibility) , _) => {
76
68
if visibility. node . is_pub ( ) {
@@ -81,6 +73,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
81
73
_ => ( ) ,
82
74
}
83
75
76
+ if let Some ( Node :: Item ( item) ) = cx. tcx . hir ( ) . find ( cx. tcx . hir ( ) . get_parent_node ( hir_id) ) {
77
+ if matches ! ( item. kind, ItemKind :: Impl { of_trait: Some ( _) , ..} | ItemKind :: Trait ( ..) ) {
78
+ return ;
79
+ }
80
+ }
81
+
84
82
let ( return_type, path) = if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( option_type) ) {
85
83
( "Option" , & paths:: OPTION_SOME )
86
84
} else if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( result_type) ) {
0 commit comments