Skip to content

Commit 47ce1af

Browse files
authored
Fix Nif* macros requiring an encoder (#676)
* Fix Nif* macros requiring an encoder * Add note and changelog entry
1 parent 6101dae commit 47ce1af

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
See [`UPGRADE.md`](./UPGRADE.md) for additional help when upgrading to newer
99
versions.
1010

11+
## unreleased
12+
13+
### Fixed
14+
15+
- Some derive macros failed when only `decode` was requested (#676)
16+
1117
## [0.35.1] - 2024-12-18
1218

1319
### Fixed

rustler_codegen/src/ex_struct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ pub fn transcoder_decorator(ast: &syn::DeriveInput, add_exception: bool) -> Toke
5959

6060
#decoder
6161

62-
#[allow(clippy::needless_borrow)]
6362
#encoder
6463
};
6564

rustler_codegen/src/map.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ pub fn transcoder_decorator(ast: &syn::DeriveInput) -> TokenStream {
4444

4545
#decoder
4646

47-
#[allow(clippy::needless_borrow)]
4847
#encoder
4948
};
5049

rustler_tests/native/rustler_test/src/test_codegen.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub fn tuple_echo(tuple: AddTuple) -> AddTuple {
2929

3030
#[derive(NifRecord)]
3131
#[rustler(encode, decode)] // Added to check encode/decode attribute, #180
32+
// The case of only `decode` is checked below
3233
#[must_use] // Added to check attribute order (see similar issue #152)
3334
#[tag = "record"]
3435
pub struct AddRecord {
@@ -225,6 +226,39 @@ pub fn tuplestruct_record_echo(tuplestruct: TupleStructRecord) -> TupleStructRec
225226
tuplestruct
226227
}
227228

229+
mod check_if_only_decode_is_enough {
230+
// Regression test, failed to compile
231+
// TODO: Move this test to the trybuild tests in rustler_codegen
232+
233+
use rustler::{NifMap, NifRecord, NifStruct, NifTaggedEnum, NifTuple, NifUnitEnum};
234+
235+
#[derive(NifMap)]
236+
#[rustler(decode)]
237+
struct TestMap {}
238+
239+
#[derive(NifRecord)]
240+
#[tag = "test_rec"]
241+
#[rustler(decode)]
242+
struct TestRec {}
243+
244+
#[derive(NifTuple)]
245+
#[rustler(decode)]
246+
struct TestTuple {}
247+
248+
#[derive(NifStruct)]
249+
#[module = "TestStruct"]
250+
#[rustler(decode)]
251+
struct TestStruct {}
252+
253+
#[derive(NifUnitEnum)]
254+
#[rustler(decode)]
255+
enum TestUnitEnum {}
256+
257+
#[derive(NifTaggedEnum)]
258+
#[rustler(decode)]
259+
enum TestTaggedEnum {}
260+
}
261+
228262
pub mod reserved_keywords {
229263
use rustler::{NifMap, NifRecord, NifStruct, NifTuple, NifUntaggedEnum};
230264

0 commit comments

Comments
 (0)