Skip to content

Commit 8ee7953

Browse files
estebankdanlehmann
authored andcommitted
Add tests for overlapping non-contiguous bit ranges
1 parent e7690cb commit 8ee7953

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use arbitrary_int::u4;
12
use bitbybit::bitfield;
23

34
#[bitfield(u32, default = 0)]
@@ -6,4 +7,27 @@ struct Test {
67
invalid_range: u8,
78
}
89

9-
fn main() {}
10+
#[bitfield(u8)]
11+
struct Test {
12+
#[bits([0, 2, 4, 6], rw)]
13+
a: u4,
14+
#[bits([1, 3, 5, 7], rw)]
15+
b: u4,
16+
#[bit(4, rw)]
17+
c: bool,
18+
}
19+
20+
#[bitfield(u8)]
21+
struct Test2 {
22+
#[bits([0, 2, 4, 6], rw)]
23+
a: u4,
24+
#[bits([1, 2, 5, 7], rw)]
25+
b: u4,
26+
}
27+
28+
29+
fn main() {
30+
Test::builder().with_a(u4::new(1)).with_b(u4::new(1)).with_c(true).build();
31+
Test::builder().with_c(true).build();
32+
Test2::builder().with_a(u4::new(1)).with_b(u4::new(1)).build();
33+
}
Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
error: bitfield!: Field invalid_range has type u8, which doesn't match the number of bits (9) that are being used for it
2-
--> tests/no_compile/invalid_field_range.rs:6:20
2+
--> tests/no_compile/invalid_field_range.rs:7:20
33
|
4-
6 | invalid_range: u8,
4+
7 | invalid_range: u8,
55
| ^^
6+
7+
error[E0599]: no method named `with_c` found for struct `PartialTest<true, true, false>` in the current scope
8+
--> tests/no_compile/invalid_field_range.rs:30:59
9+
|
10+
10 | #[bitfield(u8)]
11+
| --------------- method `with_c` not found for this struct
12+
...
13+
30 | Test::builder().with_a(u4::new(1)).with_b(u4::new(1)).with_c(true).build();
14+
| ^^^^^^ method not found in `PartialTest<true, true, false>`
15+
|
16+
= note: the method was found for
17+
- `PartialTest<false, b, false>`
18+
help: one of the expressions' fields has a method of the same name
19+
|
20+
30 | Test::builder().with_a(u4::new(1)).with_b(u4::new(1)).value.with_c(true).build();
21+
| ++++++
22+
23+
error[E0599]: no method named `build` found for struct `PartialTest<false, false, true>` in the current scope
24+
--> tests/no_compile/invalid_field_range.rs:31:34
25+
|
26+
10 | #[bitfield(u8)]
27+
| --------------- method `build` not found for this struct
28+
...
29+
31 | Test::builder().with_c(true).build();
30+
| ^^^^^ method not found in `PartialTest<false, false, true>`
31+
|
32+
= note: the method was found for
33+
- `PartialTest<true, true, false>`
34+
35+
error[E0599]: no function or associated item named `builder` found for struct `Test2` in the current scope
36+
--> tests/no_compile/invalid_field_range.rs:32:12
37+
|
38+
20 | #[bitfield(u8)]
39+
| --------------- function or associated item `builder` not found for this struct
40+
...
41+
32 | Test2::builder().with_a(u4::new(1)).with_b(u4::new(1)).build();
42+
| ^^^^^^^ function or associated item not found in `Test2`
43+
|
44+
note: if you're trying to build a new `Test2`, consider using `Test2::new_with_raw_value` which returns `Test2`
45+
--> tests/no_compile/invalid_field_range.rs:21:8
46+
|
47+
21 | struct Test2 {
48+
| ^^^^^

0 commit comments

Comments
 (0)