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

{integer}..unresolved_ident suggests field access #131471

Closed
crumblingstatue opened this issue Oct 9, 2024 · 1 comment · Fixed by #131537
Closed

{integer}..unresolved_ident suggests field access #131471

crumblingstatue opened this issue Oct 9, 2024 · 1 comment · Fixed by #131537
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@crumblingstatue
Copy link
Contributor

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

@crumblingstatue crumblingstatue added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 9, 2024
@crumblingstatue crumblingstatue changed the title Unresolved identifiers in exclusive ranges of {integer} literals suggest field access {integer}..unresolved_ident suggests field access Oct 9, 2024
@jieyouxu jieyouxu added D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` labels Oct 10, 2024
@hirschenberger
Copy link
Contributor

I'm working on this

hirschenberger added a commit to hirschenberger/rust that referenced this issue Oct 11, 2024
Fixes rust-lang#131471 by checking if the range-start is a literal.
hirschenberger added a commit to hirschenberger/rust that referenced this issue Oct 12, 2024
Fixes rust-lang#131471 by checking if the range-start is a literal.
hirschenberger added a commit to hirschenberger/rust that referenced this issue Oct 12, 2024
Fixes rust-lang#131471 by checking if the range-start is a literal.
hirschenberger added a commit to hirschenberger/rust that referenced this issue Oct 18, 2024
Fixes rust-lang#131471 by checking if the range-start is a literal.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 18, 2024
…errors

Fix range misleading field access

Fixes rust-lang#131471 by checking if the range-start is a literal.
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Oct 19, 2024
…errors

Fix range misleading field access

Fixes rust-lang#131471 by checking if the range-start is a literal.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 19, 2024
…errors

Fix range misleading field access

Fixes rust-lang#131471 by checking if the range-start is a literal.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 19, 2024
…errors

Fix range misleading field access

Fixes rust-lang#131471 by checking if the range-start is a literal.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Oct 19, 2024
…errors

Fix range misleading field access

Fixes rust-lang#131471 by checking if the range-start is a literal.
@bors bors closed this as completed in 8f2273e Oct 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 19, 2024
Rollup merge of rust-lang#131537 - hirschenberger:master, r=compiler-errors

Fix range misleading field access

Fixes rust-lang#131471 by checking if the range-start is a literal.
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 A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants