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

Typo suggestion for a variable with a name similar to struct fields #97240

Merged

Conversation

TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented May 21, 2022

closes #97133

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 21, 2022
@rust-highfive
Copy link
Collaborator

r? @compiler-errors

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 21, 2022
@Dylan-DPC
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 21, 2022

📌 Commit 42e9f2d has been approved by Dylan-DPC

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 21, 2022
@compiler-errors
Copy link
Member

Er, can I take some time to review this @Dylan-DPC?

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 21, 2022
@compiler-errors
Copy link
Member

Anyways, this looks mostly good, except is there a reason you only suggest if we have a matching field?

This is a case where we have a matching method, but local variable also matches:

struct Foo;

trait Config {
    fn config(self);
    fn something(self);
}

impl Config for Foo {
    fn config() {}

    fn something(self) {
        let cofig = 1;
        println!("{cofig}");
    }
}

What does the blessed tests look like with the suggestion moved to like line 500, where the old code would return?

|
help: you might have meant to use the available field
|
LL | println!("{self.config}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by comment: this probably shouldn't be emitted, as it won't compile.

Copy link
Member

@compiler-errors compiler-errors May 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that's a bit orthogonal to this diff, though. It might be possible to detect this case from HIR, but not related to the suggestion added here.

@TaKO8Ki, I would appreciate if you find some time to investigate suppressing this. Don't block this PR on that if it's more difficult than it seems -- if not immediately easy to fix, then could you file an issue and downgrade the suggestion from MachineApplicable to MaybeIncorrect? 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate if you find some time to investigate suppressing this. Don't block this PR on that if it's more difficult than it seems -- if not immediately easy to fix, then could you file an issue and downgrade the suggestion from MachineApplicable to MaybeIncorrect? 😅

Ok. I will investigate it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #97311. Can I work on this problem in a new PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sounds good.

@TaKO8Ki
Copy link
Member Author

TaKO8Ki commented May 21, 2022

@compiler-errors

Anyways, this looks mostly good, except is there a reason you only suggest if we have a matching field?

There are not any specific reasons. I will implement typo suggestions for all AssocSuggestion.

@compiler-errors
Copy link
Member

There are not any specific reasons. I will implement typo suggestions for all AssocSuggestion.

Sounds good. If there are too many false suggestions due to enabling it for the other AssocSuggestion, it may justify keeping it as it is now.

@TaKO8Ki
Copy link
Member Author

TaKO8Ki commented May 23, 2022

@compiler-errors
I implemented typo suggestions for all AssocSuggestion variants.

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented May 23, 2022

📌 Commit 39caed0 has been approved by compiler-errors

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 23, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request May 24, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97240 (Typo suggestion for a variable with a name similar to struct fields)
 - rust-lang#97289 (Lifetime variance fixes for clippy)
 - rust-lang#97290 (Turn on `fast_submodules` unconditionally)
 - rust-lang#97336 (typo)
 - rust-lang#97337 (Fix stabilization version of `Ipv6Addr::to_ipv4_mapped`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8d9f258 into rust-lang:master May 24, 2022
@rustbot rustbot added this to the 1.63.0 milestone May 24, 2022
@TaKO8Ki TaKO8Ki deleted the improve-errors-about-typos-on-variables branch May 24, 2022 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the error message of typos on variables that has the same name as struct fields
7 participants