Skip to content

Misleading error message with malformed turbofishes #54521

Closed
@atamis

Description

@atamis

I typoed the angle brackets when attempting turbofish.

fn main() {
    println!("{:?}", vec![1, 2, 3].into_iter().collect::<Vec<usize>>>());
}

(Playground)

I expected to see this happen: To get an error indicating that I had an extra closing
angle bracket after my turbofish, or that I had a mismatched delimiter.

Here is what happened instead:

Errors:

   Compiling playground v0.0.1 (/playground)
error: field expressions may not have generic arguments
 --> src/lib.rs:2:55
  |
2 |     println!("{:?}", vec![1, 2, 3].into_iter().collect::<Vec<usize>>>());
  |                                                       ^^^^^^^^^^^^^^

error: aborting due to previous error

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

This error message refers to the case when you attempt to use turbofish on a struct field
rather than a method or function, like struct.field::<usize>. However, this error message
is confusing to users because, if you look at the end of the collect call, there are parentheses,
and this looks like a correctly formed method call, which obscures the real error.

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lints

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions