From 781cbab4a43e4804a0a68bfc9d2c3ece7f99a081 Mon Sep 17 00:00:00 2001 From: Hyeon Kim Date: Mon, 15 Nov 2021 04:44:48 +0900 Subject: [PATCH] Fix all trivial clippy warnings using `cargo clippy --fix` --- src/client/conn.rs | 10 +++++----- src/client/data/config.rs | 26 +++++++++++--------------- src/client/data/user.rs | 6 +++--- src/client/mod.rs | 19 ++++++++----------- src/client/transport.rs | 8 +++----- 5 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/client/conn.rs b/src/client/conn.rs index 403c18a..a90f2b8 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -156,7 +156,7 @@ impl Connection { let stream = Self::new_stream(config).await?; let framed = Framed::new(stream, IrcCodec::new(config.encoding())?); - Ok(Transport::new(&config, framed, tx)) + Ok(Transport::new(config, framed, tx)) } #[cfg(all(feature = "tls-native", not(feature = "tls-rust")))] @@ -188,7 +188,7 @@ impl Connection { let mut client_cert_data = vec![]; file.read_to_end(&mut client_cert_data)?; let client_cert_pass = config.client_cert_pass(); - let pkcs12_archive = Identity::from_pkcs12(&client_cert_data, &client_cert_pass)?; + let pkcs12_archive = Identity::from_pkcs12(&client_cert_data, client_cert_pass)?; builder.identity(pkcs12_archive); log::info!( "Using {} for client certificate authentication.", @@ -215,7 +215,7 @@ impl Connection { let stream = connector.connect(domain, stream).await?; let framed = Framed::new(stream, IrcCodec::new(config.encoding())?); - Ok(Transport::new(&config, framed, tx)) + Ok(Transport::new(config, framed, tx)) } #[cfg(feature = "tls-rust")] @@ -337,7 +337,7 @@ impl Connection { let stream = connector.connect(domain, stream).await?; let framed = Framed::new(stream, IrcCodec::new(config.encoding())?); - Ok(Transport::new(&config, framed, tx)) + Ok(Transport::new(config, framed, tx)) } async fn new_mocked_transport( @@ -363,7 +363,7 @@ impl Connection { let stream = MockStream::new(&initial); let framed = Framed::new(stream, IrcCodec::new(config.encoding())?); - Ok(Transport::new(&config, framed, tx)) + Ok(Transport::new(config, framed, tx)) } /// Gets a view of the internal logging if and only if this connection is using a mock stream. diff --git a/src/client/data/config.rs b/src/client/data/config.rs index ff98d85..03546e4 100644 --- a/src/client/data/config.rs +++ b/src/client/data/config.rs @@ -394,14 +394,12 @@ impl Config { /// Determines whether or not the nickname provided is the owner of the bot. pub fn is_owner(&self, nickname: &str) -> bool { - self.owners.iter().find(|n| *n == nickname).is_some() + self.owners.iter().any(|n| n == nickname) } /// Gets the nickname specified in the configuration. pub fn nickname(&self) -> Result<&str> { - self.nickname - .as_ref() - .map(String::as_str) + self.nickname.as_deref() .ok_or_else(|| InvalidConfig { path: self.path(), cause: ConfigError::NicknameNotSpecified, @@ -425,7 +423,7 @@ impl Config { pub fn username(&self) -> &str { self.username .as_ref() - .map_or(self.nickname().unwrap_or("user"), |s| &s) + .map_or(self.nickname().unwrap_or("user"), |s| s) } /// Gets the real name specified in the configuration. @@ -433,14 +431,12 @@ impl Config { pub fn real_name(&self) -> &str { self.realname .as_ref() - .map_or(self.nickname().unwrap_or("irc"), |s| &s) + .map_or(self.nickname().unwrap_or("irc"), |s| s) } /// Gets the address of the server specified in the configuration. pub fn server(&self) -> Result<&str> { - self.server - .as_ref() - .map(String::as_str) + self.server.as_deref() .ok_or_else(|| InvalidConfig { path: self.path(), cause: ConfigError::ServerNotSpecified, @@ -517,7 +513,7 @@ impl Config { /// Gets the path to the TLS certificate in DER format if specified. #[cfg(any(feature = "tls-native", feature = "tls-rust"))] pub fn cert_path(&self) -> Option<&str> { - self.cert_path.as_ref().map(String::as_str) + self.cert_path.as_deref() } /// Gets whether or not to dangerously accept invalid certificates. @@ -532,7 +528,7 @@ impl Config { /// Gets the path to the client authentication certificate in DER format if specified. #[cfg(any(feature = "tls-native", feature = "tls-rust"))] pub fn client_cert_path(&self) -> Option<&str> { - self.client_cert_path.as_ref().map(String::as_str) + self.client_cert_path.as_deref() } /// Gets the password to the client authentication certificate. @@ -544,7 +540,7 @@ impl Config { /// Gets the encoding to use for this connection. This requires the encode feature to work. /// This defaults to UTF-8 when not specified. pub fn encoding(&self) -> &str { - self.encoding.as_ref().map_or("UTF-8", |s| &s) + self.encoding.as_ref().map_or("UTF-8", |s| s) } /// Gets the channels to join upon connection. @@ -574,7 +570,7 @@ impl Config { /// This defaults to `irc:version:env` when not specified. /// For example, `irc:0.12.0:Compiled with rustc` pub fn version(&self) -> &str { - self.version.as_ref().map_or(crate::VERSION_STR, |s| &s) + self.version.as_ref().map_or(crate::VERSION_STR, |s| s) } /// Gets the string to be sent in response to CTCP SOURCE requests. @@ -624,7 +620,7 @@ impl Config { /// Gets the NickServ command sequence to recover a nickname. /// This defaults to `["GHOST"]` when not specified. pub fn ghost_sequence(&self) -> Option<&[String]> { - self.ghost_sequence.as_ref().map(Vec::as_slice) + self.ghost_sequence.as_deref() } /// Looks up the specified string in the options map. @@ -642,7 +638,7 @@ impl Config { /// This defaults to false when not specified. /// This has no effect if `use_mock_connection` is not `true`. pub fn mock_initial_value(&self) -> &str { - self.mock_initial_value.as_ref().map_or("", |s| &s) + self.mock_initial_value.as_ref().map_or("", |s| s) } } diff --git a/src/client/data/user.rs b/src/client/data/user.rs index 5d6c06c..c25b51d 100644 --- a/src/client/data/user.rs +++ b/src/client/data/user.rs @@ -31,9 +31,9 @@ impl User { let username = state.find('@').map(|i| state[..i].to_owned()); let hostname = state.find('@').map(|i| state[i + 1..].to_owned()); User { - nickname: nickname, - username: username, - hostname: hostname, + nickname, + username, + hostname, access_levels: { let mut ranks = ranks.clone(); ranks.push(AccessLevel::Member); diff --git a/src/client/mod.rs b/src/client/mod.rs index 384af54..ef26081 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -487,7 +487,7 @@ impl Stream for ClientStream { match ready!(Pin::new(&mut self.as_mut().stream).poll_next(cx)) { Some(Ok(msg)) => { self.state.handle_message(&msg)?; - return Poll::Ready(Some(Ok(msg))); + Poll::Ready(Some(Ok(msg))) } other => Poll::Ready(other), } @@ -526,7 +526,7 @@ impl ClientState { fn send>(&self, msg: M) -> error::Result<()> { let msg = msg.into(); self.handle_sent_message(&msg)?; - Ok(self.sender.send(msg)?) + self.sender.send(msg) } /// Gets the current nickname in use. @@ -547,11 +547,8 @@ impl ClientState { fn handle_sent_message(&self, msg: &Message) -> error::Result<()> { log::trace!("[SENT] {}", msg.to_string()); - match msg.command { - PART(ref chan, _) => { - let _ = self.chanlists.write().remove(chan); - } - _ => (), + if let PART(ref chan, _) = msg.command { + let _ = self.chanlists.write().remove(chan); } Ok(()) @@ -602,7 +599,7 @@ impl ClientState { let joined_chans = self.chanlists.read(); for chan in joined_chans .keys() - .filter(|x| config_chans.iter().find(|c| c == x).is_none()) + .filter(|x| !config_chans.iter().any(|c| c == *x)) { self.send_join(chan)? } @@ -805,7 +802,7 @@ impl ClientState { #[cfg(feature = "ctcp")] fn send_ctcp_internal(&self, target: &str, msg: &str) -> error::Result<()> { - self.send_notice(target, &format!("\u{001}{}\u{001}", msg)) + self.send_notice(target, format!("\u{001}{}\u{001}", msg)) } #[cfg(not(feature = "ctcp"))] @@ -993,7 +990,7 @@ impl Client { let stream = self .incoming .take() - .ok_or_else(|| error::Error::StreamAlreadyConfigured)?; + .ok_or(error::Error::StreamAlreadyConfigured)?; Ok(ClientStream { state: Arc::clone(&self.state), @@ -1308,7 +1305,7 @@ mod test { .await?; let res = client.stream()?.try_collect::>().await; if let Err(Error::NoUsableNick) = res { - () + } else { panic!("expected error when no valid nicks were specified") } diff --git a/src/client/transport.rs b/src/client/transport.rs index df39488..7f7965c 100644 --- a/src/client/transport.rs +++ b/src/client/transport.rs @@ -96,7 +96,7 @@ impl Pinger { let mut this = self.project(); - this.tx.send(Command::PING(data.clone(), None).into())?; + this.tx.send(Command::PING(data, None).into())?; if this.ping_deadline.is_none() { let ping_deadline = time::sleep(*this.ping_timeout); @@ -118,10 +118,8 @@ impl Future for Pinger { } } - if let Poll::Ready(_) = self.as_mut().project().ping_interval.poll_tick(cx) { - if *self.as_mut().project().enabled { - self.as_mut().send_ping()?; - } + if self.as_mut().project().ping_interval.poll_tick(cx).is_ready() && *self.as_mut().project().enabled { + self.as_mut().send_ping()?; } Poll::Pending