-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #6377 - CDirkx:redundant-pattern-match-ipaddr, r=ebroto
Enhance `redundant_pattern_matching` to also lint on `std::net::IpAddr` Follow-up to #6339 r? `@ebroto` (note: also contains a small cleanup of the other ui tests) changelog: Enhance [`redundant_pattern_matching`] to also lint on `std::net::IpAddr`
- Loading branch information
Showing
11 changed files
with
341 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.