Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clippy warnings #122

Merged
merged 3 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client_listener/examples/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async fn do_restart(
) -> ! {
let data = SaveData {
listeners: listeners.save().await.unwrap(),
connections: connections.into_iter().map(|(_, c)| c.save()).collect(),
connections: connections.into_values().map(|c| c.save()).collect(),
};
let fd = to_memfd(data).unwrap();

Expand Down
13 changes: 8 additions & 5 deletions client_listener/src/internal/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::internal::*;
use crate::*;

use sha1::{Digest, Sha1};
use std::{convert::TryInto, net::IpAddr};
use std::net::IpAddr;
use tokio::{
io::AsyncWriteExt,
net::TcpStream,
Expand Down Expand Up @@ -44,12 +44,11 @@ impl InternalConnection {
.get_ref()
.1
.peer_certificates()
.map(|c| c.get(0))
.flatten()
.and_then(|c| c.first())
.map(|cert| {
let mut hasher = Sha1::new();
hasher.update(&cert.0);
hex::encode(hasher.finalize()).as_str().try_into().unwrap()
hex::encode(hasher.finalize()).as_str().into()
});

tls_info = Some(TlsInfo { fingerprint });
Expand Down Expand Up @@ -80,7 +79,11 @@ impl InternalConnection {
tls_info,
};

if let Err(_) = events.send(InternalConnectionEventType::New(conn)).await {
if events
.send(InternalConnectionEventType::New(conn))
.await
.is_err()
{
tracing::error!("Error sending new connection");
};

Expand Down
5 changes: 1 addition & 4 deletions sable_ipc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,10 @@ pub struct Receiver<T: DeserializeOwned> {

impl<T: DeserializeOwned> Receiver<T> {
fn new(socket: UnixDatagram, max_len: u64) -> Self {
let mut recv_buf = Vec::new();
recv_buf.resize(max_len as usize, 0u8);

Self {
socket: Some(socket),
max_len,
recv_buffer: Mutex::new(recv_buf),
recv_buffer: Mutex::new(vec![0u8; max_len as usize]),
_phantom: PhantomData,
}
}
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/capability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl ClientCapabilitySet {
self.0 &= !(cap as u64);
}

pub fn iter<'a>(&'a self) -> impl Iterator<Item = ClientCapability> + 'a {
pub fn iter(&self) -> impl Iterator<Item = ClientCapability> + '_ {
ClientCapability::ALL
.iter()
.cloned()
Expand Down Expand Up @@ -156,7 +156,7 @@ impl AtomicCapabilitySet {
self.0.fetch_and(!(cap as u64), Ordering::Relaxed);
}

pub fn iter<'a>(&'a self) -> impl Iterator<Item = ClientCapability> + 'a {
pub fn iter(&self) -> impl Iterator<Item = ClientCapability> + '_ {
ClientCapability::ALL
.iter()
.cloned()
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/capability/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ impl CapabilityRepository {
self.update_supported_lists();
}
*/
pub fn enable_with_values(&self, cap: ClientCapability, values: &Vec<String>) {
pub fn enable_with_values(&self, cap: ClientCapability, values: &[String]) {
for entry in &self.supported_caps {
if entry.cap == cap {
entry.available.store(true, Ordering::Relaxed);
std::mem::swap(entry.values.write().as_mut(), &mut values.clone())
std::mem::swap(entry.values.write().as_mut(), &mut values.to_owned())
}
}
self.update_supported_lists();
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/command/client_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
pub fn user(&self) -> Option<&wrapper::User<'a>> {
match self {
Self::PreClient(_) => None,
Self::User(u, _) => Some(&u),
Self::User(u, _) => Some(u),
}
}

Expand Down Expand Up @@ -51,7 +51,7 @@
/// Arguments supplied
pub args: Vec<String>,
/// Tags provided by the client
pub tags: InboundTagSet,

Check warning on line 54 in sable_ircd/src/command/client_command.rs

View workflow job for this annotation

GitHub Actions / Test (nightly)

field `tags` is never read

// The response sink. labeled-response requires that this lives for the whole
// lifetime of the command, not just the handler duration, because even translated
Expand All @@ -72,7 +72,7 @@
message: ClientMessage,
) -> Result<Self, CommandError> {
let net = server.network();
let source = Self::translate_message_source(&*net, &*connection)?;
let source = Self::translate_message_source(&net, &connection)?;
let response_target = Self::translate_internal_source(&source, net.as_ref()).format();
let response_sink = Self::make_response_sink(
Arc::clone(&connection),
Expand Down
21 changes: 9 additions & 12 deletions sable_ircd/src/command/handlers/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ use super::*;
fn handle_admin(server: &ClientServer, response: &dyn CommandResponse) -> CommandResult {
response.numeric(make_numeric!(AdminMe, server.name()));
if let Some(admin_info) = &server.info_strings.admin_info {
admin_info
.server_location
.as_ref()
.map(|i| response.numeric(make_numeric!(AdminLocation1, i)));
if let Some(i) = admin_info.server_location.as_ref() {
response.numeric(make_numeric!(AdminLocation1, i))
}

admin_info
.description
.as_ref()
.map(|i| response.numeric(make_numeric!(AdminLocation2, i)));
if let Some(i) = admin_info.description.as_ref() {
response.numeric(make_numeric!(AdminLocation2, i))
}

admin_info
.email
.as_ref()
.map(|i| response.numeric(make_numeric!(AdminEmail, i)));
if let Some(i) = admin_info.email.as_ref() {
response.numeric(make_numeric!(AdminEmail, i))
}
}
Ok(())
}
23 changes: 12 additions & 11 deletions sable_ircd/src/command/handlers/chathistory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn parse_msgref(subcommand: &str, target: Option<&str>, msgref: &str) -> Result<
}
}

#[allow(clippy::too_many_arguments)]
#[command_handler("CHATHISTORY")]
fn handle_chathistory(
source: UserSource,
Expand Down Expand Up @@ -66,7 +67,7 @@ fn handle_chathistory(
// The spec allows the from and to timestamps in either order; list_targets requires from < to
list_targets(
server,
&response,
response,
source,
Some(min(from_ts, to_ts)),
Some(max(from_ts, to_ts)),
Expand All @@ -93,10 +94,10 @@ fn handle_chathistory(

send_history_for_target(
server,
&response,
response,
source,
subcommand,
&target,
target,
None,
to_ts,
limit,
Expand All @@ -120,7 +121,7 @@ fn handle_chathistory(

send_history_for_target(
server,
&response,
response,
source,
subcommand,
target,
Expand All @@ -147,10 +148,10 @@ fn handle_chathistory(

send_history_for_target(
server,
&response,
response,
source,
subcommand,
&target,
target,
Some(start_ts),
None,
Some(0), // backward limit
Expand All @@ -176,10 +177,10 @@ fn handle_chathistory(

send_history_for_target(
server,
&response,
response,
source,
subcommand,
&target,
target,
Some(around_ts),
None,
Some(limit / 2), // backward limit
Expand All @@ -204,10 +205,10 @@ fn handle_chathistory(

send_history_for_target(
server,
&response,
response,
source,
subcommand,
&target,
target,
Some(start_ts),
Some(end_ts),
Some(0), // backward limit
Expand Down Expand Up @@ -371,7 +372,7 @@ fn send_history_entries<'a>(
backward_entries: Vec<&'a HistoryLogEntry>,
forward_entries: Vec<&'a HistoryLogEntry>,
) -> CommandResult {
if backward_entries.len() == 0 && forward_entries.len() == 0 {
if backward_entries.is_empty() && forward_entries.is_empty() {
into.send(message::Fail::new(
"CHATHISTORY",
"INVALID_TARGET",
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/command/handlers/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async fn handle_user_mode(
if let Ok(d) = Direction::try_from(c) {
dir = d;
} else if let Some(flag) = UserModeFlag::from_mode_char(c) {
if server.policy().can_set_umode(&source, flag).is_err() {
if server.policy().can_set_umode(source, flag).is_err() {
continue;
}

Expand Down
3 changes: 1 addition & 2 deletions sable_ircd/src/command/handlers/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ fn handle_monitor_add(
let mut monitors = server.monitors.write();
let res = targets
.iter()
.map(|&target| monitors.insert(target, cmd.connection_id()))
.collect::<Result<(), _>>()
.try_for_each(|&target| monitors.insert(target, cmd.connection_id()))
.map_err(
|MonitorInsertError::TooManyMonitorsPerConnection { max, current }| {
CommandError::Numeric(make_numeric!(MonListFull, max, current))
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/command/handlers/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn handle_names(
) -> CommandResult {
match channel {
Ok(channel) => Ok(crate::utils::send_channel_names(
server, &response, &source, &channel,
server, response, &source, &channel,
)?),
Err(channel_name) => {
// "If the channel name is invalid or the channel does not exist, one RPL_ENDOFNAMES numeric
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/command/handlers/notice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn handle_notice(
*/
return Ok(());
};
if msg.len() == 0 {
if msg.is_empty() {
// Ditto
return Ok(());
}
Expand All @@ -44,7 +44,7 @@ async fn handle_notice(
}
}
TargetParameter::Channel(channel) => {
if server.policy().can_send(&source, &channel, msg).is_err() {
if server.policy().can_send(&source, channel, msg).is_err() {
// Silent error, see above
return Ok(());
}
Expand Down
7 changes: 1 addition & 6 deletions sable_ircd/src/command/handlers/oper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,5 @@ fn find_oper_block<'a>(
) -> Option<&'a config::OperConfig> {
let conf = net.config();

for block in &conf.opers {
if block.name == oper_name {
return Some(block);
}
}
None
conf.opers.iter().find(|&block| block.name == oper_name)
}
6 changes: 3 additions & 3 deletions sable_ircd/src/command/handlers/privmsg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ async fn handle_privmsg(
target: TargetParameter<'_>,
msg: &str,
) -> CommandResult {
if msg.len() == 0 {
if msg.is_empty() {
return numeric_error!(NoTextToSend);
}

match &target {
TargetParameter::User(user) => {
if let Some(AliasUser { command_alias, .. }) = user.is_alias_user() {
return super::services::dispatch_alias_command(cmd, &user, &command_alias, msg)
return super::services::dispatch_alias_command(cmd, user, command_alias, msg)
.await;
}

Expand All @@ -26,7 +26,7 @@ async fn handle_privmsg(
}
}
TargetParameter::Channel(channel) => {
server.policy().can_send(&source, &channel, msg)?;
server.policy().can_send(&source, channel, msg)?;
}
}

Expand Down
1 change: 1 addition & 0 deletions sable_ircd/src/command/handlers/rename.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

#[allow(clippy::too_many_arguments)]
#[command_handler("RENAME")]
async fn handle_rename(
server: &ClientServer,
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/command/handlers/services/cs/role.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async fn role_edit(
let (adding, flag_name) = match flag_str.as_bytes()[0] {
b'+' => (true, &flag_str[1..]),
b'-' => (false, &flag_str[1..]),
_ => (true, &flag_str[..]),
_ => (true, flag_str),
};

let Ok(flag) = ChannelAccessFlag::from_str(flag_name) else {
Expand Down Expand Up @@ -154,7 +154,7 @@ async fn role_add(
source: source.account.id(),
channel: chan.id(),
name: target_role_name,
flags: flags,
flags,
};
let registration_response = services_target.send_remote_request(request).await;

Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/command/handlers/services/dispatch_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub async fn dispatch_alias_command(
alias: &str,
command_str: &str,
) -> CommandResult {
let (command, args) = command_str.split_once(" ").unwrap_or((command_str, ""));
let (command, args) = command_str.split_once(' ').unwrap_or((command_str, ""));

let new_args = args.split(" ").map(ToOwned::to_owned).collect::<Vec<_>>();
let new_args = args.split(' ').map(ToOwned::to_owned).collect::<Vec<_>>();
let new_arg_iter = ArgListIter::new(&new_args);

let new_cmd = ServicesCommand::new(cmd, command, new_arg_iter, Some(through_user));
Expand Down
Loading
Loading