about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2020-11-25 02:01:05 +0100
committerChristiaan Dirkx <christiaan@dirkx.email>2020-11-25 02:01:05 +0100
commitdc075b426675e61cc46089046cf41d85edd79aaa (patch)
tree2d91a4c52af11b82953779483727c9ef58a1d4b9
parentf897d27d8b394464048a60e5bf38d4cd1e31a5fe (diff)
downloadrust-dc075b426675e61cc46089046cf41d85edd79aaa.tar.gz
rust-dc075b426675e61cc46089046cf41d85edd79aaa.zip
Change `redundant_pattern_matching` to also lint `std::net::IpAddr`
Suggest using utility methods `is_ipv4` and `is_ipv6`.
-rw-r--r--clippy_lints/src/matches.rs25
-rw-r--r--clippy_lints/src/utils/paths.rs2
-rw-r--r--tests/ui/redundant_pattern_matching_ipaddr.fixed73
-rw-r--r--tests/ui/redundant_pattern_matching_ipaddr.rs91
-rw-r--r--tests/ui/redundant_pattern_matching_ipaddr.stderr130
-rw-r--r--tests/ui/redundant_pattern_matching_option.fixed5
-rw-r--r--tests/ui/redundant_pattern_matching_option.rs5
-rw-r--r--tests/ui/redundant_pattern_matching_option.stderr18
-rw-r--r--tests/ui/redundant_pattern_matching_poll.fixed5
-rw-r--r--tests/ui/redundant_pattern_matching_poll.rs5
-rw-r--r--tests/ui/redundant_pattern_matching_poll.stderr18
11 files changed, 341 insertions, 36 deletions
diff --git a/clippy_lints/src/matches.rs b/clippy_lints/src/matches.rs
index af59917e801..a14b63faf78 100644
--- a/clippy_lints/src/matches.rs
+++ b/clippy_lints/src/matches.rs
@@ -411,8 +411,8 @@ declare_clippy_lint! {
 }
 
 declare_clippy_lint! {
-    /// **What it does:** Lint for redundant pattern matching over `Result`, `Option` or
-    /// `std::task::Poll`
+    /// **What it does:** Lint for redundant pattern matching over `Result`, `Option`,
+    /// `std::task::Poll` or `std::net::IpAddr`
     ///
     /// **Why is this bad?** It's more concise and clear to just use the proper
     /// utility function
@@ -423,12 +423,15 @@ declare_clippy_lint! {
     ///
     /// ```rust
     /// # use std::task::Poll;
+    /// # use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
     /// if let Ok(_) = Ok::<i32, i32>(42) {}
     /// if let Err(_) = Err::<i32, i32>(42) {}
     /// if let None = None::<()> {}
     /// if let Some(_) = Some(42) {}
     /// if let Poll::Pending = Poll::Pending::<()> {}
     /// if let Poll::Ready(_) = Poll::Ready(42) {}
+    /// if let IpAddr::V4(_) = IpAddr::V4(Ipv4Addr::LOCALHOST) {}
+    /// if let IpAddr::V6(_) = IpAddr::V6(Ipv6Addr::LOCALHOST) {}
     /// match Ok::<i32, i32>(42) {
     ///     Ok(_) => true,
     ///     Err(_) => false,
@@ -439,12 +442,15 @@ declare_clippy_lint! {
     ///
     /// ```rust
     /// # use std::task::Poll;
+    /// # use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
     /// if Ok::<i32, i32>(42).is_ok() {}
     /// if Err::<i32, i32>(42).is_err() {}
     /// if None::<()>.is_none() {}
     /// if Some(42).is_some() {}
     /// if Poll::Pending::<()>.is_pending() {}
     /// if Poll::Ready(42).is_ready() {}
+    /// if IpAddr::V4(Ipv4Addr::LOCALHOST).is_ipv4() {}
+    /// if IpAddr::V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
     /// Ok::<i32, i32>(42).is_ok();
     /// ```
     pub REDUNDANT_PATTERN_MATCHING,
@@ -1546,6 +1552,10 @@ mod redundant_pattern_match {
                         "is_some()"
                     } else if match_qpath(path, &paths::POLL_READY) {
                         "is_ready()"
+                    } else if match_qpath(path, &paths::IPADDR_V4) {
+                        "is_ipv4()"
+                    } else if match_qpath(path, &paths::IPADDR_V6) {
+                        "is_ipv6()"
                     } else {
                         return;
                     }
@@ -1626,6 +1636,17 @@ mod redundant_pattern_match {
                             "is_ok()",
                             "is_err()",
                         )
+                        .or_else(|| {
+                            find_good_method_for_match(
+                                arms,
+                                path_left,
+                                path_right,
+                                &paths::IPADDR_V4,
+                                &paths::IPADDR_V6,
+                                "is_ipv4()",
+                                "is_ipv6()",
+                            )
+                        })
                     } else {
                         None
                     }
diff --git a/clippy_lints/src/utils/paths.rs b/clippy_lints/src/utils/paths.rs
index 829e9a2989c..61aeabb7ba7 100644
--- a/clippy_lints/src/utils/paths.rs
+++ b/clippy_lints/src/utils/paths.rs
@@ -58,6 +58,8 @@ pub const INTO: [&str; 3] = ["core", "convert", "Into"];
 pub const INTO_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "IntoIterator"];
 pub const IO_READ: [&str; 3] = ["std", "io", "Read"];
 pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"];
+pub const IPADDR_V4: [&str; 4] = ["std", "net", "IpAddr", "V4"];
+pub const IPADDR_V6: [&str; 4] = ["std", "net", "IpAddr", "V6"];
 pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator"];
 pub const LATE_CONTEXT: [&str; 2] = ["rustc_lint", "LateContext"];
 pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
diff --git a/tests/ui/redundant_pattern_matching_ipaddr.fixed b/tests/ui/redundant_pattern_matching_ipaddr.fixed
new file mode 100644
index 00000000000..acc8de5f41e
--- /dev/null
+++ b/tests/ui/redundant_pattern_matching_ipaddr.fixed
@@ -0,0 +1,73 @@
+// run-rustfix
+
+#![warn(clippy::all)]
+#![warn(clippy::redundant_pattern_matching)]
+#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
+
+use std::net::{
+    IpAddr::{self, V4, V6},
+    Ipv4Addr, Ipv6Addr,
+};
+
+fn main() {
+    let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST);
+    if ipaddr.is_ipv4() {}
+
+    if V4(Ipv4Addr::LOCALHOST).is_ipv4() {}
+
+    if V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
+
+    while V4(Ipv4Addr::LOCALHOST).is_ipv4() {}
+
+    while V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
+
+    if V4(Ipv4Addr::LOCALHOST).is_ipv4() {}
+
+    if V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
+
+    if let V4(ipaddr) = V4(Ipv4Addr::LOCALHOST) {
+        println!("{}", ipaddr);
+    }
+
+    V4(Ipv4Addr::LOCALHOST).is_ipv4();
+
+    V4(Ipv4Addr::LOCALHOST).is_ipv6();
+
+    V6(Ipv6Addr::LOCALHOST).is_ipv6();
+
+    V6(Ipv6Addr::LOCALHOST).is_ipv4();
+
+    let _ = if V4(Ipv4Addr::LOCALHOST).is_ipv4() {
+        true
+    } else {
+        false
+    };
+
+    ipaddr_const();
+
+    let _ = if gen_ipaddr().is_ipv4() {
+        1
+    } else if gen_ipaddr().is_ipv6() {
+        2
+    } else {
+        3
+    };
+}
+
+fn gen_ipaddr() -> IpAddr {
+    V4(Ipv4Addr::LOCALHOST)
+}
+
+const fn ipaddr_const() {
+    if V4(Ipv4Addr::LOCALHOST).is_ipv4() {}
+
+    if V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
+
+    while V4(Ipv4Addr::LOCALHOST).is_ipv4() {}
+
+    while V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
+
+    V4(Ipv4Addr::LOCALHOST).is_ipv4();
+
+    V6(Ipv6Addr::LOCALHOST).is_ipv6();
+}
diff --git a/tests/ui/redundant_pattern_matching_ipaddr.rs b/tests/ui/redundant_pattern_matching_ipaddr.rs
new file mode 100644
index 00000000000..678d91ce93a
--- /dev/null
+++ b/tests/ui/redundant_pattern_matching_ipaddr.rs
@@ -0,0 +1,91 @@
+// run-rustfix
+
+#![warn(clippy::all)]
+#![warn(clippy::redundant_pattern_matching)]
+#![allow(unused_must_use, clippy::needless_bool, clippy::match_like_matches_macro)]
+
+use std::net::{
+    IpAddr::{self, V4, V6},
+    Ipv4Addr, Ipv6Addr,
+};
+
+fn main() {
+    let ipaddr: IpAddr = V4(Ipv4Addr::LOCALHOST);
+    if let V4(_) = &ipaddr {}
+
+    if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+
+    if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+
+    while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+
+    while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+
+    if V4(Ipv4Addr::LOCALHOST).is_ipv4() {}
+
+    if V6(Ipv6Addr::LOCALHOST).is_ipv6() {}
+
+    if let V4(ipaddr) = V4(Ipv4Addr::LOCALHOST) {
+        println!("{}", ipaddr);
+    }
+
+    match V4(Ipv4Addr::LOCALHOST) {
+        V4(_) => true,
+        V6(_) => false,
+    };
+
+    match V4(Ipv4Addr::LOCALHOST) {
+        V4(_) => false,
+        V6(_) => true,
+    };
+
+    match V6(Ipv6Addr::LOCALHOST) {
+        V4(_) => false,
+        V6(_) => true,
+    };
+
+    match V6(Ipv6Addr::LOCALHOST) {
+        V4(_) => true,
+        V6(_) => false,
+    };
+
+    let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) {
+        true
+    } else {
+        false
+    };
+
+    ipaddr_const();
+
+    let _ = if let V4(_) = gen_ipaddr() {
+        1
+    } else if let V6(_) = gen_ipaddr() {
+        2
+    } else {
+        3
+    };
+}
+
+fn gen_ipaddr() -> IpAddr {
+    V4(Ipv4Addr::LOCALHOST)
+}
+
+const fn ipaddr_const() {
+    if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+
+    if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+
+    while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+
+    while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+
+    match V4(Ipv4Addr::LOCALHOST) {
+        V4(_) => true,
+        V6(_) => false,
+    };
+
+    match V6(Ipv6Addr::LOCALHOST) {
+        V4(_) => false,
+        V6(_) => true,
+    };
+}
diff --git a/tests/ui/redundant_pattern_matching_ipaddr.stderr b/tests/ui/redundant_pattern_matching_ipaddr.stderr
new file mode 100644
index 00000000000..caf458cd862
--- /dev/null
+++ b/tests/ui/redundant_pattern_matching_ipaddr.stderr
@@ -0,0 +1,130 @@
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:14:12
+   |
+LL |     if let V4(_) = &ipaddr {}
+   |     -------^^^^^---------- help: try this: `if ipaddr.is_ipv4()`
+   |
+   = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:16:12
+   |
+LL |     if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+   |     -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:18:12
+   |
+LL |     if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+   |     -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:20:15
+   |
+LL |     while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+   |     ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:22:15
+   |
+LL |     while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+   |     ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:32:5
+   |
+LL | /     match V4(Ipv4Addr::LOCALHOST) {
+LL | |         V4(_) => true,
+LL | |         V6(_) => false,
+LL | |     };
+   | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:37:5
+   |
+LL | /     match V4(Ipv4Addr::LOCALHOST) {
+LL | |         V4(_) => false,
+LL | |         V6(_) => true,
+LL | |     };
+   | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv6()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:42:5
+   |
+LL | /     match V6(Ipv6Addr::LOCALHOST) {
+LL | |         V4(_) => false,
+LL | |         V6(_) => true,
+LL | |     };
+   | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:47:5
+   |
+LL | /     match V6(Ipv6Addr::LOCALHOST) {
+LL | |         V4(_) => true,
+LL | |         V6(_) => false,
+LL | |     };
+   | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:52:20
+   |
+LL |     let _ = if let V4(_) = V4(Ipv4Addr::LOCALHOST) {
+   |             -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:60:20
+   |
+LL |     let _ = if let V4(_) = gen_ipaddr() {
+   |             -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:62:19
+   |
+LL |     } else if let V6(_) = gen_ipaddr() {
+   |            -------^^^^^--------------- help: try this: `if gen_ipaddr().is_ipv6()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:74:12
+   |
+LL |     if let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+   |     -------^^^^^-------------------------- help: try this: `if V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:76:12
+   |
+LL |     if let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+   |     -------^^^^^-------------------------- help: try this: `if V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:78:15
+   |
+LL |     while let V4(_) = V4(Ipv4Addr::LOCALHOST) {}
+   |     ----------^^^^^-------------------------- help: try this: `while V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:80:15
+   |
+LL |     while let V6(_) = V6(Ipv6Addr::LOCALHOST) {}
+   |     ----------^^^^^-------------------------- help: try this: `while V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+
+error: redundant pattern matching, consider using `is_ipv4()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:82:5
+   |
+LL | /     match V4(Ipv4Addr::LOCALHOST) {
+LL | |         V4(_) => true,
+LL | |         V6(_) => false,
+LL | |     };
+   | |_____^ help: try this: `V4(Ipv4Addr::LOCALHOST).is_ipv4()`
+
+error: redundant pattern matching, consider using `is_ipv6()`
+  --> $DIR/redundant_pattern_matching_ipaddr.rs:87:5
+   |
+LL | /     match V6(Ipv6Addr::LOCALHOST) {
+LL | |         V4(_) => false,
+LL | |         V6(_) => true,
+LL | |     };
+   | |_____^ help: try this: `V6(Ipv6Addr::LOCALHOST).is_ipv6()`
+
+error: aborting due to 18 previous errors
+
diff --git a/tests/ui/redundant_pattern_matching_option.fixed b/tests/ui/redundant_pattern_matching_option.fixed
index bc369dd2491..66f580a0a68 100644
--- a/tests/ui/redundant_pattern_matching_option.fixed
+++ b/tests/ui/redundant_pattern_matching_option.fixed
@@ -37,8 +37,7 @@ fn main() {
     let _ = None::<()>.is_none();
 
     let opt = Some(false);
-    let x = if opt.is_some() { true } else { false };
-    takes_bool(x);
+    let _ = if opt.is_some() { true } else { false };
 
     issue6067();
 
@@ -55,8 +54,6 @@ fn gen_opt() -> Option<()> {
     None
 }
 
-fn takes_bool(_: bool) {}
-
 fn foo() {}
 
 fn bar() {}
diff --git a/tests/ui/redundant_pattern_matching_option.rs b/tests/ui/redundant_pattern_matching_option.rs
index d7616a72913..f18b27b8b95 100644
--- a/tests/ui/redundant_pattern_matching_option.rs
+++ b/tests/ui/redundant_pattern_matching_option.rs
@@ -46,8 +46,7 @@ fn main() {
     };
 
     let opt = Some(false);
-    let x = if let Some(_) = opt { true } else { false };
-    takes_bool(x);
+    let _ = if let Some(_) = opt { true } else { false };
 
     issue6067();
 
@@ -64,8 +63,6 @@ fn gen_opt() -> Option<()> {
     None
 }
 
-fn takes_bool(_: bool) {}
-
 fn foo() {}
 
 fn bar() {}
diff --git a/tests/ui/redundant_pattern_matching_option.stderr b/tests/ui/redundant_pattern_matching_option.stderr
index 7ddfbe503a2..58482a0ab70 100644
--- a/tests/ui/redundant_pattern_matching_option.stderr
+++ b/tests/ui/redundant_pattern_matching_option.stderr
@@ -73,47 +73,47 @@ LL | |     };
 error: redundant pattern matching, consider using `is_some()`
   --> $DIR/redundant_pattern_matching_option.rs:49:20
    |
-LL |     let x = if let Some(_) = opt { true } else { false };
+LL |     let _ = if let Some(_) = opt { true } else { false };
    |             -------^^^^^^^------ help: try this: `if opt.is_some()`
 
 error: redundant pattern matching, consider using `is_some()`
-  --> $DIR/redundant_pattern_matching_option.rs:54:20
+  --> $DIR/redundant_pattern_matching_option.rs:53:20
    |
 LL |     let _ = if let Some(_) = gen_opt() {
    |             -------^^^^^^^------------ help: try this: `if gen_opt().is_some()`
 
 error: redundant pattern matching, consider using `is_none()`
-  --> $DIR/redundant_pattern_matching_option.rs:56:19
+  --> $DIR/redundant_pattern_matching_option.rs:55:19
    |
 LL |     } else if let None = gen_opt() {
    |            -------^^^^------------ help: try this: `if gen_opt().is_none()`
 
 error: redundant pattern matching, consider using `is_some()`
-  --> $DIR/redundant_pattern_matching_option.rs:77:12
+  --> $DIR/redundant_pattern_matching_option.rs:74:12
    |
 LL |     if let Some(_) = Some(42) {}
    |     -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
 
 error: redundant pattern matching, consider using `is_none()`
-  --> $DIR/redundant_pattern_matching_option.rs:79:12
+  --> $DIR/redundant_pattern_matching_option.rs:76:12
    |
 LL |     if let None = None::<()> {}
    |     -------^^^^------------- help: try this: `if None::<()>.is_none()`
 
 error: redundant pattern matching, consider using `is_some()`
-  --> $DIR/redundant_pattern_matching_option.rs:81:15
+  --> $DIR/redundant_pattern_matching_option.rs:78:15
    |
 LL |     while let Some(_) = Some(42) {}
    |     ----------^^^^^^^----------- help: try this: `while Some(42).is_some()`
 
 error: redundant pattern matching, consider using `is_none()`
-  --> $DIR/redundant_pattern_matching_option.rs:83:15
+  --> $DIR/redundant_pattern_matching_option.rs:80:15
    |
 LL |     while let None = None::<()> {}
    |     ----------^^^^------------- help: try this: `while None::<()>.is_none()`
 
 error: redundant pattern matching, consider using `is_some()`
-  --> $DIR/redundant_pattern_matching_option.rs:85:5
+  --> $DIR/redundant_pattern_matching_option.rs:82:5
    |
 LL | /     match Some(42) {
 LL | |         Some(_) => true,
@@ -122,7 +122,7 @@ LL | |     };
    | |_____^ help: try this: `Some(42).is_some()`
 
 error: redundant pattern matching, consider using `is_none()`
-  --> $DIR/redundant_pattern_matching_option.rs:90:5
+  --> $DIR/redundant_pattern_matching_option.rs:87:5
    |
 LL | /     match None::<()> {
 LL | |         Some(_) => false,
diff --git a/tests/ui/redundant_pattern_matching_poll.fixed b/tests/ui/redundant_pattern_matching_poll.fixed
index 564c427f063..465aa80dac2 100644
--- a/tests/ui/redundant_pattern_matching_poll.fixed
+++ b/tests/ui/redundant_pattern_matching_poll.fixed
@@ -34,8 +34,7 @@ fn main() {
     let _ = Pending::<()>.is_pending();
 
     let poll = Ready(false);
-    let x = if poll.is_ready() { true } else { false };
-    takes_poll(x);
+    let _ = if poll.is_ready() { true } else { false };
 
     poll_const();
 
@@ -52,8 +51,6 @@ fn gen_poll() -> Poll<()> {
     Pending
 }
 
-fn takes_poll(_: bool) {}
-
 fn foo() {}
 
 fn bar() {}
diff --git a/tests/ui/redundant_pattern_matching_poll.rs b/tests/ui/redundant_pattern_matching_poll.rs
index d453d4184af..7891ff353b1 100644
--- a/tests/ui/redundant_pattern_matching_poll.rs
+++ b/tests/ui/redundant_pattern_matching_poll.rs
@@ -43,8 +43,7 @@ fn main() {
     };
 
     let poll = Ready(false);
-    let x = if let Ready(_) = poll { true } else { false };
-    takes_poll(x);
+    let _ = if let Ready(_) = poll { true } else { false };
 
     poll_const();
 
@@ -61,8 +60,6 @@ fn gen_poll() -> Poll<()> {
     Pending
 }
 
-fn takes_poll(_: bool) {}
-
 fn foo() {}
 
 fn bar() {}
diff --git a/tests/ui/redundant_pattern_matching_poll.stderr b/tests/ui/redundant_pattern_matching_poll.stderr
index 42e5d6f41fe..5ffc6c47c90 100644
--- a/tests/ui/redundant_pattern_matching_poll.stderr
+++ b/tests/ui/redundant_pattern_matching_poll.stderr
@@ -67,47 +67,47 @@ LL | |     };
 error: redundant pattern matching, consider using `is_ready()`
   --> $DIR/redundant_pattern_matching_poll.rs:46:20
    |
-LL |     let x = if let Ready(_) = poll { true } else { false };
+LL |     let _ = if let Ready(_) = poll { true } else { false };
    |             -------^^^^^^^^------- help: try this: `if poll.is_ready()`
 
 error: redundant pattern matching, consider using `is_ready()`
-  --> $DIR/redundant_pattern_matching_poll.rs:51:20
+  --> $DIR/redundant_pattern_matching_poll.rs:50:20
    |
 LL |     let _ = if let Ready(_) = gen_poll() {
    |             -------^^^^^^^^------------- help: try this: `if gen_poll().is_ready()`
 
 error: redundant pattern matching, consider using `is_pending()`
-  --> $DIR/redundant_pattern_matching_poll.rs:53:19
+  --> $DIR/redundant_pattern_matching_poll.rs:52:19
    |
 LL |     } else if let Pending = gen_poll() {
    |            -------^^^^^^^------------- help: try this: `if gen_poll().is_pending()`
 
 error: redundant pattern matching, consider using `is_ready()`
-  --> $DIR/redundant_pattern_matching_poll.rs:71:12
+  --> $DIR/redundant_pattern_matching_poll.rs:68:12
    |
 LL |     if let Ready(_) = Ready(42) {}
    |     -------^^^^^^^^------------ help: try this: `if Ready(42).is_ready()`
 
 error: redundant pattern matching, consider using `is_pending()`
-  --> $DIR/redundant_pattern_matching_poll.rs:73:12
+  --> $DIR/redundant_pattern_matching_poll.rs:70:12
    |
 LL |     if let Pending = Pending::<()> {}
    |     -------^^^^^^^---------------- help: try this: `if Pending::<()>.is_pending()`
 
 error: redundant pattern matching, consider using `is_ready()`
-  --> $DIR/redundant_pattern_matching_poll.rs:75:15
+  --> $DIR/redundant_pattern_matching_poll.rs:72:15
    |
 LL |     while let Ready(_) = Ready(42) {}
    |     ----------^^^^^^^^------------ help: try this: `while Ready(42).is_ready()`
 
 error: redundant pattern matching, consider using `is_pending()`
-  --> $DIR/redundant_pattern_matching_poll.rs:77:15
+  --> $DIR/redundant_pattern_matching_poll.rs:74:15
    |
 LL |     while let Pending = Pending::<()> {}
    |     ----------^^^^^^^---------------- help: try this: `while Pending::<()>.is_pending()`
 
 error: redundant pattern matching, consider using `is_ready()`
-  --> $DIR/redundant_pattern_matching_poll.rs:79:5
+  --> $DIR/redundant_pattern_matching_poll.rs:76:5
    |
 LL | /     match Ready(42) {
 LL | |         Ready(_) => true,
@@ -116,7 +116,7 @@ LL | |     };
    | |_____^ help: try this: `Ready(42).is_ready()`
 
 error: redundant pattern matching, consider using `is_pending()`
-  --> $DIR/redundant_pattern_matching_poll.rs:84:5
+  --> $DIR/redundant_pattern_matching_poll.rs:81:5
    |
 LL | /     match Pending::<()> {
 LL | |         Ready(_) => false,