@@ -1701,7 +1701,7 @@ mod redundant_pattern_match {
17011701 use super :: REDUNDANT_PATTERN_MATCHING ;
17021702 use clippy_utils:: diagnostics:: span_lint_and_then;
17031703 use clippy_utils:: source:: snippet;
1704- use clippy_utils:: { is_lang_ctor, is_trait_method , match_qpath , paths} ;
1704+ use clippy_utils:: { is_lang_ctor, is_qpath_def_path , is_trait_method , paths} ;
17051705 use if_chain:: if_chain;
17061706 use rustc_ast:: ast:: LitKind ;
17071707 use rustc_errors:: Applicability ;
@@ -1735,8 +1735,8 @@ mod redundant_pattern_match {
17351735 kind = & inner. kind ;
17361736 }
17371737 let good_method = match kind {
1738- PatKind :: TupleStruct ( ref path, patterns , _) if patterns . len ( ) == 1 => {
1739- if let PatKind :: Wild = patterns [ 0 ] . kind {
1738+ PatKind :: TupleStruct ( ref path, [ sub_pat ] , _) => {
1739+ if let PatKind :: Wild = sub_pat . kind {
17401740 if is_lang_ctor ( cx, path, ResultOk ) {
17411741 "is_ok()"
17421742 } else if is_lang_ctor ( cx, path, ResultErr ) {
@@ -1745,9 +1745,9 @@ mod redundant_pattern_match {
17451745 "is_some()"
17461746 } else if is_lang_ctor ( cx, path, PollReady ) {
17471747 "is_ready()"
1748- } else if match_qpath ( path, & paths:: IPADDR_V4 ) {
1748+ } else if is_qpath_def_path ( cx , path, sub_pat . hir_id , & paths:: IPADDR_V4 ) {
17491749 "is_ipv4()"
1750- } else if match_qpath ( path, & paths:: IPADDR_V6 ) {
1750+ } else if is_qpath_def_path ( cx , path, sub_pat . hir_id , & paths:: IPADDR_V6 ) {
17511751 "is_ipv6()"
17521752 } else {
17531753 return ;
@@ -1821,6 +1821,7 @@ mod redundant_pattern_match {
18211821 ) if patterns_left. len ( ) == 1 && patterns_right. len ( ) == 1 => {
18221822 if let ( PatKind :: Wild , PatKind :: Wild ) = ( & patterns_left[ 0 ] . kind , & patterns_right[ 0 ] . kind ) {
18231823 find_good_method_for_match (
1824+ cx,
18241825 arms,
18251826 path_left,
18261827 path_right,
@@ -1831,6 +1832,7 @@ mod redundant_pattern_match {
18311832 )
18321833 . or_else ( || {
18331834 find_good_method_for_match (
1835+ cx,
18341836 arms,
18351837 path_left,
18361838 path_right,
@@ -1850,6 +1852,7 @@ mod redundant_pattern_match {
18501852 {
18511853 if let PatKind :: Wild = patterns[ 0 ] . kind {
18521854 find_good_method_for_match (
1855+ cx,
18531856 arms,
18541857 path_left,
18551858 path_right,
@@ -1860,6 +1863,7 @@ mod redundant_pattern_match {
18601863 )
18611864 . or_else ( || {
18621865 find_good_method_for_match (
1866+ cx,
18631867 arms,
18641868 path_left,
18651869 path_right,
@@ -1900,7 +1904,9 @@ mod redundant_pattern_match {
19001904 }
19011905 }
19021906
1907+ #[ allow( clippy:: too_many_arguments) ]
19031908 fn find_good_method_for_match < ' a > (
1909+ cx : & LateContext < ' _ > ,
19041910 arms : & [ Arm < ' _ > ] ,
19051911 path_left : & QPath < ' _ > ,
19061912 path_right : & QPath < ' _ > ,
@@ -1909,9 +1915,13 @@ mod redundant_pattern_match {
19091915 should_be_left : & ' a str ,
19101916 should_be_right : & ' a str ,
19111917 ) -> Option < & ' a str > {
1912- let body_node_pair = if match_qpath ( path_left, expected_left) && match_qpath ( path_right, expected_right) {
1918+ let body_node_pair = if is_qpath_def_path ( cx, path_left, arms[ 0 ] . pat . hir_id , expected_left)
1919+ && is_qpath_def_path ( cx, path_right, arms[ 1 ] . pat . hir_id , expected_right)
1920+ {
19131921 ( & ( * arms[ 0 ] . body ) . kind , & ( * arms[ 1 ] . body ) . kind )
1914- } else if match_qpath ( path_right, expected_left) && match_qpath ( path_left, expected_right) {
1922+ } else if is_qpath_def_path ( cx, path_right, arms[ 1 ] . pat . hir_id , expected_left)
1923+ && is_qpath_def_path ( cx, path_left, arms[ 0 ] . pat . hir_id , expected_right)
1924+ {
19151925 ( & ( * arms[ 1 ] . body ) . kind , & ( * arms[ 0 ] . body ) . kind )
19161926 } else {
19171927 return None ;
0 commit comments