Skip to content

Add #[must_use] to relevant generated methods - #141

Open
nicopap wants to merge 2 commits into
danlehmann:mainfrom
nicopap:fix-mustuse-lint
Open

nicopap wants to merge 2 commits into
danlehmann:mainfrom
nicopap:fix-mustuse-lint

Conversation

@nicopap

@nicopap nicopap commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Most methods on bitfields are without side effects, therefore it makes sense to mark them as #[must_use].

@nicopap

nicopap commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

I investigated the error messages on the failing build pipeline and I'm at a loss as to why it's not passing.

Locally, running the same command as on the action (cargo test --no-default-features --features defmt) I don't get any errors.

And it appears to run the trybuild stuff too.

Most methods on bitfields are without side effects, therefore it makes
sense to mark them as `#[must_use]`.

* This fixes danlehmann#140
* Since now, we get a warning on non-used return values on existing
  builder methods, we have to ignore some return types in the tests
* I added a `#![deny(clippy::must_use_candidate)]` to one of the tests
  to ensure no regression.
@danlehmann

Copy link
Copy Markdown
Owner

Thanks, I fixed the error messages on main. They were a result of a newer Rust compiler. Your patch now passes fine.

- Move the clippy::must_use_candidate enforcement into a dedicated library
  crate (bitbybit-compile-checks) and lint it explicitly in CI. The lint only
  applies to genuinely public items, and items inside integration-test binaries
  are never considered public, so the previous in-test guard in basic.rs was
  vacuous.
- The bitfield in the check crate exercises every generated method shape
  (plain/indexed getters and setters, ro/wo/rw fields, arbitrary-int fields,
  and a bitenum custom type), so dropping a #[must_use] from the macro fails it.
- CHANGELOG entry
@danlehmann

Copy link
Copy Markdown
Owner

Please take a look at #147 - I made some changes on top

@danlehmann

Copy link
Copy Markdown
Owner

@nicopap feel free to pick my additions - that way I can approve this patch and merge. I wasn't able to edit your PR directly

@nicopap

nicopap commented Aug 28, 2026

Copy link
Copy Markdown
Contributor Author

I pulled the changes from #147 into this PR now.

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.

bitfield macro triggers clippy::must_use_candidate lints since 2.0.1

2 participants