Repository: sharksforarms/deku
Pull request #474 (2024-09-04 13:02:07)

Fix incorrect error spans

github-actions[bot]: ## Benchmark for 9a3f906
  <details>
    <summary>Click to view benchmark</summary>

| Test | Base         | PR               | % |
|------|--------------|------------------|---|
| count | **3.4±0.02µs** | 3.6±0.01µs | **+5.88%** |
| deku_read_bits | 1126.5±16.04ns | 1113.1±24.44ns | -1.19% |
| deku_read_byte | 3.6±0.11ns | **3.4±0.05ns** | **-5.56%** |
| deku_read_enum | 3.5±0.02ns | **3.1±0.03ns** | **-11.43%** |
| deku_read_vec | 31.7±0.32ns | 31.7±0.46ns | 0.00% |
| deku_write_bits | 198.2±3.93ns | **184.2±4.20ns** | **-7.06%** |
| deku_write_byte | 24.5±0.32ns | 24.5±0.16ns | 0.00% |
| deku_write_enum | 22.7±0.64ns | 22.8±0.81ns | +0.44% |
| deku_write_vec | **410.5±4.42ns** | 437.1±6.54ns | **+6.48%** |
| read_all | **3.8±0.05µs** | 5.5±0.04µs | **+44.74%** |
| read_all_bytes | 5.6±0.04µs | **3.8±0.06µs** | **-32.14%** |

  </details>
  

Patch:
diff --git a/deku-derive/src/lib.rs b/deku-derive/src/lib.rs
index fea289b..a686b3b 100644
--- a/deku-derive/src/lib.rs
+++ b/deku-derive/src/lib.rs
@@ -571,8 +571,8 @@ impl FieldData {
                 || (data.bits_read.is_some() || data.bytes_read.is_some()))
         {
             return Err(cerror(
-                data.bits.span(),
-                "conflicting: `read_all` cannot be used with `until`, count`, `bits_read`, or `bytes_read`",
+                data.read_all.span(),
+                "conflicting: `read_all` cannot be used with `until`, `count`, `bits_read`, or `bytes_read`",
             ));
         }
 
@@ -584,7 +584,7 @@ impl FieldData {
             > 1
         {
             return Err(cerror(
-                data.bits.span(),
+                data.ty.span(),
                 "conflicting: only one `seek` attribute can be used at one time",
             ));
         }


Test patch:
diff --git a/tests/test_compile/cases/count_read_conflict.stderr b/tests/test_compile/cases/count_read_conflict.stderr
index 19f29cf..9adaa4a 100644
--- a/tests/test_compile/cases/count_read_conflict.stderr
+++ b/tests/test_compile/cases/count_read_conflict.stderr
@@ -22,7 +22,7 @@ error: conflicting: both `count` and `bytes_read` specified on field
 23 |     #[deku(count = "1", bytes_read = "2")]
    |                    ^^^
 
-error: conflicting: `read_all` cannot be used with `until`, count`, `bits_read`, or `bytes_read`
+error: conflicting: `read_all` cannot be used with `until`, `count`, `bits_read`, or `bytes_read`
   --> $DIR/count_read_conflict.rs:27:10
    |
 27 | #[derive(DekuRead)]
@@ -30,7 +30,7 @@ error: conflicting: `read_all` cannot be used with `until`, count`, `bits_read`,
    |
    = note: this error originates in the derive macro `DekuRead` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: conflicting: `read_all` cannot be used with `until`, count`, `bits_read`, or `bytes_read`
+error: conflicting: `read_all` cannot be used with `until`, `count`, `bits_read`, or `bytes_read`
   --> $DIR/count_read_conflict.rs:33:10
    |
 33 | #[derive(DekuRead)]
@@ -38,7 +38,7 @@ error: conflicting: `read_all` cannot be used with `until`, count`, `bits_read`,
    |
    = note: this error originates in the derive macro `DekuRead` (in Nightly builds, run with -Z macro-backtrace for more info)
 
-error: conflicting: `read_all` cannot be used with `until`, count`, `bits_read`, or `bytes_read`
+error: conflicting: `read_all` cannot be used with `until`, `count`, `bits_read`, or `bytes_read`
   --> $DIR/count_read_conflict.rs:39:10
    |
 39 | #[derive(DekuRead)]
diff --git a/tests/test_compile/cases/seek_conflict.stderr b/tests/test_compile/cases/seek_conflict.stderr
index 0666f5e..d16a136 100644
--- a/tests/test_compile/cases/seek_conflict.stderr
+++ b/tests/test_compile/cases/seek_conflict.stderr
@@ -1,7 +1,5 @@
 error: conflicting: only one `seek` attribute can be used at one time
- --> tests/test_compile/cases/seek_conflict.rs:3:10
+ --> tests/test_compile/cases/seek_conflict.rs:6:13
   |
-3 | #[derive(DekuRead, Debug, PartialEq, Eq)]
-  |          ^^^^^^^^
-  |
-  = note: this error originates in the derive macro `DekuRead` (in Nightly builds, run with -Z macro-backtrace for more info)
+6 |     byte_a: u8,
+  |             ^^