11use 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,
44} ;
55use if_chain:: if_chain;
66use rustc_errors:: Applicability ;
77use rustc_hir:: intravisit:: FnKind ;
8- use rustc_hir:: { Body , ExprKind , FnDecl , HirId } ;
8+ use rustc_hir:: { Body , ExprKind , FnDecl , HirId , ItemKind , Node } ;
99use rustc_lint:: { LateContext , LateLintPass } ;
1010use rustc_middle:: ty:: subst:: GenericArgKind ;
1111use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
@@ -63,14 +63,6 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
6363 span : Span ,
6464 hir_id : HirId ,
6565 ) {
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-
7466 match fn_kind {
7567 FnKind :: ItemFn ( .., visibility, _) | FnKind :: Method ( .., Some ( visibility) , _) => {
7668 if visibility. node . is_pub ( ) {
@@ -81,6 +73,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWrap {
8173 _ => ( ) ,
8274 }
8375
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+
8482 let ( return_type, path) = if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( option_type) ) {
8583 ( "Option" , & paths:: OPTION_SOME )
8684 } else if is_type_diagnostic_item ( cx, return_ty ( cx, hir_id) , sym ! ( result_type) ) {
0 commit comments