@@ -1701,7 +1701,7 @@ mod redundant_pattern_match {
1701
1701
use super :: REDUNDANT_PATTERN_MATCHING ;
1702
1702
use clippy_utils:: diagnostics:: span_lint_and_then;
1703
1703
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} ;
1705
1705
use if_chain:: if_chain;
1706
1706
use rustc_ast:: ast:: LitKind ;
1707
1707
use rustc_errors:: Applicability ;
@@ -1735,8 +1735,8 @@ mod redundant_pattern_match {
1735
1735
kind = & inner. kind ;
1736
1736
}
1737
1737
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 {
1740
1740
if is_lang_ctor ( cx, path, ResultOk ) {
1741
1741
"is_ok()"
1742
1742
} else if is_lang_ctor ( cx, path, ResultErr ) {
@@ -1745,9 +1745,9 @@ mod redundant_pattern_match {
1745
1745
"is_some()"
1746
1746
} else if is_lang_ctor ( cx, path, PollReady ) {
1747
1747
"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 ) {
1749
1749
"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 ) {
1751
1751
"is_ipv6()"
1752
1752
} else {
1753
1753
return ;
@@ -1821,6 +1821,7 @@ mod redundant_pattern_match {
1821
1821
) if patterns_left. len ( ) == 1 && patterns_right. len ( ) == 1 => {
1822
1822
if let ( PatKind :: Wild , PatKind :: Wild ) = ( & patterns_left[ 0 ] . kind , & patterns_right[ 0 ] . kind ) {
1823
1823
find_good_method_for_match (
1824
+ cx,
1824
1825
arms,
1825
1826
path_left,
1826
1827
path_right,
@@ -1831,6 +1832,7 @@ mod redundant_pattern_match {
1831
1832
)
1832
1833
. or_else ( || {
1833
1834
find_good_method_for_match (
1835
+ cx,
1834
1836
arms,
1835
1837
path_left,
1836
1838
path_right,
@@ -1850,6 +1852,7 @@ mod redundant_pattern_match {
1850
1852
{
1851
1853
if let PatKind :: Wild = patterns[ 0 ] . kind {
1852
1854
find_good_method_for_match (
1855
+ cx,
1853
1856
arms,
1854
1857
path_left,
1855
1858
path_right,
@@ -1860,6 +1863,7 @@ mod redundant_pattern_match {
1860
1863
)
1861
1864
. or_else ( || {
1862
1865
find_good_method_for_match (
1866
+ cx,
1863
1867
arms,
1864
1868
path_left,
1865
1869
path_right,
@@ -1900,7 +1904,9 @@ mod redundant_pattern_match {
1900
1904
}
1901
1905
}
1902
1906
1907
+ #[ allow( clippy:: too_many_arguments) ]
1903
1908
fn find_good_method_for_match < ' a > (
1909
+ cx : & LateContext < ' _ > ,
1904
1910
arms : & [ Arm < ' _ > ] ,
1905
1911
path_left : & QPath < ' _ > ,
1906
1912
path_right : & QPath < ' _ > ,
@@ -1909,9 +1915,13 @@ mod redundant_pattern_match {
1909
1915
should_be_left : & ' a str ,
1910
1916
should_be_right : & ' a str ,
1911
1917
) -> 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
+ {
1913
1921
( & ( * 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
+ {
1915
1925
( & ( * arms[ 1 ] . body ) . kind , & ( * arms[ 0 ] . body ) . kind )
1916
1926
} else {
1917
1927
return None ;
0 commit comments