Repository: rust
Issue: Confusing and big error when misusing function instead of function call in iterator chain
Labels: C-enhancement,A-diagnostics,T-compiler

I've accidentally used a function (`String::from`) instead of a function call (`String::from("...")`) and the error was hard to read. Maybe it can be improved. ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=a10d7c3db979164ae8323aea36721754))

<details><summary>Code</summary>
<p>

```rust
fn test(media: &str) {
    std::iter::once((
        String::from, // <-- I've meant `String::from("...")`
        serde_json::Value::String(String::from("document")),
    ))
    .chain(
        std::iter::once((
            String::from("media"),
            serde_json::Value::String(media.to_owned()),
        ))
        .chain(
            Some("caption")
                .iter()
                .map(serde_json::to_value)
                .map(Result::unwrap)
                .map(|v| (String::from("caption"), v))
                .chain(
                    Some("parse_mode")
                        .iter()
                        .map(serde_json::to_value)
                        .map(Result::unwrap)
                        .map(|v| (String::from("parse_mode"), v)),
                ),
        ),
    )
    .collect::<Vec<_>>();
}
```

</p>
</details>

<details><summary>Error</summary>
<p>

(this error is from `1.51.0-nightly (2021-01-30 04caa632dd10c2bf64b6)`, previous compiler versions produce similar errors)

```
error[E0271]: type mismatch resolving `<std::iter::Chain<std::iter::Once<(std::string::String, Value)>, std::iter::Chain<std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:18:26: 18:58]>, std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:24:34: 24:69]>>> as IntoIterator>::Item == (fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)`
 --> src/lib.rs:8:10
  |
8 |         .chain(
  |          ^^^^^ expected struct `std::string::String`, found fn item
  |
  = note: expected type `(std::string::String, Value)`
            found tuple `(fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)`

error[E0599]: the method `collect` exists for struct `std::iter::Chain<std::iter::Once<(fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)>, std::iter::Chain<std::iter::Once<(std::string::String, Value)>, std::iter::Chain<std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:18:26: 18:58]>, std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:24:34: 24:69]>>>>`, but its trait bounds were not satisfied
  --> src/lib.rs:28:10
   |
28 |           .collect(),
   |            ^^^^^^^ method cannot be called on `std::iter::Chain<std::iter::Once<(fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)>, std::iter::Chain<std::iter::Once<(std::string::String, Value)>, std::iter::Chain<std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:18:26: 18:58]>, std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:24:34: 24:69]>>>>` due to unsatisfied trait bounds
   |
   = note: the following trait bounds were not satisfied:
           `<std::iter::Chain<std::iter::Once<(std::string::String, Value)>, std::iter::Chain<std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:18:26: 18:58]>, std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:24:34: 24:69]>>> as Iterator>::Item = (fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)`
           which is required by `std::iter::Chain<std::iter::Once<(fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)>, std::iter::Chain<std::iter::Once<(std::string::String, Value)>, std::iter::Chain<std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:18:26: 18:58]>, std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:24:34: 24:69]>>>>: Iterator`
           `std::iter::Chain<std::iter::Once<(fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)>, std::iter::Chain<std::iter::Once<(std::string::String, Value)>, std::iter::Chain<std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:18:26: 18:58]>, std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:24:34: 24:69]>>>>: Iterator`
           which is required by `&mut std::iter::Chain<std::iter::Once<(fn(_) -> std::string::String {<std::string::String as From<_>>::from}, Value)>, std::iter::Chain<std::iter::Once<(std::string::String, Value)>, std::iter::Chain<std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:18:26: 18:58]>, std::iter::Map<std::iter::Map<std::iter::Map<std::option::Iter<'_, &str>, fn(&&str) -> std::result::Result<Value, serde_json::Error> {to_value::<&&str>}>, fn(std::result::Result<Value, serde_json::Error>) -> Value {std::result::Result::<Value, serde_json::Error>::unwrap}>, [closure@src/lib.rs:24:34: 24:69]>>>>: Iterator`
```

</p>
</details>