Skip to content

Missing parentheses for range leads to misleading help suggestion #102396

Closed
@Rageking8

Description

@Rageking8

Given the following code: link

fn main() { 
    for i in 1..11.rev() {
        println!("{i}");
    }
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0689]](https://doc.rust-lang.org/nightly/error-index.html#E0689): can't call method `rev` on ambiguous numeric type `{integer}`
 --> src/main.rs:2:20
  |
2 |     for i in 1..11.rev() {
  |                    ^^^
  |
help: you must specify a concrete type for this numeric value, like `i32`
  |
2 |     for i in 1..11_i32.rev() {
  |                 ~~~~~~

For more information about this error, try `rustc --explain E0689`.
error: could not compile `playground` due to previous error

Ideally the output should something like this:

Compiling playground v0.0.1 (/playground)
error[[E0689]](https://doc.rust-lang.org/nightly/error-index.html#E0689): can't call method `rev` on ambiguous numeric type `{integer}`
 --> src/main.rs:2:20
  |
2 |     for i in 1..11.rev() {
  |                    ^^^
  |
help: you must surround the range in parentheses to call the `rev` function
  |
2 |     for i in (1..11).rev() {
  |              +     +

For more information about this error, try `rustc --explain E0689`.
error: could not compile `playground` due to previous error

@rustbot label +D-confusing +D-invalid-suggestion

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions