From 6ab8320f075e36f2328a86f5fcf7674844a0bd12 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 29 Dec 2022 12:23:54 +0100 Subject: chore(tvix/store): address clippy warnings The only warnings left are unused warnings, but that'll change once we have a real implementation, and not just tests. Change-Id: I28912281b5e66735be37e999cc8ef4b8b09028fb Reviewed-on: https://cl.tvl.fyi/c/depot/+/7669 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/store/build.rs | 2 +- tvix/store/src/proto.rs | 31 ++++++++++++++----------------- 2 files changed, 15 insertions(+), 18 deletions(-) (limited to 'tvix/store') diff --git a/tvix/store/build.rs b/tvix/store/build.rs index 335e87b6c1d8..3fdc7418c1c5 100644 --- a/tvix/store/build.rs +++ b/tvix/store/build.rs @@ -15,7 +15,7 @@ fn main() -> Result<()> { // If we are in running `cargo build` manually, using `../..` works fine, // but in case we run inside a nix build, we need to instead point PROTO_ROOT // to a sparseTree containing that structure. - &[match std::env::var_os(&"PROTO_ROOT") { + &[match std::env::var_os("PROTO_ROOT") { Some(proto_root) => proto_root.to_str().unwrap().to_owned(), None => "../..".to_string(), }], diff --git a/tvix/store/src/proto.rs b/tvix/store/src/proto.rs index e5cde99ca8dc..40f1d1050c10 100644 --- a/tvix/store/src/proto.rs +++ b/tvix/store/src/proto.rs @@ -1,3 +1,5 @@ +#![allow(clippy::derive_partial_eq_without_eq)] +// https://github.com/hyperium/tonic/issues/1056 use std::collections::HashSet; use thiserror::Error; @@ -6,7 +8,7 @@ use prost::Message; tonic::include_proto!("tvix.store.v1"); /// Errors that can occur during the validation of Directory messages. -#[derive(Debug, Error, PartialEq)] +#[derive(Debug, PartialEq, Eq, Error)] pub enum ValidateDirectoryError { /// Elements are not in sorted order #[error("{0} is not sorted")] @@ -28,10 +30,9 @@ pub enum ValidateDirectoryError { /// message with an empty string as name is allowed, but they don't occur /// inside a Directory message. fn validate_node_name(name: &str) -> Result<(), ValidateDirectoryError> { - if name == "" || name == ".." || name == "." || name.contains("\x00") || name.contains("/") { - return Err(ValidateDirectoryError::InvalidName( - name.to_string().clone(), - )); + if name.is_empty() || name == ".." || name == "." || name.contains('\x00') || name.contains('/') + { + return Err(ValidateDirectoryError::InvalidName(name.to_string())); } Ok(()) } @@ -53,9 +54,7 @@ fn update_if_lt_prev<'set, 'n>( name: &'n str, ) -> Result<(), ValidateDirectoryError> { if *name < **prev_name { - return Err(ValidateDirectoryError::WrongSorting( - name.to_string().clone(), - )); + return Err(ValidateDirectoryError::WrongSorting(name.to_string())); } *prev_name = name; Ok(()) @@ -68,9 +67,7 @@ fn insert_once<'n>( name: &'n str, ) -> Result<(), ValidateDirectoryError> { if seen_names.get(name).is_some() { - return Err(ValidateDirectoryError::DuplicateName( - name.to_string().clone(), - )); + return Err(ValidateDirectoryError::DuplicateName(name.to_string())); } seen_names.insert(name); Ok(()) @@ -111,8 +108,8 @@ impl Directory { validate_node_name(&directory_node.name)?; validate_digest(&directory_node.digest)?; - update_if_lt_prev(&mut last_directory_name, &mut directory_node.name.as_str())?; - insert_once(&mut seen_names, &directory_node.name.as_str())?; + update_if_lt_prev(&mut last_directory_name, directory_node.name.as_str())?; + insert_once(&mut seen_names, directory_node.name.as_str())?; } // check files @@ -120,16 +117,16 @@ impl Directory { validate_node_name(&file_node.name)?; validate_digest(&file_node.digest)?; - update_if_lt_prev(&mut last_file_name, &mut file_node.name.as_str())?; - insert_once(&mut seen_names, &file_node.name.as_str())?; + update_if_lt_prev(&mut last_file_name, file_node.name.as_str())?; + insert_once(&mut seen_names, file_node.name.as_str())?; } // check symlinks for symlink_node in &self.symlinks { validate_node_name(&symlink_node.name)?; - update_if_lt_prev(&mut last_symlink_name, &mut symlink_node.name.as_str())?; - insert_once(&mut seen_names, &symlink_node.name.as_str())?; + update_if_lt_prev(&mut last_symlink_name, symlink_node.name.as_str())?; + insert_once(&mut seen_names, symlink_node.name.as_str())?; } Ok(()) -- cgit 1.4.1