Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misleading error message with malformed turbofishes #54521

Closed
atamis opened this issue Sep 24, 2018 · 3 comments
Closed

Misleading error message with malformed turbofishes #54521

atamis opened this issue Sep 24, 2018 · 3 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@atamis
Copy link

atamis commented Sep 24, 2018

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.

@csmoe csmoe added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 24, 2018
@atamis
Copy link
Author

atamis commented Sep 24, 2018

For reference, this is how the compiler responds to the same typo elsewhere.

fn main() {
    println!("{:?}", Vec::<usize>>::new());
}

(Playground)

   Compiling playground v0.0.1 (/playground)
error[E0423]: expected value, found struct `Vec`
 --> src/main.rs:2:22
  |
2 |     println!("{:?}", Vec::<usize>>::new());
  |                      ^^^^^^^^^^^^ did you mean `Vec { /* fields */ }`?

error[E0425]: cannot find function `new` in the crate root
 --> src/main.rs:2:37
  |
2 |     println!("{:?}", Vec::<usize>>::new());
  |                                     ^^^ not found in the crate root

@mrcnski
Copy link
Contributor

mrcnski commented Jan 16, 2019

Just ran into this. Weird/confusing/unhelpful error message -- the real problem is an extra delimiter as you said.

@estebank
Copy link
Contributor

estebank commented Jan 21, 2019

The opposite problem should also be handled, probably as part of a separate PR: vec![1, 2, 3].into_iter().collect::<Vec<usize>())


Created #57819 to track this case.

@davidtwco davidtwco self-assigned this Jan 21, 2019
Centril added a commit to Centril/rust that referenced this issue Jan 23, 2019
Add error for trailing angle brackets.

Fixes rust-lang#54521.

This PR adds a error (and accompanying machine applicable
suggestion) for trailing angle brackets on function calls with a
turbofish.

r? @estebank
@bors bors closed this as completed in b5447b5 Jan 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

5 participants