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

Account for shadowed bindings in E0599 method not found errors #123558

Open
estebank opened this issue Apr 6, 2024 · 1 comment
Open

Account for shadowed bindings in E0599 method not found errors #123558

estebank opened this issue Apr 6, 2024 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Apr 6, 2024

Code

fn main() {
    let x = Some(3);
    let y = vec![1, 2];
    if let Some(y) = x {
        y.push(y);
    }
}

Current output

error[E0599]: no method named `push` found for type `{integer}` in the current scope
 --> src/main.rs:5:11
  |
5 |         y.push(y);
  |           ^^^^ method not found in `{integer}`

Desired output

error[E0599]: no method named `push` found for type `{integer}` in the current scope
 --> src/main.rs:5:11
  |
5 |         y.push(y);
  |           ^^^^ method not found in `{integer}`
note: there's an earlier shadowed binding `y` of type `Vec<{integer}>` that *has* method `push` available
  |
3 |     let y = vec![1, 2];
  |         ^ `y` of type `Vec<{integer}>` that has method `push` defined earlier here
4 |     if let Some(y) = x {
  |                 ^ earlier `y` shadowed here with type `{integer}`

Rationale and extra context

Shadowed bindings can sometimes confuse the user as to why they don't have the expected type. Pointing out shadowed bindings in type and trait errors can help avoid that.

Other cases

E0308 would present similar situations.

Rust Version

rustc 1.78.0-nightly (3b1717c05 2024-03-10)

Anything else?

No response

@estebank estebank 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. D-papercut Diagnostics: An error or lint that needs small tweaks. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Apr 6, 2024
@surechen
Copy link
Contributor

@rustbot claim

surechen added a commit to surechen/rust that referenced this issue Apr 23, 2024
surechen added a commit to surechen/rust that referenced this issue May 20, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 20, 2024
Note for E0599 if shadowed bindings has the method.

implement rust-lang#123558

Use a visitor to find earlier shadowed bingings which has the method.

r? `@estebank`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue May 20, 2024
Note for E0599 if shadowed bindings has the method.

implement rust-lang#123558

Use a visitor to find earlier shadowed bingings which has the method.

r? ``@estebank``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue May 21, 2024
Rollup merge of rust-lang#124283 - surechen:fix_123558, r=estebank

Note for E0599 if shadowed bindings has the method.

implement rust-lang#123558

Use a visitor to find earlier shadowed bingings which has the method.

r? ``@estebank``
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 D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants