Skip to content

Commit

Permalink
Update for needless_borrows_for_generic_args
Browse files Browse the repository at this point in the history
A fix for this appears to be coming soon:
rust-lang/rust-clippy#12892

Signed-off-by: J Robert Ray <jrray@jrray.org>
  • Loading branch information
jrray committed Aug 2, 2024
1 parent 8cf6318 commit cdf6ad4
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 3 deletions.
6 changes: 6 additions & 0 deletions crates/spfs/src/graph/annotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ impl<'a> AnnotationValue<'a> {
pub fn legacy_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
match self {
AnnotationValue::String(v) => {
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_uint8(&mut writer, AnnotationValueKind::String as u8)?;
Ok(encoding::write_string(writer, v)?)
}
AnnotationValue::Blob(v) => {
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_uint8(&mut writer, AnnotationValueKind::Blob as u8)?;
Ok(encoding::write_digest(writer, v)?)
}
Expand Down Expand Up @@ -187,6 +191,8 @@ impl<'buf> Annotation<'buf> {

// Note: This is used for legacy and new style digest calculations
pub fn legacy_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_string(&mut writer, self.key())?;
self.value().legacy_encode(&mut writer)?;
Ok(())
Expand Down
4 changes: 4 additions & 0 deletions crates/spfs/src/graph/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ impl Blob {
}

pub(super) fn legacy_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_digest(&mut writer, self.payload())?;
encoding::write_uint64(writer, self.size())?;
Ok(())
Expand Down Expand Up @@ -132,6 +134,8 @@ impl BlobBuilder {
/// Read a data encoded using the legacy format, and
/// use the data to fill and complete this builder
pub fn legacy_decode(self, mut reader: &mut impl std::io::Read) -> Result<Blob> {
// Clippy doesn't realize `reader` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
Ok(self
.with_payload(encoding::read_digest(&mut reader)?)
.with_size(encoding::read_uint64(reader)?)
Expand Down
6 changes: 6 additions & 0 deletions crates/spfs/src/graph/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ impl<'buf> encoding::Digestible for Entry<'buf> {
}

impl<'buf> Entry<'buf> {
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
pub(super) fn digest_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
encoding::write_digest(&mut writer, self.object())?;
self.kind().encode(&mut writer)?;
Expand All @@ -189,6 +191,8 @@ impl<'buf> Entry<'buf> {
Ok(())
}

// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
pub(super) fn legacy_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
encoding::write_digest(&mut writer, self.object())?;
self.kind().encode(&mut writer)?;
Expand All @@ -198,6 +202,8 @@ impl<'buf> Entry<'buf> {
Ok(())
}

// Clippy doesn't realize `reader` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
pub(super) fn legacy_decode<'builder>(
builder: &mut flatbuffers::FlatBufferBuilder<'builder>,
mut reader: &mut impl BufRead,
Expand Down
2 changes: 2 additions & 0 deletions crates/spfs/src/graph/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ impl Layer {
// Includes any annotations regardless of the EncodingFormat setting
let annotations = self.annotations();
let result = if let Some(manifest_digest) = self.manifest() {
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
let manifest_result =
encoding::write_digest(&mut writer, manifest_digest).map_err(Error::Encoding);
for entry in annotations {
Expand Down
6 changes: 6 additions & 0 deletions crates/spfs/src/graph/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ impl Manifest {
// this method encodes the root tree first, and does not
// include it in the count of remaining trees since at least
// one root is always required
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_uint64(&mut writer, self.proto().trees().len() as u64 - 1)?;
// skip the root tree when saving the rest
for tree in self.iter_trees().skip(1) {
Expand All @@ -169,6 +171,8 @@ impl Manifest {
// this method encodes the root tree first, and does not
// include it in the count of remaining trees since at least
// one root is always required
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_uint64(&mut writer, self.proto().trees().len() as u64 - 1)?;
// skip the root tree when saving the rest
for tree in self.iter_trees().skip(1) {
Expand Down Expand Up @@ -246,6 +250,8 @@ impl ManifestBuilder {
// historically, the root tree was stored first an not included in the count
// since it is an error to not have at least one root tree
let root = Tree::legacy_decode(builder, &mut reader)?;
// Clippy doesn't realize `reader` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
let num_trees = encoding::read_uint64(&mut reader)?;
let mut trees = Vec::with_capacity(num_trees as usize + 1);
trees.push(root);
Expand Down
6 changes: 6 additions & 0 deletions crates/spfs/src/graph/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ impl Platform {
self.iter_bottom_up().copied().collect()
}

// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
pub(super) fn digest_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
// use a vec to know the name ahead of time and
// avoid iterating the stack twice
Expand All @@ -68,6 +70,8 @@ impl Platform {
Ok(())
}

// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
pub(super) fn legacy_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
// use a vec to know the name ahead of time and
// avoid iterating the stack twice
Expand Down Expand Up @@ -169,6 +173,8 @@ impl PlatformBuilder {

/// Read a data encoded using the legacy format, and
/// use the data to fill and complete this builder
// Clippy doesn't realize `reader` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
pub fn legacy_decode(self, mut reader: &mut impl std::io::Read) -> Result<Platform> {
let num_layers = encoding::read_uint64(&mut reader)?;
let mut layers = Vec::with_capacity(num_layers as usize);
Expand Down
6 changes: 6 additions & 0 deletions crates/spfs/src/graph/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ impl<'buf> Tree<'buf> {

pub(super) fn digest_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
let mut entries: Vec<_> = self.entries().collect();
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_uint64(&mut writer, entries.len() as u64)?;
// this is not the default sort mode for entries but
// matches the existing compatible encoding order
Expand All @@ -51,6 +53,8 @@ impl<'buf> Tree<'buf> {

pub(super) fn legacy_encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
let mut entries: Vec<_> = self.entries().collect();
// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
encoding::write_uint64(&mut writer, entries.len() as u64)?;
// this is not the default sort mode for entries but
// matches the existing compatible encoding order
Expand All @@ -66,6 +70,8 @@ impl<'buf> Tree<'buf> {
mut reader: &mut impl BufRead,
) -> Result<flatbuffers::WIPOffset<spfs_proto::Tree<'builder>>> {
let mut entries = Vec::new();
// Clippy doesn't realize `reader` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
let entry_count = encoding::read_uint64(&mut reader)?;
for _ in 0..entry_count {
entries.push(Entry::legacy_decode(builder, reader)?);
Expand Down
2 changes: 1 addition & 1 deletion crates/spfs/src/tracking/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl<'m, T> Iterator for ManifestWalker<'m, T> {
if child.kind.is_tree() {
self.active_child = Some(
ManifestWalker::new(child)
.with_prefix(&self.prefix.join(name))
.with_prefix(self.prefix.join(name))
.into(),
);
}
Expand Down
4 changes: 4 additions & 0 deletions crates/spfs/src/tracking/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ impl Digestible for Tag {
impl Encodable for Tag {
type Error = Error;

// Clippy doesn't realize `writer` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
fn encode(&self, mut writer: &mut impl std::io::Write) -> Result<()> {
if let Some(org) = self.org.as_ref() {
encoding::write_string(&mut writer, org)?;
Expand All @@ -156,6 +158,8 @@ impl Encodable for Tag {
}

impl encoding::Decodable for Tag {
// Clippy doesn't realize `reader` can't be moved here.
#[allow(clippy::needless_borrows_for_generic_args)]
fn decode(mut reader: &mut impl BufRead) -> Result<Self> {
let org = encoding::read_string(&mut reader)?;
let org = match org.as_str() {
Expand Down
4 changes: 2 additions & 2 deletions crates/spk-schema/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl TemplateExt for SpecTemplate {
Ok(v) => v,
};

let api = template_value.get(&serde_yaml::Value::String("api".to_string()));
let api = template_value.get(serde_yaml::Value::String("api".to_string()));

if api.is_none() {
tracing::warn!(
Expand All @@ -210,7 +210,7 @@ impl TemplateExt for SpecTemplate {
};

let pkg = template_value
.get(&serde_yaml::Value::String(name_field.to_string()))
.get(serde_yaml::Value::String(name_field.to_string()))
.ok_or_else(|| {
crate::Error::String(format!(
"Missing {name_field} field in spec file: {file_path:?}"
Expand Down

0 comments on commit cdf6ad4

Please sign in to comment.