Repository: rust
Issue: Inspect does not feed properly into map
Labels: A-type-system,A-diagnostics,A-inference,C-bug,D-confusing,T-types

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

```rust
pub fn compile<S>(filenames: &[S]) -> String
  where
      S: AsRef<str> + AsRef<Path> + Display,
  {
      let source_strings: Vec<_> = filenames
          .iter()
          .inspect(file::validate_filename)
          .map(file::open_file)
          .map(byte_reader::read_bytes)
          .collect();

     // -- snip
  }
```

I expected to see this happen: For the code to compile, and for the inspect to not break the iterator like it does. It works when I write it like this:

```rust
pub fn compile<S>(filenames: &[S]) -> String
  where
      S: AsRef<str> + AsRef<Path> + Display,
  {
      let source_strings: Vec<_> = filenames
          .iter()
          .inspect(|f| file::validate_filename(f))
          .map(file::open_file)
          .map(byte_reader::read_bytes)
          .collect();

     // -- snip
  }
```

Instead, this happened: It gives me a compiler error:

```
error[E0599]: no method named `map` found for struct `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>` in the current scope
    --> src/compile.rs:12:10
     |
12   |         .map(file::open_file)
     |          ^^^ method not found in `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>`
     |
    ::: /Users/rrampersad/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/mod.rs:2743:1
     |
2743 | pub struct Inspect<I, F> {
     | ------------------------ doesn't satisfy `_: Iterator`
     |
     = note: the method `map` exists but the following trait bounds were not satisfied:
             `<fn(&&S) {validate_filename::<&&S>} as FnOnce<(&&S,)>>::Output = ()`
             which is required by `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`
             `fn(&&S) {validate_filename::<&&S>}: FnMut<(&&S,)>`
             which is required by `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`
             `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`
             which is required by `&mut Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`

error[E0599]: no method named `map` found for struct `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>` in the current scope
    --> src/compile.rs:12:10
     |
12   |         .map(file::open_file)
     |          ^^^ method not found in `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>`
     |
    ::: /Users/rrampersad/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/iter/adapters/mod.rs:2743:1
     |
2743 | pub struct Inspect<I, F> {
     | ------------------------ doesn't satisfy `_: Iterator`
     |
     = note: the method `map` exists but the following trait bounds were not satisfied:
             `<fn(&&S) {validate_filename::<&&S>} as FnOnce<(&&S,)>>::Output = ()`
             which is required by `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`
             `fn(&&S) {validate_filename::<&&S>}: FnMut<(&&S,)>`
             which is required by `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`
             `Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`
             which is required by `&mut Inspect<std::slice::Iter<'_, S>, fn(&&S) {validate_filename::<&&S>}>: Iterator`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `joos_1w_compiler`

To learn more, run the command again with --verbose.
```

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.49.0 (e1884a8e3 2020-12-29)
binary: rustc
commit-hash: e1884a8e3c3e813aada8254edfa120e85bf5ffca
commit-date: 2020-12-29
host: x86_64-apple-darwin
release: 1.49.0
```

<details><summary>Signature of `validate_filename`</summary>
<p>
```
pub fn validate_filename<S>(filename: S)
where
    S: AsRef<str> + Display,
{ ... }
```
</p>
</details>