Keats / validator

Simple validation for Rust structs
MIT License
1.91k stars 140 forks source link

fix: darling unexpected literal type error #327

Closed tvincent2 closed 1 day ago

tvincent2 commented 2 months ago

Hello!

When updating my dependency of validator from 0.16.1 to 0.18.1, I got the following error:

error: Unexpected literal type `path`
   --> /home/tvincent/.cargo/registry/src/index.crates.io-6f17d22bba15001f/validator_derive-0.18.1/src/lib.rs:228:22
    |
228 | #[darling(and_then = ValidationData::validate)]
    |                      ^^^^^^^^^^^^^^

From darling's README, it looks like the path given to and_then should be within double quotes, and indeed it fixed my build issue.

This PR simply adds the missing double quotes.

Thanks for making and taking care of validator (and zola!).

Keats commented 2 months ago

Hm was it changed in a version or depend on a specific version of rust? It definitely worked for me

tvincent2 commented 2 months ago

Hm was it changed in a version or depend on a specific version of rust? It definitely worked for me

I tested this on rust stable (i.e. 1.77.2 currently).

I tried to narrow it down a bit and it stops working for me with validator 0.17.0. The only changes I see are the bump of validator version and the introduction of darling in validator_derive's dependencies.

➜  git diff
diff --git a/Cargo.lock b/Cargo.lock
index 3f573e8..6c86b02 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1742,10 +1742,14 @@ dependencies = [
 ]

 [[package]]
-name = "if_chain"
-version = "1.0.2"
+name = "idna"
+version = "0.5.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cb56e1aa765b4b4f3aadfab769793b7087bb03a4ea4920644a6d238e2df5b9ed"
+checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6"
+dependencies = [
+ "unicode-bidi",
+ "unicode-normalization",
+]

 [[package]]
 name = "indexmap"
@@ -3331,12 +3335,12 @@ dependencies = [

 [[package]]
 name = "validator"
-version = "0.16.1"
+version = "0.17.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b92f40481c04ff1f4f61f304d61793c7b56ff76ac1469f1beb199b1445b253bd"
+checksum = "da339118f018cc70ebf01fafc103360528aad53717e4bf311db929cb01cb9345"
 dependencies = [
- "idna 0.4.0",
- "lazy_static",
+ "idna 0.5.0",
+ "once_cell",
  "regex",
  "serde",
  "serde_derive",
@@ -3347,28 +3351,16 @@ dependencies = [

 [[package]]
 name = "validator_derive"
-version = "0.16.0"
+version = "0.17.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bc44ca3088bb3ba384d9aecf40c6a23a676ce23e09bdaca2073d99c207f864af"
+checksum = "76e88ea23b8f5e59230bff8a2f03c0ee0054a61d5b8343a38946bcd406fe624c"
 dependencies = [
- "if_chain",
- "lazy_static",
+ "darling 0.20.1",
  "proc-macro-error",
  "proc-macro2",
  "quote",
  "regex",
- "syn 1.0.109",
- "validator_types",
-]
-
-[[package]]
-name = "validator_types"
-version = "0.16.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "111abfe30072511849c5910134e8baf8dc05de4c0e5903d681cbd5c9c4d611e3"
-dependencies = [
- "proc-macro2",
- "syn 1.0.109",
+ "syn 2.0.48",
 ]

 [[package]]
diff --git a/code/common/Cargo.toml b/code/common/Cargo.toml
index 26ecfa0..70f26a2 100644
--- a/code/common/Cargo.toml
+++ b/code/common/Cargo.toml
@@ -14,7 +14,7 @@ tracing = { workspace = true }
 tracing-subscriber = { workspace = true }
 serde ={ workspace = true }
 serde_json ={ workspace = true }
-validator = { version = "0.16.1", features = ["derive"] }
+validator = { version = "0.17.0", features = ["derive"] }
 sha1 = "0.10.6"
 hex-literal = "0.4.1"
 serde_with = { version = "3.6.1" }
Keats commented 2 months ago

CI failures are a bit weird?