Repository: rust-bakery/nom (language: rust)

Issue:
strict trait bounds on nom::multi::fill
Hi,

I was trying to use the `nom::multi::fill` fn with other `nom` parsers and found that it failed to compose in some cases due to the trait bounds on the `fill` function. 

## Prerequisites
- Rust version : `rustc 1.58.1 (db9d1b20b 2022-01-20)`
- nom version : `7.1.1`
- nom compilation features used: `default`

## Test case
```rust
#[test]
fn issue_x_looser_fill_bounds() {
  use nom::{
    bytes::streaming::tag, character::streaming::digit1, error_position, multi::fill,
    sequence::terminated,
  };

  fn fill_pair(i: &[u8]) -> IResult<&[u8], [&[u8]; 2]> {
    let mut buf = [&[][..], &[][..]];
    let (i, _) = fill(terminated(digit1, tag(",")), &mut buf)(i)?;
    Ok((i, buf))
  }

  assert_eq!(
    fill_pair(b"123,456,"),
    Ok((&b""[..], [&b"123"[..], &b"456"[..]]))
  );
  assert_eq!(
    fill_pair(b"123,456,789"),
    Ok((&b"789"[..], [&b"123"[..], &b"456"[..]]))
  );
  assert_eq!(
    fill_pair(b"123,,"),
    Err(Err::Error(error_position!(&b","[..], ErrorKind::Digit)))
  );
}
```
The following test cases fails with the following

```txt
error[E0277]: expected a `Fn<(_,)>` closure, found `impl FnMut(_)-> Result<(_, _), nom::Err<_>>`
   --> tests/issues.rs:227:23
    |
227 |     let (i, _) = fill(terminated(digit1, tag(",")), &mut buf)(i)?;
    |                  ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected an `Fn<(_,)>` closure, found `impl FnMut(_)-> Result<(_, _), nom::Err<_>>`
    |                  |
    |                  required by a bound introduced by this call
    |
    = help: the trait `Fn<(_,)>` is not implemented for `impl FnMut(_)-> Result<(_, _), nom::Err<_>>`
note: required by a bound in `fill`
   --> /home/mustafa/git/nom/src/multi/mod.rs:579:6
    |
579 |   F: Fn(I) -> IResult<I, O, E> + 'a,
    |      ^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `fill`

For more information about this error, try `rustc --explain E0277`.
```
Changing the bounds on `F` in `nom::multi::fill` to be `nom::Parser` fixes this test case.


Discussion / hints:

Fix patch:
diff --git a/src/multi/mod.rs b/src/multi/mod.rs
index dff28e60f..ce23ae993 100644
--- a/src/multi/mod.rs
+++ b/src/multi/mod.rs
@@ -620,10 +620,10 @@ where
 /// assert_eq!(parser(""), Err(Err::Error(Error::new("", ErrorKind::Tag))));
 /// assert_eq!(parser("abcabcabc"), Ok(("abc", ["abc", "abc"])));
 /// ```
-pub fn fill<'a, I, O, E, F>(f: F, buf: &'a mut [O]) -> impl FnMut(I) -> IResult<I, (), E> + 'a
+pub fn fill<'a, I, O, E, F>(mut f: F, buf: &'a mut [O]) -> impl FnMut(I) -> IResult<I, (), E> + 'a
 where
   I: Clone + PartialEq,
-  F: Fn(I) -> IResult<I, O, E> + 'a,
+  F: Parser<I, O, E> + 'a,
   E: ParseError<I>,
 {
   move |i: I| {
@@ -631,7 +631,7 @@ where
 
     for elem in buf.iter_mut() {
       let input_ = input.clone();
-      match f(input_) {
+      match f.parse(input_) {
         Ok((i, o)) => {
           *elem = o;
           input = i;


Test patch:
diff --git a/tests/issues.rs b/tests/issues.rs
index fde900774..978437092 100644
--- a/tests/issues.rs
+++ b/tests/issues.rs
@@ -217,6 +217,32 @@ fn issue_1282_findtoken_char() {
 }
 
 #[test]
+fn issue_x_looser_fill_bounds() {
+  use nom::{
+    bytes::streaming::tag, character::streaming::digit1, error_position, multi::fill,
+    sequence::terminated,
+  };
+
+  fn fill_pair(i: &[u8]) -> IResult<&[u8], [&[u8]; 2]> {
+    let mut buf = [&[][..], &[][..]];
+    let (i, _) = fill(terminated(digit1, tag(",")), &mut buf)(i)?;
+    Ok((i, buf))
+  }
+
+  assert_eq!(
+    fill_pair(b"123,456,"),
+    Ok((&b""[..], [&b"123"[..], &b"456"[..]]))
+  );
+  assert_eq!(
+    fill_pair(b"123,456,789"),
+    Ok((&b"789"[..], [&b"123"[..], &b"456"[..]]))
+  );
+  assert_eq!(
+    fill_pair(b"123,,"),
+    Err(Err::Error(error_position!(&b","[..], ErrorKind::Digit)))
+  );
+}
+
 fn issue_1459_clamp_capacity() {
   use nom::character::complete::char;