Skip to content

Commit

Permalink
Merge pull request #6 from dfns/derive-fixes
Browse files Browse the repository at this point in the history
Fix `udigest-derive` causing clippy warnings
  • Loading branch information
survived authored Jun 18, 2024
2 parents 5e9e8fd + 93d2f1e commit 85786ab
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 25 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
cache-on-failure: "true"
- name: Check docs
run: RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps
check-clippy:
clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -67,6 +67,15 @@ jobs:
cache-on-failure: "true"
- name: Run clippy
run: cargo clippy --all-features -- -D clippy::all
clippy-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"
- name: Run clippy
run: cargo clippy --all-features --tests -- -D clippy::all
check-changelog:
runs-on: ubuntu-latest
steps:
Expand Down
17 changes: 3 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions udigest-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## v0.2.0
* Fix proc macro causing clippy warnings in certain cases [#6]

[#6]: https://github.com/dfns/udigest/pull/6

## v0.1.0

The first release!
4 changes: 2 additions & 2 deletions udigest-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udigest-derive"
version = "0.1.0"
version = "0.2.0-rc3"
edition = "2021"
description = "Proc macro for `udigest` crate"
license = "MIT OR Apache-2.0"
Expand All @@ -15,4 +15,4 @@ path = "src/lib.rs"
[dependencies]
syn = "2"
quote = "1"
proc-macro2 = "1"
proc-macro2 = "1"
5 changes: 3 additions & 2 deletions udigest-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,16 +399,17 @@ fn encode_field(
let field_encoder = #encoder_var.add_field(#field_name);
let field_bytes = #func(#field_ref);
let field_bytes = AsRef::<[u8]>::as_ref(&field_bytes);
field_encoder.encode_leaf().chain(field_bytes);
field_encoder.encode_leaf_value(field_bytes);
}},
None => quote_spanned!(field_span => {
let field_encoder = #encoder_var.add_field(#field_name);
let field_bytes: &[u8] = AsRef::<[u8]>::as_ref(#field_ref);
field_encoder.encode_leaf().chain(field_bytes);
field_encoder.encode_leaf_value(field_bytes);
}),
},
(None, Some(attrs::With { value: func, .. })) => quote_spanned! {field_span => {
let field_encoder = #encoder_var.add_field(#field_name);
#[allow(clippy::needless_borrow)]
#func(#field_ref, field_encoder);
}},
(None, None) => quote_spanned! {field_span => {
Expand Down
2 changes: 2 additions & 0 deletions udigest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
* Add `udigest::inline_struct!` macro [#4]
* Add support for digesting `usize`/`isize` [#5]
* fix: handle cases when `EncodeValue` is dropped without being used [#4]
* fix: proc macro used to cause clippy warnings in certain cases [#6]

[#4]: https://github.com/dfns/udigest/pull/4
[#5]: https://github.com/dfns/udigest/pull/5
[#6]: https://github.com/dfns/udigest/pull/6

## v0.1.0

Expand Down
4 changes: 2 additions & 2 deletions udigest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "udigest"
version = "0.2.0-rc2"
version = "0.2.0-rc3"
edition = "2021"
license = "MIT OR Apache-2.0"
description = "Unambiguously digest structured data"
Expand All @@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
digest = { version = "0.10", default-features = false, optional = true }

udigest-derive = { version = "0.1", optional = true }
udigest-derive = { version = "0.2.0-rc3", path = "../udigest-derive", optional = true }

[dev-dependencies]
hex = "0.4"
Expand Down
10 changes: 10 additions & 0 deletions udigest/tests/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,13 @@ mod encoding {
list.finish()
}
}

#[derive(udigest::Digestable)]
pub struct StructWithRefs<'a> {
field1: &'a str,
#[udigest(as_bytes)]
field2: &'a [u8],
field3: &'a String,
#[udigest(with = encoding::encode_bar)]
field4: &'a Bar,
}
8 changes: 4 additions & 4 deletions udigest/tests/deterministic_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn shake256() {
let mut alice_hash_reader = udigest::hash_xof::<sha3::Shake256>(&ALICE);
alice_hash_reader.read(&mut hash);
assert_eq!(
hex::encode(&hash),
hex::encode(hash),
"ee629bcc426422887fe6f9a9a3384128bd5efc3c623a4599c8526c24a97972be\
2a325ef03c95ac649b77f0193c901c942762e93fd939372ef484681220c6fc0b\
0dc12be8c6b9ee914dac34697d0deeb3a3e510f24a1b0bfc24d144b639a66c6a\
Expand All @@ -50,7 +50,7 @@ fn shake256() {
let mut bob_hash_reader = udigest::hash_xof::<sha3::Shake256>(&BOB);
bob_hash_reader.read(&mut hash);
assert_eq!(
hex::encode(&hash),
hex::encode(hash),
"56cd71e796fc94176923b73bfe3f659ea7a9a666a2faae6020d1c4f41a51035a\
e7965583087f1badf452a40036499d54075350d8e64e5b68b0f3f52c286c15e3\
cb010249754a0c7f263d14c7a284da134ca133df84c62d80adfdb0ec0d5c3f0a\
Expand All @@ -64,14 +64,14 @@ fn blake2b() {

udigest::hash_vof::<blake2::Blake2bVar>(&ALICE, &mut out).unwrap();
assert_eq!(
hex::encode(&out),
hex::encode(out),
"57b2a8a078ca3b04dc72b308696bc4715c62593b461608bff01388ef3bd49fed\
244bd2e9407965ec2bfe13781ae3cd28ea0cb08fb4b46824ea7909c488fec8"
);

udigest::hash_vof::<blake2::Blake2bVar>(&BOB, &mut out).unwrap();
assert_eq!(
hex::encode(&out),
hex::encode(out),
"83aa6240d105ec1b496e6963dbab3e48fd09860b734c963b59ee764781d922f1\
207405232c1d84965b32f6a73b182b224d1533859f586c332377fe4a39489e"
);
Expand Down

0 comments on commit 85786ab

Please sign in to comment.