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 help message for ambiguous numeric type in for loop over a range #51634

Closed
HugoArts opened this issue Jun 19, 2018 · 0 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug.

Comments

@HugoArts
Copy link

The following code (playground):

for i in 0..100 {
    println!("{}", i.pow(2));
}

fails to compile. The error message correctly points to the problem but the help message's suggestion is a syntax error:

error[E0689]: can't call method `pow` on ambiguous numeric type `{integer}`
 --> src/main.rs:3:26
  |
3 |         println!("{}", i.pow(2));
  |                          ^^^
help: you must specify a type for this binding, like `i32`
  |
2 |     for i: i32 in 0..100 {
  |         ^^^^^^

Following the suggestion leads to another compile error (missing 'in' in for loop). Usually the correct solution in this case is to add the type to the range (0i32..100).

@HugoArts HugoArts changed the title misleading help message for ambiguous numeric type in for loop over range misleading help message for ambiguous numeric type in for loop over a range Jun 19, 2018
@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. labels Jun 19, 2018
bors added a commit that referenced this issue Jun 22, 2018
Don't suggest incorrect syntax

Fix #51634.
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 C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants