about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authoredef <edef@edef.eu>2023-10-27T12·31+0000
committeredef <edef@edef.eu>2023-10-27T13·56+0000
commite5252720192064c8dfee6b869e8a5859d08e4a94 (patch)
tree69e1d3bbd4d598c98e13050e8371a4dfd6d9c448 /tvix
parent520c5a191e34e5b784efc624648ebd6d9292b556 (diff)
refactor(tvix): turn nullary enum variants into unit variants r/6893
Change-Id: Iad4f2cb4aa92b5bb29ead6050348a8cd3e7b8632
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9860
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Diffstat (limited to 'tvix')
-rw-r--r--tvix/castore/src/proto/mod.rs4
-rw-r--r--tvix/castore/src/proto/tests/directory.rs10
-rw-r--r--tvix/nix-compat/src/nixbase32.rs4
-rw-r--r--tvix/nix-compat/src/store_path/mod.rs28
-rw-r--r--tvix/store/src/proto/mod.rs4
-rw-r--r--tvix/store/src/proto/tests/pathinfo.rs10
6 files changed, 30 insertions, 30 deletions
diff --git a/tvix/castore/src/proto/mod.rs b/tvix/castore/src/proto/mod.rs
index cd7ea66b8c..f590c68413 100644
--- a/tvix/castore/src/proto/mod.rs
+++ b/tvix/castore/src/proto/mod.rs
@@ -48,7 +48,7 @@ pub enum ValidateNodeError {
     InvalidDigestLen(usize),
     /// Invalid name encountered
     #[error("Invalid name")]
-    InvalidName(),
+    InvalidName,
     /// Invalid symlink target
     #[error("Invalid symlink target: {}", .0.as_bstr())]
     InvalidSymlinkTarget(Vec<u8>),
@@ -63,7 +63,7 @@ fn validate_node_name(name: &[u8]) -> Result<(), ValidateNodeError> {
         || name.contains(&0x00)
         || name.contains(&b'/')
     {
-        Err(ValidateNodeError::InvalidName())?;
+        Err(ValidateNodeError::InvalidName)?;
     }
     Ok(())
 }
diff --git a/tvix/castore/src/proto/tests/directory.rs b/tvix/castore/src/proto/tests/directory.rs
index d4de19b771..0464a26829 100644
--- a/tvix/castore/src/proto/tests/directory.rs
+++ b/tvix/castore/src/proto/tests/directory.rs
@@ -165,7 +165,7 @@ fn validate_invalid_names() {
             ..Default::default()
         };
         match d.validate().expect_err("must fail") {
-            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
+            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
                 assert_eq!(n, b"")
             }
             _ => panic!("unexpected error"),
@@ -182,7 +182,7 @@ fn validate_invalid_names() {
             ..Default::default()
         };
         match d.validate().expect_err("must fail") {
-            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
+            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
                 assert_eq!(n, b".")
             }
             _ => panic!("unexpected error"),
@@ -200,7 +200,7 @@ fn validate_invalid_names() {
             ..Default::default()
         };
         match d.validate().expect_err("must fail") {
-            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
+            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
                 assert_eq!(n, b"..")
             }
             _ => panic!("unexpected error"),
@@ -216,7 +216,7 @@ fn validate_invalid_names() {
             ..Default::default()
         };
         match d.validate().expect_err("must fail") {
-            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
+            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
                 assert_eq!(n, b"\x00")
             }
             _ => panic!("unexpected error"),
@@ -232,7 +232,7 @@ fn validate_invalid_names() {
             ..Default::default()
         };
         match d.validate().expect_err("must fail") {
-            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
+            ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
                 assert_eq!(n, b"foo/bar")
             }
             _ => panic!("unexpected error"),
diff --git a/tvix/nix-compat/src/nixbase32.rs b/tvix/nix-compat/src/nixbase32.rs
index d9821bc495..6f88d51b34 100644
--- a/tvix/nix-compat/src/nixbase32.rs
+++ b/tvix/nix-compat/src/nixbase32.rs
@@ -19,7 +19,7 @@ pub enum Nixbase32DecodeError {
     #[error("character {0:x} not in alphabet")]
     CharacterNotInAlphabet(u8),
     #[error("nonzero carry")]
-    NonzeroCarry(),
+    NonzeroCarry,
     #[error("invalid length")]
     InvalidLength,
 }
@@ -118,7 +118,7 @@ fn decode_inner(input: &[u8], output: &mut [u8]) -> Result<(), Nixbase32DecodeEr
 
     // if we're at the end, but have a nonzero carry, the encoding is invalid.
     if carry != 0 {
-        return Err(Nixbase32DecodeError::NonzeroCarry());
+        return Err(Nixbase32DecodeError::NonzeroCarry);
     }
 
     Ok(())
diff --git a/tvix/nix-compat/src/store_path/mod.rs b/tvix/nix-compat/src/store_path/mod.rs
index 63f0aaa3fe..7c0ff7eab1 100644
--- a/tvix/nix-compat/src/store_path/mod.rs
+++ b/tvix/nix-compat/src/store_path/mod.rs
@@ -28,11 +28,11 @@ pub const STORE_DIR_WITH_SLASH: &str = "/nix/store/";
 #[derive(Debug, PartialEq, Eq, thiserror::Error)]
 pub enum Error {
     #[error("Dash is missing between hash and name")]
-    MissingDash(),
+    MissingDash,
     #[error("Hash encoding is invalid: {0}")]
     InvalidHashEncoding(Nixbase32DecodeError),
     #[error("Invalid length")]
-    InvalidLength(),
+    InvalidLength,
     #[error(
         "Invalid name: \"{}\", character at position {} is invalid",
         std::str::from_utf8(.0).unwrap_or(&BASE64.encode(.0)),
@@ -40,7 +40,7 @@ pub enum Error {
     )]
     InvalidName(Vec<u8>, u8),
     #[error("Tried to parse an absolute path which was missing the store dir prefix.")]
-    MissingStoreDir(),
+    MissingStoreDir,
 }
 
 /// Represents a path in the Nix store (a direct child of [STORE_DIR]).
