Skip to content

refactor(bindgen): remove the dependency on itertools - #3408

Merged
emilio merged 2 commits into
rust-lang:mainfrom
AudaciousAxiom:refactor/remove-itertools
Jul 28, 2026
Merged

refactor(bindgen): remove the dependency on itertools#3408
emilio merged 2 commits into
rust-lang:mainfrom
AudaciousAxiom:refactor/remove-itertools

Conversation

@AudaciousAxiom

Copy link
Copy Markdown
Contributor

This proposes to slightly refactor the only use of itertools to be able to remove the dependency on it. Removing the dependency helps reduce the future maintenance burden (e.g., see #3407).

Closes #3407

Comment thread bindgen/ir/comp.rs
fields.extend(non_bitfields);
let raw_fields = raw_fields.by_ref();
while let Some(raw_field) =
raw_fields.next_if(|f| f.bitfield_width().is_none())

@AudaciousAxiom AudaciousAxiom Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses Peekable::next_if(), which wasn't available when this was written, but has been stable since 1.51.

View changes since the review

Comment thread bindgen/ir/comp.rs
@@ -496,22 +494,27 @@ where
// resulting fields. We introduce a scope here so that we can use
// `raw_fields` again after the `by_ref` iterator adaptor is dropped.
{

@AudaciousAxiom AudaciousAxiom Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This preserves the original additional scope even though I'm not sure it's actually needed: the tests pass just the same without it (and with a single .by_ref() call). Happy to remove it if it is indeed extraneous.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The by_ref is overall redundant. I opened #3410 for this.

@AudaciousAxiom
AudaciousAxiom marked this pull request as ready for review July 28, 2026 09:02
@AudaciousAxiom

Copy link
Copy Markdown
Contributor Author

r? @emilio

Comment thread bindgen/ir/comp.rs
while let Some(raw_field) =
raw_fields.next_if(|f| f.bitfield_width().is_some())
{
bitfields.push(raw_field);

@AudaciousAxiom AudaciousAxiom Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allocates all the bitfields at once instead of using an iterator: I expect there is relatively few of them, so I hope this is acceptable.

View changes since the review

@oscargus

Copy link
Copy Markdown

Also closes #3086

@emilio
emilio added this pull request to the merge queue Jul 28, 2026
@emilio emilio mentioned this pull request Jul 28, 2026
Merged via the queue into rust-lang:main with commit 25b2347 Jul 28, 2026
51 checks passed
@AudaciousAxiom
AudaciousAxiom deleted the refactor/remove-itertools branch July 28, 2026 13:24
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.

4 participants