Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion bitbybit/tests/no_compile/invalid_field_range.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use arbitrary_int::u4;
use bitbybit::bitfield;

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

fn main() {}
#[bitfield(u8)]
struct Test {
#[bits([0, 2, 4, 6], rw)]
a: u4,
#[bits([1, 3, 5, 7], rw)]
b: u4,
#[bit(4, rw)]
c: bool,
}

#[bitfield(u8)]
struct Test2 {
#[bits([0, 2, 4, 6], rw)]
a: u4,
#[bits([1, 2, 5, 7], rw)]
b: u4,
}


fn main() {
Test::builder().with_a(u4::new(1)).with_b(u4::new(1)).with_c(true).build();
Test::builder().with_c(true).build();
Test2::builder().with_a(u4::new(1)).with_b(u4::new(1)).build();
}
47 changes: 45 additions & 2 deletions bitbybit/tests/no_compile/invalid_field_range.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
error: bitfield!: Field invalid_range has type u8, which doesn't match the number of bits (9) that are being used for it
--> tests/no_compile/invalid_field_range.rs:6:20
--> tests/no_compile/invalid_field_range.rs:7:20
|
6 | invalid_range: u8,
7 | invalid_range: u8,
| ^^

error[E0599]: no method named `with_c` found for struct `PartialTest<true, true, false>` in the current scope
--> tests/no_compile/invalid_field_range.rs:30:59
|
10 | #[bitfield(u8)]
| --------------- method `with_c` not found for this struct
...
30 | Test::builder().with_a(u4::new(1)).with_b(u4::new(1)).with_c(true).build();
| ^^^^^^ method not found in `PartialTest<true, true, false>`
|
= note: the method was found for
- `PartialTest<false, b, false>`
help: one of the expressions' fields has a method of the same name
|
30 | Test::builder().with_a(u4::new(1)).with_b(u4::new(1)).value.with_c(true).build();
| ++++++

error[E0599]: no method named `build` found for struct `PartialTest<false, false, true>` in the current scope
--> tests/no_compile/invalid_field_range.rs:31:34
|
10 | #[bitfield(u8)]
| --------------- method `build` not found for this struct
...
31 | Test::builder().with_c(true).build();
| ^^^^^ method not found in `PartialTest<false, false, true>`
|
= note: the method was found for
- `PartialTest<true, true, false>`

error[E0599]: no function or associated item named `builder` found for struct `Test2` in the current scope
--> tests/no_compile/invalid_field_range.rs:32:12
|
20 | #[bitfield(u8)]
| --------------- function or associated item `builder` not found for this struct
...
32 | Test2::builder().with_a(u4::new(1)).with_b(u4::new(1)).build();
| ^^^^^^^ function or associated item not found in `Test2`
|
note: if you're trying to build a new `Test2`, consider using `Test2::new_with_raw_value` which returns `Test2`
--> tests/no_compile/invalid_field_range.rs:21:8
|
21 | struct Test2 {
| ^^^^^
Loading