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 and run Clippy on CI #146

Merged
merged 3 commits into from
Nov 17, 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
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ jobs:
# command: doc
# args: ${{ matrix.features }}

fmt:
name: Check formatting
lint:
name: Linting
runs-on: ubuntu-latest

steps:
Expand All @@ -67,3 +67,8 @@ jobs:
command: fmt
args: -- --check

- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets
4 changes: 2 additions & 2 deletions client_listener/examples/restart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ async fn do_restart(
let fd = to_memfd(data).unwrap();

tracing::debug!("executing restart");
Command::new(current_exe().unwrap())
let e = Command::new(current_exe().unwrap())
.args([fd.to_string()])
.exec();

panic!("Couldn't exec?");
panic!("Couldn't exec: {:?}", e);
}

#[tokio::main]
Expand Down
2 changes: 1 addition & 1 deletion client_listener/src/internal/connection_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
message = lines.next_line() => match message {
Ok(None) => { break; },
Ok(Some(m)) => {
if m.as_bytes().len() as u64 > crate::MAX_MSG_SIZE {
if m.len() as u64 > crate::MAX_MSG_SIZE { // in bytes
if self.event_channel.send(InternalConnectionEventType::Event(InternalConnectionEvent::ConnectionError(self.id, ConnectionError::InputLineTooLong))).await.is_err() {
tracing::error!("Error notifying socket error on connection {:?}", self.id);
}
Expand Down
4 changes: 2 additions & 2 deletions sable_history/src/pg_history_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> PgHistoryService<'a> {
}
}

impl<'a> HistoryService for PgHistoryService<'a> {
impl HistoryService for PgHistoryService<'_> {
async fn list_targets(
&self,
_user: UserId,
Expand All @@ -48,7 +48,7 @@ impl<'a> HistoryService for PgHistoryService<'a> {
{
Err(e) => {
tracing::error!("Could not get history channels: {e}");
return HashMap::new();
HashMap::new()
}
Ok(rows) => rows
.map(|row| -> Result<(TargetId, i64)> {
Expand Down
10 changes: 4 additions & 6 deletions sable_history/src/server/update_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl HistoryServer {
let mut connection_lock = self.database_connection.lock().await;

if let Some(existing) = historic_users
.filter(HistoricUser::with_network_id(&huid))
.filter(HistoricUser::with_network_id(huid))
.select(HistoricUser::as_select())
.first(&mut *connection_lock)
.await
Expand Down Expand Up @@ -103,9 +103,9 @@ impl HistoryServer {
}
}

async fn get_or_create_channel<'a>(
async fn get_or_create_channel(
&self,
data: wrapper::Channel<'a>,
data: wrapper::Channel<'_>,
) -> anyhow::Result<crate::models::Channel> {
use crate::schema::channels::dsl::*;

Expand Down Expand Up @@ -154,9 +154,7 @@ impl HistoryServer {
};
let net_message = net.message(new_message.message)?;

let db_source = self
.get_or_create_historic_user(&source_id, &source)
.await?;
let db_source = self.get_or_create_historic_user(&source_id, source).await?;
let db_channel = self.get_or_create_channel(channel).await?;

let db_message = crate::models::Message {
Expand Down
6 changes: 6 additions & 0 deletions sable_ircd/src/capability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ impl ClientCapabilitySet {
#[derive(Debug)]
pub struct AtomicCapabilitySet(AtomicU64);

impl Default for AtomicCapabilitySet {
fn default() -> Self {
Self::new()
}
}

impl AtomicCapabilitySet {
pub fn new() -> Self {
Self(AtomicU64::new(0))
Expand Down
6 changes: 2 additions & 4 deletions sable_ircd/src/command/handlers/chathistory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async fn list_targets<'a>(
}
}

fn send_history_entries<'a>(
fn send_history_entries(
_server: &ClientServer,
conn: impl MessageSink,
target: &str,
Expand All @@ -226,9 +226,7 @@ fn send_history_entries<'a>(
text,
} => {
let msg = message::Message::new(&source, &target, message_type, &text)
.with_tag(server_time::server_time_tag(
i64::try_from(timestamp).unwrap_or(i64::MAX),
))
.with_tag(server_time::server_time_tag(timestamp))
.with_tag(OutboundMessageTag::new(
"msgid",
Some(id.to_string()),
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/command/handlers/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<'a> ServicesCommand<'a> {
}
}

impl<'a> Command for ServicesCommand<'a> {
impl Command for ServicesCommand<'_> {
fn source(&self) -> CommandSource<'_> {
self.outer.source()
}
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/command/handlers/services/ns/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async fn cert_add(
cmd: &dyn Command,
param: Conditional<&str>,
) -> CommandResult {
let fingerprint = match param.is_present() {
let fingerprint = match param.present() {
Some(fp) => fp,
None => {
if let Some(fp) = cmd
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/command/plumbing/argument_wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a> AmbientArgument<'a> for ServicesTarget<'a> {
}
}

impl<'a> ServicesTarget<'a> {
impl ServicesTarget<'_> {
pub async fn send_remote_request(
&self,
req: RemoteServerRequestType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl<T> Conditional<T> {
}

/// Return the argument, if it was successfully parsed
pub fn is_present(self) -> Option<T> {
pub fn present(self) -> Option<T> {
self.0.ok()
}
}
Expand Down
4 changes: 2 additions & 2 deletions sable_ircd/src/command/plumbing/target_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl TargetParameter<'_> {
}
}

impl<'a> From<&TargetParameter<'a>> for sable_network::history::TargetId {
impl From<&TargetParameter<'_>> for sable_network::history::TargetId {
fn from(value: &TargetParameter) -> Self {
match value {
TargetParameter::User(u) => u.id().into(),
Expand All @@ -25,7 +25,7 @@ impl<'a> From<&TargetParameter<'a>> for sable_network::history::TargetId {
}
}

impl<'a> From<TargetParameter<'a>> for sable_network::history::TargetId {
impl From<TargetParameter<'_>> for sable_network::history::TargetId {
fn from(value: TargetParameter) -> Self {
(&value).into()
}
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/connection_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl ConnectionCollection {
}
}

impl<'a> Iterator for UserConnectionIter<'a> {
impl Iterator for UserConnectionIter<'_> {
type Item = Arc<ClientConnection>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
10 changes: 5 additions & 5 deletions sable_ircd/src/messages/send_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl SendHistoryItem<update::ChannelTopicChange> for ClientServer {
let source = net.message_source(&item.setter)?;
let channel = net.channel(item.channel)?;

let message = message::Topic::new(&source, &channel.name(), &item.new_text)
let message = message::Topic::new(&source, channel.name(), &item.new_text)
.with_tags_from(from_entry, &net);

conn.send(message);
Expand Down Expand Up @@ -302,7 +302,7 @@ impl SendHistoryItem<update::ChannelJoin> for ClientServer {
let membership = net.membership(item.membership)?;
let channel = membership.channel()?;

let message = message::Join::new(user, &channel.name()).with_tags_from(from_entry, &net);
let message = message::Join::new(user, channel.name()).with_tags_from(from_entry, &net);

conn.send(message);

Expand Down Expand Up @@ -343,7 +343,7 @@ impl SendHistoryItem<update::ChannelKick> for ClientServer {
let user = net.historic_user(item.user)?;
let channel = net.channel(item.membership.channel)?;

let message = message::Kick::new(&source, user, &channel.name(), &item.message)
let message = message::Kick::new(&source, user, channel.name(), &item.message)
.with_tags_from(from_entry, &net);

conn.send(message);
Expand All @@ -365,7 +365,7 @@ impl SendHistoryItem<update::ChannelPart> for ClientServer {

// If editing this behaviour, make sure that the faked version in the channel rename
// handler stays in sync
let message = message::Part::new(user, &channel.name(), &item.message)
let message = message::Part::new(user, channel.name(), &item.message)
.with_tags_from(from_entry, &net);

conn.send(message);
Expand All @@ -387,7 +387,7 @@ impl SendHistoryItem<update::ChannelInvite> for ClientServer {
let channel = net.channel(item.invite.channel())?;

let message =
message::Invite::new(&source, user, &channel.name()).with_tags_from(from_entry, &net);
message::Invite::new(&source, user, channel.name()).with_tags_from(from_entry, &net);

conn.send(message);

Expand Down
6 changes: 3 additions & 3 deletions sable_ircd/src/messages/source_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl MessageSource for wrapper::User<'_> {
}
}

impl<'a> MessageSource for wrapper::HistoricMessageSource<'a> {
impl MessageSource for wrapper::HistoricMessageSource<'_> {
fn format(&self) -> String {
match self {
Self::User(historic_user) => MessageSource::format(*historic_user),
Expand Down Expand Up @@ -115,7 +115,7 @@ impl MessageTarget for state::HistoricUser {
}
}

impl<'a> MessageTarget for wrapper::HistoricMessageTarget<'a> {
impl MessageTarget for wrapper::HistoricMessageTarget<'_> {
fn format(&self) -> String {
match self {
Self::Channel(c) => c.name().to_string(),
Expand All @@ -127,7 +127,7 @@ impl<'a> MessageTarget for wrapper::HistoricMessageTarget<'a> {

// This may seem counter-intuitive, but there are times we need to
// format a message source as if it were a target
impl<'a> MessageTarget for wrapper::HistoricMessageSource<'a> {
impl MessageTarget for wrapper::HistoricMessageSource<'_> {
fn format(&self) -> String {
match self {
Self::Server(s) => s.name().to_string(),
Expand Down
6 changes: 6 additions & 0 deletions sable_ircd/src/server/async_handler_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ pub struct AsyncHandlerCollection<'a> {
futures: FuturesUnordered<AsyncHandler<'a>>,
}

impl Default for AsyncHandlerCollection<'_> {
fn default() -> Self {
Self::new()
}
}

impl<'a> AsyncHandlerCollection<'a> {
pub fn new() -> Self {
Self {
Expand Down
2 changes: 1 addition & 1 deletion sable_ircd/src/throttled_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<T: std::fmt::Debug> ThrottledQueue<T> {
}
}

impl<'a, T: std::fmt::Debug> Iterator for ThrottledQueueIterator<'a, T> {
impl<T: std::fmt::Debug> Iterator for ThrottledQueueIterator<'_, T> {
type Item = T;

fn next(&mut self) -> Option<T> {
Expand Down
3 changes: 2 additions & 1 deletion sable_ircd/src/utils/line_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl<const JOINER: char, Item: AsRef<str>, Iter: Iterator<Item = Item>> Iterator

for item in self.iter.by_ref() {
let item = item.as_ref();
if buf.as_bytes().len() + JOINER.len_utf8() + item.as_bytes().len() <= self.line_length
if buf.len() + JOINER.len_utf8() + item.len() <= self.line_length
// in bytes
{
buf.push(JOINER);
buf.push_str(item);
Expand Down
4 changes: 3 additions & 1 deletion sable_network/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ fn write_head_date(root: String, dest: path::PathBuf) -> Result<(), git2::Error>
&& e.code() == git2::ErrorCode::NotFound =>
{
f.write_all(
format!("\npub const GIT_COMMIT_TIME_UTC: Option<&str> = None;\n").as_bytes(),
"\npub const GIT_COMMIT_TIME_UTC: Option<&str> = None;\n"
.to_string()
.as_bytes(),
)
.expect("could not write to built.rs");
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion sable_network/src/audit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> AuditLogger<'a> {
}
}

impl<'a> AuditLoggerEntry<'a> {
impl AuditLoggerEntry<'_> {
pub fn source(mut self, id: Option<UserId>, ip: Option<IpAddr>) -> Self {
self.source_id = id;
self.source_str = format_source(self.node, id, ip);
Expand Down
6 changes: 3 additions & 3 deletions sable_network/src/history/local_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a, NetworkPolicy: policy::PolicyService> LocalHistoryService<'a, NetworkPo
Ok(backward_entries
.into_iter()
.rev()
.chain(forward_entries.into_iter())
.chain(forward_entries)
.flat_map(move |entry| Self::translate_log_entry(entry, &net)))
} else {
Err(HistoryError::InvalidTarget(target))
Expand Down Expand Up @@ -145,8 +145,8 @@ impl<'a, NetworkPolicy: policy::PolicyService> LocalHistoryService<'a, NetworkPo
}
}

impl<'a, NetworkPolicy: policy::PolicyService> HistoryService
for LocalHistoryService<'a, NetworkPolicy>
impl<NetworkPolicy: policy::PolicyService> HistoryService
for LocalHistoryService<'_, NetworkPolicy>
{
#[instrument(skip(self))]
async fn list_targets(
Expand Down
4 changes: 2 additions & 2 deletions sable_network/src/history/remote_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl<'a, NetworkPolicy: policy::PolicyService> RemoteHistoryService<'a, NetworkP
}
}

impl<'a, NetworkPolicy: policy::PolicyService> HistoryService
for RemoteHistoryService<'a, NetworkPolicy>
impl<NetworkPolicy: policy::PolicyService> HistoryService
for RemoteHistoryService<'_, NetworkPolicy>
{
#[instrument(skip(self))]
async fn list_targets(
Expand Down
10 changes: 5 additions & 5 deletions sable_network/src/network/network/channel_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl Network {
updates.notify(
update::MembershipFlagChange {
membership: target,
user: self.translate_historic_user_id(&user),
user: self.translate_historic_user_id(user),
added: details.added,
removed: details.removed,
changed_by: self.translate_state_change_source(details.changed_by),
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Network {
if let Some(user) = self.users.get(&target.user()) {
let update = update::ChannelJoin {
membership: target,
user: self.translate_historic_user_id(&user),
user: self.translate_historic_user_id(user),
};
updates.notify(update, event);
}
Expand All @@ -314,7 +314,7 @@ impl Network {
let update = update::ChannelKick {
membership: removed_membership,
source: self.translate_state_change_source(details.source.into()),
user: self.translate_historic_user_id(&user),
user: self.translate_historic_user_id(user),
message: details.message.clone(),
};
updates.notify(update, event);
Expand All @@ -341,7 +341,7 @@ impl Network {
if let Some(user) = self.users.get(&target.user()) {
let update = update::ChannelPart {
membership: removed_membership,
user: self.translate_historic_user_id(&user),
user: self.translate_historic_user_id(user),
message: details.message.clone(),
};
updates.notify(update, event);
Expand Down Expand Up @@ -380,7 +380,7 @@ impl Network {
let update = update::ChannelInvite {
invite: target,
source: self.translate_state_change_source(details.source.into()),
user: self.translate_historic_user_id(&user),
user: self.translate_historic_user_id(user),
};
updates.notify(update, event);
}
Expand Down
Loading
Loading