Skip to content

{integer}..unresolved_ident suggests field access #131471

Closed
@crumblingstatue

Description

@crumblingstatue

Code

fn main() {
    let width = 10;
    // ...
    for _ in 0..w {
        
    }
}

Current output

error[E0425]: cannot find value `w` in this scope
 --> src/main.rs:4:17
  |
4 |     for _ in 0..w {
  |                 ^ not found in this scope
  |
help: you might have meant to write `.` instead of `..`
  |
4 -     for _ in 0..w {
4 +     for _ in 0.w {
  |

Desired output

error[E0425]: cannot find value `w` in this scope
 --> src/main.rs:4:17
  |
4 |     for _ in 0..w {
  |                 ^ not found in this scope
  |

Rationale and extra context

Since integer literals do not have fields, it's odd to suggest field access.
It just confuses the user, rather than helping.

Other cases

No response

Rust Version

rustc 1.83.0-nightly (6f4ae0f34 2024-10-08)
binary: rustc
commit-hash: 6f4ae0f34503601e54680a137c1db0b81b56cc3d
commit-date: 2024-10-08
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`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