Skip to content

Add levenshtein distance based suggestions everywhere #30197

Open

Description

@Manishearth

Currently, we suggest typo fixes in case of function calls, locals, and field accesses. So, both the marked lines below will suggest the correct fix:

struct A {foo: u8}
fn main() {
    let x = A {foo: 1};
    x.fob; // here
    let aaaaaaa=1;
    let z = aaaaaab; // here
}

However, this is not the case for imports, crates, and inline paths. We should fix this.

This is probably not an easy bug, but should be fun. Basically you need to look for the source of the "could not find X" error, and do something similar to

fn find_best_match_for_name(&mut self, name: &str) -> SuggestionType {

@apasel422 @Wafflespeanut want to work on this?

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
    on Dec 4, 2015
  2. self-assigned this
    on Dec 8, 2015
  3. Manishearth commented on Dec 8, 2015

    @Manishearth
    MemberAuthor

    Go ahead!

  4. added a commit that references this issue on Dec 23, 2015
  5. mitaa commented on Feb 27, 2016

    @mitaa
    Contributor

    I was surprised that I didn't get a suggestion here

    fn main() {
        "".is_emtpy();
    }
  6. mitaa commented on Feb 27, 2016

    @mitaa
    Contributor

    is_empty? (p and t are flipped)

  7. Manishearth commented on Feb 27, 2016

    @Manishearth
    MemberAuthor

    No, we just don't handle methods.

  8. cramertj commented on May 25, 2016

    @cramertj
    Member

    Did crate and inline path support ever get added for this? If not, I'd be interested in giving it a shot.

  9. Manishearth commented on May 25, 2016

    @Manishearth
    MemberAuthor

    I don't think so. Go ahead!

  10. nikhilshagri commented on Jul 10, 2016

    @nikhilshagri
    Contributor

    @Manishearth can I pick this up if nobody else is working on it?

  11. Manishearth commented on Jul 10, 2016

    @Manishearth
    MemberAuthor

    Sure!

  12. 20 remaining items

  13. ConnorGray commented on May 2, 2017

    @ConnorGray

    Okay, thanks for the clarification. And thanks anyway. I'm still wading through it, and I think I've made some progress understanding nonetheless.

  14. laumann commented on Aug 19, 2017

    @laumann

    Hi! Is anyone working on adding suggestions for method names (re @mitaa's is_emtpy() example)? I have a patch that I wrote some time ago that implements this, but if someone else is working on it I don't want to get in the way.

  15. laumann commented on Sep 26, 2017

    @laumann

    If @petrochenkov's list is being kept up-to-date, I think the "method calls" point can be crossed off.

  16. petrochenkov commented on Sep 26, 2017

    @petrochenkov
    Contributor

    @laumann
    Updated the list.
    Thanks for working on this.

  17. laumann commented on Sep 26, 2017

    @laumann

    @petrochenkov Happy to help :-)

    I considered looking into suggestions for "Lifetime and label names" next - that sounds like it should be more or less straight-forward...

  18. petrochenkov commented on Oct 3, 2017

    @petrochenkov
    Contributor

    @laumann
    It should be straightforward, but note that with #44524 typos in lifetimes will be impossible by definition (every typo becomes a new lifetime, modulo some corner cases).

  19. added a commit that references this issue on Oct 13, 2017
  20. steveklabnik commented on Dec 25, 2018

    @steveklabnik
    Contributor

    Triage: do we plan on doing more of this? I'm not sure.

  21. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.P-lowLow priorityT-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