Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix endian-neutral parsers that use attributes #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cky
Copy link

@cky cky commented Jan 17, 2023

Normally, when using the Nom derive, parse_le delegates to parse_le, and parse_be delegates to parse_be. This allows the parser to be endian-neutral.

However, when using attributes, this is no longer the case, and both parse_le and parse_be delegate to parse. For example, for the below struct, MyStruct::parse_le and MyStruct::parse_be will both parse the u32 as big-endian:

#[derive(Nom)]
struct MyStruct(#[nom(Complete)] u32);

@cky
Copy link
Author

cky commented Jan 17, 2023

By the way, when running tests locally, it seems that the compiler output has changed for the current version, breaking some of the compile-fail tests. Here's a diff to fix those:

diff --git a/tests/compile-fail/error-enums.stderr b/tests/compile-fail/error-enums.stderr
index 4488c9f..ddc3731 100644
--- a/tests/compile-fail/error-enums.stderr
+++ b/tests/compile-fail/error-enums.stderr
@@ -27,3 +27,5 @@ error[E0552]: unrecognized representation hint
    |
 27 | #[repr(U24)] // ERROR: Nom-derive: cannot parse 'repr' content (must be a primitive type)
    |        ^^^
+   |
+   = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
diff --git a/tests/compile-fail/unsupported_types.stderr b/tests/compile-fail/unsupported_types.stderr
index 3a5a5d6..a15cc01 100644
--- a/tests/compile-fail/unsupported_types.stderr
+++ b/tests/compile-fail/unsupported_types.stderr
@@ -2,7 +2,7 @@ error: Nom-derive: multiple segments in type path are not supported
   --> $DIR/unsupported_types.rs:14:8
    |
 14 |     h: ::std::primitive::u64, // ERROR: Nom-derive: multiple segments in type path are not supported
-   |        ^^
+   |        ^
 
 error[E0599]: no function or associated item named `parse_be` found for struct `HashMap` in the current scope
  --> $DIR/unsupported_types.rs:7:10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant