Skip to content

Commit

Permalink
fix: Remove dead code detected by the rust beta compiler (#2121)
Browse files Browse the repository at this point in the history
## Description

The beta compiler identifies these as dead code.

## Notes & open questions

<!-- Any notes, remarks or open questions you have to make about the PR.
-->

## Change checklist

- [x] Self-review.
  • Loading branch information
flub authored Mar 25, 2024
1 parent a136b1d commit 2c59d7d
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 65 deletions.
43 changes: 3 additions & 40 deletions iroh-bytes/src/store/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
use std::{collections::BTreeSet, io, path::PathBuf};

use bao_tree::{
io::fsm::{BaoContentItem, Outboard, OutboardMut},
io::fsm::{BaoContentItem, Outboard},
BaoTree, ByteNum, ChunkRanges,
};
use bytes::Bytes;
use futures::{future, Future, Stream, StreamExt};
use futures::{Future, Stream, StreamExt};
use genawaiter::rc::{Co, Gen};
use iroh_base::rpc::RpcError;
use iroh_io::{AsyncSliceReader, AsyncSliceWriter};
use iroh_io::AsyncSliceReader;
use serde::{Deserialize, Serialize};
use tokio::io::AsyncRead;
use tokio_util::task::LocalPoolHandle;
Expand Down Expand Up @@ -216,43 +216,6 @@ impl<W: BaoBatchWriter, F: Fn(u64, usize) -> io::Result<()> + 'static> BaoBatchW
}
}

/// A combined batch writer
///
/// This is just temporary to allow reusing the existing store implementations
/// that have separate data and outboard writers.
#[derive(Debug)]
pub(crate) struct CombinedBatchWriter<D, O> {
/// data part
pub data: D,
/// outboard part
pub outboard: O,
}

impl<D, O> BaoBatchWriter for CombinedBatchWriter<D, O>
where
D: AsyncSliceWriter,
O: OutboardMut,
{
async fn write_batch(&mut self, _size: u64, batch: Vec<BaoContentItem>) -> io::Result<()> {
for item in batch {
match item {
BaoContentItem::Parent(parent) => {
self.outboard.save(parent.node, &parent.pair).await?;
}
BaoContentItem::Leaf(leaf) => {
self.data.write_bytes_at(leaf.offset.0, leaf.data).await?;
}
}
}
Ok(())
}

async fn sync(&mut self) -> io::Result<()> {
future::try_join(self.data.sync(), self.outboard.sync()).await?;
Ok(())
}
}

/// A mutable bao map.
///
/// This extends the readonly [`Map`] trait with methods to create and modify entries.
Expand Down
4 changes: 0 additions & 4 deletions iroh-net/src/relay/client_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::time::Duration;
use anyhow::{Context, Result};
use bytes::Bytes;
use futures::{SinkExt, StreamExt};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::sync::mpsc;
use tokio_util::codec::Framed;
use tokio_util::sync::CancellationToken;
Expand Down Expand Up @@ -68,9 +67,6 @@ pub(crate) struct ClientChannels {
pub(crate) peer_gone: mpsc::Sender<PublicKey>,
}

pub trait Io: AsyncRead + AsyncWrite + Unpin + std::fmt::Debug {}
impl<T: AsyncRead + AsyncWrite + Unpin + std::fmt::Debug> Io for T {}

/// A builds a [`ClientConnManager`] from a [`PublicKey`] and an io connection.
#[derive(Debug)]
pub struct ClientConnBuilder {
Expand Down
2 changes: 2 additions & 0 deletions iroh-sync/src/ranger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ pub trait RangeEntry: Debug + Clone {
/// A trait constraining types that are valid entry keys.
pub trait RangeKey: Sized + Debug + Ord + PartialEq + Clone + 'static {
/// Returns `true` if `self` is a prefix of `other`.
#[cfg(test)]
fn is_prefix_of(&self, other: &Self) -> bool;

/// Returns true if `other` is a prefix of `self`.
#[cfg(test)]
fn is_prefixed_by(&self, other: &Self) -> bool {
other.is_prefix_of(self)
}
Expand Down
1 change: 1 addition & 0 deletions iroh-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ impl Debug for RecordIdentifier {
}

impl RangeKey for RecordIdentifier {
#[cfg(test)]
fn is_prefix_of(&self, other: &Self) -> bool {
other.as_ref().starts_with(self.as_ref())
}
Expand Down
21 changes: 0 additions & 21 deletions iroh/src/util/io.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Utilities for working with tokio io
use bao_tree::io::EncodeError;
use derive_more::Display;
use std::io::Write;
use thiserror::Error;

/// Todo: gather more information about validation errors. E.g. offset
Expand All @@ -14,23 +13,3 @@ pub enum BaoValidationError {
/// The data failed to validate
EncodeError(#[from] EncodeError),
}

/// little util that discards data but prints progress every 1MB
struct DevNull<F>(u64, F);

impl<F: Fn(u64)> Write for DevNull<F> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
const NOTIFY_EVERY: u64 = 1024 * 1024;
let prev = self.0;
let curr = prev + buf.len() as u64;
if prev % NOTIFY_EVERY != curr % NOTIFY_EVERY {
(self.1)(curr);
}
self.0 = curr;
Ok(buf.len())
}

fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}

0 comments on commit 2c59d7d

Please sign in to comment.