From 058699d0a2fca02127761f014d0ecfce1c5541ec Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 13 Oct 2020 17:58:29 -0400 Subject: [PATCH 1/6] [net] clippy: needless_update warning: struct update has no effect, all the fields in the struct have already been specified --> library/std/src/net/addr.rs:367:19 | 367 | ..unsafe { mem::zeroed() } | ^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::needless_update)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_update --- library/std/src/net/addr.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/library/std/src/net/addr.rs b/library/std/src/net/addr.rs index 63de87128340f..549192c9d30fc 100644 --- a/library/std/src/net/addr.rs +++ b/library/std/src/net/addr.rs @@ -364,7 +364,6 @@ impl SocketAddrV6 { sin6_addr: *ip.as_inner(), sin6_flowinfo: flowinfo, sin6_scope_id: scope_id, - ..unsafe { mem::zeroed() } }, } } From e6dc604e8b184b1224ae7acf58f06fa021ece82c Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 13 Oct 2020 18:00:59 -0400 Subject: [PATCH 2/6] [net] clippy: match_like_matches_macro warning: match expression looks like `matches!` macro --> library/std/src/net/ip.rs:459:9 | 459 | / match self.octets() { 460 | | [169, 254, ..] => true, 461 | | _ => false, 462 | | } | |_________^ help: try this: `matches!(self.octets(), [169, 254, ..])` | = note: `#[warn(clippy::match_like_matches_macro)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro Signed-off-by: wcampbell --- library/std/src/net/ip.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index f01a7b72a6559..4ff12da883236 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -456,10 +456,7 @@ impl Ipv4Addr { #[rustc_const_unstable(feature = "const_ipv4", issue = "76205")] #[stable(since = "1.7.0", feature = "ip_17")] pub const fn is_link_local(&self) -> bool { - match self.octets() { - [169, 254, ..] => true, - _ => false, - } + matches!(self.octets(), [169, 254, ..]) } /// Returns [`true`] if the address appears to be globally routable. From 7a75f4418313da0173192ed4d2f198e505e11428 Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 13 Oct 2020 18:03:27 -0400 Subject: [PATCH 3/6] [net] clippy: identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[0]` --> library/std/src/net/ip.rs:1265:9 | 1265 | (self.segments()[0] & 0xffff) == 0xfe80 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::identity_op)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[1]` --> library/std/src/net/ip.rs:1266:16 | 1266 | && (self.segments()[1] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[2]` --> library/std/src/net/ip.rs:1267:16 | 1267 | && (self.segments()[2] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op warning: the operation is ineffective. Consider reducing it to `self.segments()[3]` --> library/std/src/net/ip.rs:1268:16 | 1268 | && (self.segments()[3] & 0xffff) == 0 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#identity_op Signed-off-by: wcampbell --- library/std/src/net/ip.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 4ff12da883236..6bf71d28bb666 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -1259,10 +1259,10 @@ impl Ipv6Addr { /// [RFC 4291 errata 4406]: https://www.rfc-editor.org/errata/eid4406 #[rustc_const_unstable(feature = "const_ipv6", issue = "76205")] pub const fn is_unicast_link_local_strict(&self) -> bool { - (self.segments()[0] & 0xffff) == 0xfe80 - && (self.segments()[1] & 0xffff) == 0 - && (self.segments()[2] & 0xffff) == 0 - && (self.segments()[3] & 0xffff) == 0 + (self.segments()[0]) == 0xfe80 + && self.segments()[1] == 0 + && self.segments()[2] == 0 + && self.segments()[3] == 0 } /// Returns [`true`] if the address is a unicast link-local address (`fe80::/10`). From 7da0e58da4f1a4a7f102eb5478dbd4e7fa7edbaf Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 13 Oct 2020 19:33:39 -0400 Subject: [PATCH 4/6] use matches! in library/std/src/net/ip.rs Apply suggestion from review Co-authored-by: LingMan --- library/std/src/net/ip.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index 6bf71d28bb666..eb054b081175d 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -1259,10 +1259,7 @@ impl Ipv6Addr { /// [RFC 4291 errata 4406]: https://www.rfc-editor.org/errata/eid4406 #[rustc_const_unstable(feature = "const_ipv6", issue = "76205")] pub const fn is_unicast_link_local_strict(&self) -> bool { - (self.segments()[0]) == 0xfe80 - && self.segments()[1] == 0 - && self.segments()[2] == 0 - && self.segments()[3] == 0 + matches!(self.segments(), [0xfe80, 0, 0, 0, ..]) } /// Returns [`true`] if the address is a unicast link-local address (`fe80::/10`). From ce04836327e6aebab6a834d89e7305d1b1be958b Mon Sep 17 00:00:00 2001 From: wcampbell Date: Tue, 13 Oct 2020 20:11:29 -0400 Subject: [PATCH 5/6] fmt Signed-off-by: wcampbell --- library/std/src/net/ip.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/net/ip.rs b/library/std/src/net/ip.rs index eb054b081175d..8089d7a8ba6f1 100644 --- a/library/std/src/net/ip.rs +++ b/library/std/src/net/ip.rs @@ -1259,7 +1259,7 @@ impl Ipv6Addr { /// [RFC 4291 errata 4406]: https://www.rfc-editor.org/errata/eid4406 #[rustc_const_unstable(feature = "const_ipv6", issue = "76205")] pub const fn is_unicast_link_local_strict(&self) -> bool { - matches!(self.segments(), [0xfe80, 0, 0, 0, ..]) + matches!(self.segments(), [0xfe80, 0, 0, 0, ..]) } /// Returns [`true`] if the address is a unicast link-local address (`fe80::/10`). From 736c27ec0b2cd8c79fedd66e5487b47b8746b7c0 Mon Sep 17 00:00:00 2001 From: wcampbell Date: Mon, 19 Oct 2020 07:22:45 -0400 Subject: [PATCH 6/6] Revert "[net] clippy: needless_update" This reverts commit 058699d0a2fca02127761f014d0ecfce1c5541ec. --- library/std/src/net/addr.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/net/addr.rs b/library/std/src/net/addr.rs index 549192c9d30fc..63de87128340f 100644 --- a/library/std/src/net/addr.rs +++ b/library/std/src/net/addr.rs @@ -364,6 +364,7 @@ impl SocketAddrV6 { sin6_addr: *ip.as_inner(), sin6_flowinfo: flowinfo, sin6_scope_id: scope_id, + ..unsafe { mem::zeroed() } }, } }