Three problems with the code generated using bindgen

Situations
I use bindgen to try to generate an FFI of the kernel header file notifier.h oom.h, but there are several problems in the generated lib.rs, how should I deal with these problems?
Problems

error[E0277]: `[String; 2]` is not an iterator
    --> /root/.cargo/registry/src/mirrors.xfusion.com-7d95ac17e52a23da/bindgen-0.63.0/./lib.rs:1557:18
     |
1557 |                 .flat_map(|header| ["-include".into(), header.to_string()]),
     |                  ^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
     |
     = help: the trait `Iterator` is not implemented for `[String; 2]`
     = note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
     = note: required because of the requirements on the impl of `IntoIterator` for `[String; 2]`

error[E0277]: `[String; 2]` is not an iterator
    --> /root/.cargo/registry/src/mirrors.xfusion.com-7d95ac17e52a23da/bindgen-0.63.0/./lib.rs:1554:13
     |
1554 | /             options.input_headers
1555 | |                 [..options.input_headers.len().saturating_sub(1)]
1556 | |                 .iter()
1557 | |                 .flat_map(|header| ["-include".into(), header.to_string()]),
     | |___________________________________________________________________________^ expected an implementor of trait `IntoIterator`
     |
     = note: the trait bound `[String; 2]: IntoIterator` is not satisfied
     = note: required because of the requirements on the impl of `IntoIterator` for `[String; 2]`
help: consider borrowing here
     |
1554 |             &options.input_headers
1555 |                 [..options.input_headers.len().saturating_sub(1)]
1556 |                 .iter()
1557 |                 .flat_map(|header| ["-include".into(), header.to_string()]),
     |

error[E0277]: `[&mut regex_set::RegexSet; 27]` is not an iterator
    --> /root/.cargo/registry/src/mirrors.xfusion.com-7d95ac17e52a23da/bindgen-0.63.0/./lib.rs:2164:64
     |
2164 |         for regex_set in self.abi_overrides.values_mut().chain(regex_sets) {
     |                                                                ^^^^^^^^^^
     |                                                                |
     |                                                                expected an implementor of trait `IntoIterator`
     |                                                                help: consider borrowing here: `&regex_sets`
     |
     = note: the trait bound `[&mut regex_set::RegexSet; 27]: IntoIterator` is not satisfied
     = note: required because of the requirements on the impl of `IntoIterator` for `[&mut regex_set::RegexSet; 27]`

error[E0277]: `[&mut regex_set::RegexSet; 27]` is not an iterator
    --> /root/.cargo/registry/src/mirrors.xfusion.com-7d95ac17e52a23da/bindgen-0.63.0/./lib.rs:2164:26
     |
2164 |         for regex_set in self.abi_overrides.values_mut().chain(regex_sets) {
     |                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ borrow the array with `&` or call `.iter()` on it to iterate over it
     |
     = help: the trait `Iterator` is not implemented for `[&mut regex_set::RegexSet; 27]`
     = note: arrays are not iterators, but slices like the following are: `&[1, 2, 3]`
     = note: required because of the requirements on the impl of `Iterator` for `std::iter::Chain<std::collections::hash_map::ValuesMut<'_, function::Abi, regex_set::RegexSet>, [&mut regex_set::RegexSet; 27]>`
     = note: required because of the requirements on the impl of `IntoIterator` for `std::iter::Chain<std::collections::hash_map::ValuesMut<'_, function::Abi, regex_set::RegexSet>, [&mut regex_set::RegexSet; 27]>`
     = note: required by `into_iter`

error[E0277]: `[&str; 2]` is not an iterator
    --> /root/.cargo/registry/src/mirrors.xfusion.com-7d95ac17e52a23da/bindgen-0.63.0/./lib.rs:2727:22
     |
2727 |             cmd.args(["--config-path", path]);
     |                      ^^^^^^^^^^^^^^^^^^^^^^^
     |                      |
     |                      expected an implementor of trait `IntoIterator`
     |                      help: consider borrowing here: `&["--config-path", path]`
     |
     = note: the trait bound `[&str; 2]: IntoIterator` is not satisfied
     = note: required because of the requirements on the impl of `IntoIterator` for `[&str; 2]`

error: aborting due to 5 previous errors

For more information about this error, try `rustc --explain E0277`.
error: could not compile `bindgen`

It looks like your toolchain is missing impl IntoIterator for [T; N]. What's your Rust version and the edition of your crate?

2 Likes

okay, there are information about them.
rustc 1.51.0
[build-dependencies]
bindgen = "0.63.0"

Your Rust version is too old. You can see in the link that @Cerber-Ursi posted that the impl that you're missing is available starting from Rust 1.53.

2 Likes

ok
thank you!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.