@@ -102,7 +102,7 @@ impl StorePath {
         // - 1 dash
         // - 1 character for the name
         if s.len() < ENCODED_DIGEST_SIZE + 2 {
-            Err(Error::InvalidLength())?
+            Err(Error::InvalidLength)?
         }
 
         let digest = match nixbase32::decode(&s[..ENCODED_DIGEST_SIZE]) {
@@ -111,7 +111,7 @@ impl StorePath {
         };
 
         if s[ENCODED_DIGEST_SIZE] != b'-' {
-            return Err(Error::MissingDash());
+            return Err(Error::MissingDash);
         }
 
         Ok(StorePath {
@@ -126,7 +126,7 @@ impl StorePath {
     pub fn from_absolute_path(s: &[u8]) -> Result<StorePath, Error> {
         match s.strip_prefix(STORE_DIR_WITH_SLASH.as_bytes()) {
             Some(s_stripped) => Self::from_bytes(s_stripped),
-            None => Err(Error::MissingStoreDir()),
+            None => Err(Error::MissingStoreDir),
         }
     }
 
@@ -134,7 +134,7 @@ impl StorePath {
     pub fn from_name_and_digest(name: String, digest: &[u8]) -> Result<StorePath, Error> {
         Ok(Self {
             name: validate_name(name.as_bytes())?.to_owned(),
-            digest: digest.try_into().map_err(|_| Error::InvalidLength())?,
+            digest: digest.try_into().map_err(|_| Error::InvalidLength)?,
         })
     }
 
@@ -144,7 +144,7 @@ impl StorePath {
     pub fn from_absolute_path_full(s: &str) -> Result<(StorePath, PathBuf), Error> {
         // strip [STORE_DIR_WITH_SLASH] from s
         match s.strip_prefix(STORE_DIR_WITH_SLASH) {
-            None => Err(Error::MissingStoreDir()),
+            None => Err(Error::MissingStoreDir),
             Some(rest) => {
                 // put rest in a PathBuf
                 let mut p = PathBuf::new();
@@ -161,7 +161,7 @@ impl StorePath {
                     let rest_buf: PathBuf = it.collect();
                     Ok((store_path, rest_buf))
                 } else {
-                    Err(Error::InvalidLength()) // Well, or missing "/"?
+                    Err(Error::InvalidLength) // Well, or missing "/"?
                 }
             }
         }
@@ -205,7 +205,7 @@ pub(crate) fn validate_name(s: &(impl AsRef<[u8]> + ?Sized)) -> Result<&str, Err
 
     // Empty or excessively long names are not allowed.
     if s.is_empty() || s.len() > 211 {
-        return Err(Error::InvalidLength());
+        return Err(Error::InvalidLength);
     }
 
     if s[0] == b'.' {
@@ -341,7 +341,7 @@ mod tests {
     #[test]
     fn absolute_path_missing_prefix() {
         assert_eq!(
-            Error::MissingStoreDir(),
+            Error::MissingStoreDir,
             StorePath::from_absolute_path(b"foobar-123").expect_err("must fail")
         );
     }
@@ -370,15 +370,15 @@ mod tests {
     #[test]
     fn from_absolute_path_errors() {
         assert_eq!(
-            Error::InvalidLength(),
+            Error::InvalidLength,
             StorePath::from_absolute_path_full("/nix/store/").expect_err("must fail")
         );
         assert_eq!(
-            Error::InvalidLength(),
+            Error::InvalidLength,
             StorePath::from_absolute_path_full("/nix/store/foo").expect_err("must fail")
         );
         assert_eq!(
-            Error::MissingStoreDir(),
+            Error::MissingStoreDir,
             StorePath::from_absolute_path_full(
                 "00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432"
             )
diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs
index fe942ac266..232086c0f8 100644
--- a/tvix/store/src/proto/mod.rs
+++ b/tvix/store/src/proto/mod.rs
@@ -29,7 +29,7 @@ pub enum ValidatePathInfoError {
 
     /// No node present
     #[error("No node present")]
-    NoNodePresent(),
+    NoNodePresent,
 
     /// Node fails validation
     #[error("Invalid root node: {:?}", .0.to_string())]
@@ -159,7 +159,7 @@ impl PathInfo {
         // Ensure there is a (root) node present, and it properly parses to a [store_path::StorePath].
         let root_nix_path = match &self.node {
             None | Some(castorepb::Node { node: None }) => {
-                Err(ValidatePathInfoError::NoNodePresent())?
+                Err(ValidatePathInfoError::NoNodePresent)?
             }
             Some(castorepb::Node { node: Some(node) }) => {
                 node.validate()
diff --git a/tvix/store/src/proto/tests/pathinfo.rs b/tvix/store/src/proto/tests/pathinfo.rs
index 392d5d8127..c296512f66 100644
--- a/tvix/store/src/proto/tests/pathinfo.rs
+++ b/tvix/store/src/proto/tests/pathinfo.rs
@@ -8,12 +8,12 @@ use tvix_castore::proto as castorepb;
 
 #[test_case(
     None,
-    Err(ValidatePathInfoError::NoNodePresent()) ;
+    Err(ValidatePathInfoError::NoNodePresent) ;
     "No node"
 )]
 #[test_case(
     Some(castorepb::Node { node: None }),
-    Err(ValidatePathInfoError::NoNodePresent());
+    Err(ValidatePathInfoError::NoNodePresent);
     "No node 2"
 )]
 fn validate_no_node(
@@ -54,7 +54,7 @@ fn validate_no_node(
     },
     Err(ValidatePathInfoError::InvalidNodeName(
         "invalid".into(),
-        store_path::Error::InvalidLength()
+        store_path::Error::InvalidLength
     ));
     "invalid node name"
 )]
@@ -99,7 +99,7 @@ fn validate_directory(
     },
     Err(ValidatePathInfoError::InvalidNodeName(
         "invalid".into(),
-        store_path::Error::InvalidLength()
+        store_path::Error::InvalidLength
     ));
     "invalid node name"
 )]
@@ -132,7 +132,7 @@ fn validate_file(
     },
     Err(ValidatePathInfoError::InvalidNodeName(
         "invalid".into(),
-        store_path::Error::InvalidLength()
+        store_path::Error::InvalidLength
     ));
     "invalid node name"
 )]