style: crank clippy to pedantic+nursery and fix all lints
Enable the full clippy all + pedantic + nursery groups as workspace warnings, with a small documented allow-list for the pedantic/nursery lints this project intentionally does not follow (rustdoc-style requirements, deliberate numeric casts in the protocol/UI layers, and a few noisy nursery lints). Also enable the rust unused_lifetimes and unsafe_op_in_unsafe_fn lints. Fixed every resulting warning (527 -> 0) mechanically per clippy's suggestions: inline format args, const fns, item ordering, let-else, redundant clones, map_or, cast_lossless, Eq derives, associated-fn conversions for methods that never used self, and removing unnecessary Result wrappers whose call sites could never propagate an error. No runtime behavior changed; cargo fmt applied. cargo clippy --workspace --all-targets: 0 warnings. All tests pass.
This commit is contained in:
@@ -37,22 +37,22 @@ pub enum DownloadError {
|
||||
impl std::fmt::Display for DownloadError {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::ConnectionFailed(e) => write!(f, "Connection failed: {}", e),
|
||||
Self::ConnectionFailed(e) => write!(f, "Connection failed: {e}"),
|
||||
Self::InvalidAddress(addr) => {
|
||||
write!(f, "Invalid address: {}", addr)
|
||||
write!(f, "Invalid address: {addr}")
|
||||
}
|
||||
Self::HandshakeFailed(e) => write!(f, "Handshake failed: {}", e),
|
||||
Self::StreamReadError(e) => write!(f, "Stream read error: {}", e),
|
||||
Self::StreamWriteError(e) => write!(f, "Stream write error: {}", e),
|
||||
Self::HandshakeFailed(e) => write!(f, "Handshake failed: {e}"),
|
||||
Self::StreamReadError(e) => write!(f, "Stream read error: {e}"),
|
||||
Self::StreamWriteError(e) => write!(f, "Stream write error: {e}"),
|
||||
Self::TokenNotFound(token) => {
|
||||
write!(f, "Token not found: {}", token)
|
||||
write!(f, "Token not found: {token}")
|
||||
}
|
||||
Self::DownloadInfoMissing(token) => {
|
||||
write!(f, "Download info missing for token: {}", token)
|
||||
write!(f, "Download info missing for token: {token}")
|
||||
}
|
||||
Self::FileWriteError(e) => write!(f, "File write error: {}", e),
|
||||
Self::FileWriteError(e) => write!(f, "File write error: {e}"),
|
||||
Self::PathResolutionError(msg) => {
|
||||
write!(f, "Path resolution error: {}", msg)
|
||||
write!(f, "Path resolution error: {msg}")
|
||||
}
|
||||
Self::InvalidTokenBytes => {
|
||||
write!(f, "Invalid token bytes received")
|
||||
@@ -100,7 +100,7 @@ struct StreamProcessor {
|
||||
}
|
||||
|
||||
impl StreamProcessor {
|
||||
fn new() -> Self {
|
||||
const fn new() -> Self {
|
||||
Self {
|
||||
total_bytes: 0,
|
||||
received: false,
|
||||
@@ -113,7 +113,7 @@ impl StreamProcessor {
|
||||
self.total_bytes += data.len();
|
||||
}
|
||||
|
||||
fn should_continue(&self, expected_size: Option<usize>) -> bool {
|
||||
const fn should_continue(&self, expected_size: Option<usize>) -> bool {
|
||||
if let Some(size) = expected_size {
|
||||
self.total_bytes < size
|
||||
} else {
|
||||
@@ -134,7 +134,7 @@ pub struct DownloadPeer {
|
||||
|
||||
impl DownloadPeer {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
pub const fn new(
|
||||
username: String,
|
||||
host: String,
|
||||
port: u32,
|
||||
@@ -277,7 +277,7 @@ impl DownloadPeer {
|
||||
|
||||
loop {
|
||||
if let Some(ref dl) = download {
|
||||
self.wait_while_paused(client_context, dl)?;
|
||||
Self::wait_while_paused(client_context, dl)?;
|
||||
}
|
||||
|
||||
match stream.read(&mut read_buffer) {
|
||||
@@ -387,7 +387,6 @@ impl DownloadPeer {
|
||||
}
|
||||
|
||||
fn wait_while_paused(
|
||||
&self,
|
||||
client_context: &Arc<RwLock<ClientContext>>,
|
||||
download: &Download,
|
||||
) -> Result<(), DownloadError> {
|
||||
@@ -408,7 +407,6 @@ impl DownloadPeer {
|
||||
}
|
||||
|
||||
fn resolve_download_path(
|
||||
&self,
|
||||
download: &Download,
|
||||
) -> Result<String, DownloadError> {
|
||||
let download_directory = &download.download_directory;
|
||||
@@ -462,7 +460,6 @@ impl DownloadPeer {
|
||||
}
|
||||
|
||||
fn save_downloaded_file(
|
||||
&self,
|
||||
path: &str,
|
||||
data: &[u8],
|
||||
) -> Result<(), DownloadError> {
|
||||
@@ -511,8 +508,8 @@ impl DownloadPeer {
|
||||
let (buffer, download) =
|
||||
self.read_download_stream(&mut stream, &client_context, download)?;
|
||||
|
||||
let final_path = self.resolve_download_path(&download)?;
|
||||
self.save_downloaded_file(&final_path, &buffer)?;
|
||||
let final_path = Self::resolve_download_path(&download)?;
|
||||
Self::save_downloaded_file(&final_path, &buffer)?;
|
||||
|
||||
trace!(
|
||||
"[download_peer:{}] download completed successfully: {} bytes, saved to: {}",
|
||||
@@ -533,7 +530,8 @@ mod tests {
|
||||
fn finalize_rejects_truncated_download() {
|
||||
// Peer closed early: 5 of 10 promised bytes. Must be a failure so the
|
||||
// partial file is never reported as Completed.
|
||||
let result = DownloadPeer::finalize_download_buffer(vec![1, 2, 3, 4, 5], 10);
|
||||
let result =
|
||||
DownloadPeer::finalize_download_buffer(vec![1, 2, 3, 4, 5], 10);
|
||||
assert!(matches!(
|
||||
result,
|
||||
Err(DownloadError::IncompleteDownload {
|
||||
|
||||
@@ -65,7 +65,7 @@ fn parse_token_from_buffer(buffer: &[u8], username: &str) -> Option<u32> {
|
||||
let token = u32::from_le_bytes(
|
||||
token_bytes
|
||||
.try_into()
|
||||
.unwrap_or_else(|_| panic!("[listener:{}] slice with incorrect length, can't extract transfer_token", username)),
|
||||
.unwrap_or_else(|_| panic!("[listener:{username}] slice with incorrect length, can't extract transfer_token")),
|
||||
);
|
||||
Some(token)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ fn handle_file_connection(
|
||||
DownloadStatus::Completed,
|
||||
),
|
||||
Err(e) => {
|
||||
error!("[listener] handle_file_connection write: {}", e)
|
||||
error!("[listener] handle_file_connection write: {}", e);
|
||||
}
|
||||
}
|
||||
info!(
|
||||
@@ -204,7 +204,10 @@ fn handle_file_connection(
|
||||
DownloadStatus::Failed,
|
||||
),
|
||||
Err(e) => {
|
||||
error!("[listener] handle_file_connection fail write: {}", e)
|
||||
error!(
|
||||
"[listener] handle_file_connection fail write: {}",
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -272,7 +275,7 @@ fn handle_incoming_connection(stream: TcpStream, context: ConnectionContext) {
|
||||
&context,
|
||||
&peer_ip,
|
||||
peer_port,
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
ConnectionType::D => {
|
||||
|
||||
@@ -60,9 +60,9 @@ impl FromStr for ConnectionType {
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"P" => Ok(ConnectionType::P),
|
||||
"F" => Ok(ConnectionType::F),
|
||||
"D" => Ok(ConnectionType::D),
|
||||
"P" => Ok(Self::P),
|
||||
"F" => Ok(Self::F),
|
||||
"D" => Ok(Self::D),
|
||||
_ => Err(ParseConnectionTypeError),
|
||||
}
|
||||
}
|
||||
@@ -71,11 +71,11 @@ impl FromStr for ConnectionType {
|
||||
impl fmt::Display for ConnectionType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let s = match self {
|
||||
ConnectionType::P => "P",
|
||||
ConnectionType::F => "F",
|
||||
ConnectionType::D => "D",
|
||||
Self::P => "P",
|
||||
Self::F => "F",
|
||||
Self::D => "D",
|
||||
};
|
||||
write!(f, "{}", s)
|
||||
write!(f, "{s}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,7 +93,8 @@ pub struct Peer {
|
||||
}
|
||||
impl Peer {
|
||||
#[allow(clippy::too_many_arguments, dead_code)]
|
||||
pub fn new(
|
||||
#[must_use]
|
||||
pub const fn new(
|
||||
username: String,
|
||||
connection_type: ConnectionType,
|
||||
host: String,
|
||||
|
||||
Reference in New Issue
Block a user