Skip to content

Checker:: Execute levenshtein before other context checking #39291

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

Merged
merged 1 commit into from
Apr 29, 2017

Conversation

Freyskeyd
Copy link
Contributor

@Freyskeyd Freyskeyd commented Jan 25, 2017

As explain here i think it's better to check for a miss typing before checking context dependent help.

struct Handle {}

struct Something {
     handle: Handle
}

fn main() {
     let handle: Handle = Handle {};

     let s: Something = Something {
         // Checker detect an error and propose a solution with `Handle { /* ... */ }`
         // but it's a miss typing of `handle`
         handle: Handle 
    };
}

Ping: @nagisa for #39226

Signed-off-by: Freyskeyd simon.paitrault@gmail.com

@rust-highfive
Copy link
Contributor

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @arielb1 (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@nagisa
Copy link
Member

nagisa commented Jan 25, 2017

Needs a test at the very least.

@nagisa
Copy link
Member

nagisa commented Jan 25, 2017

Question: does the other suggestion fire at all anymore?

e.g. I would expect rustc to report both hints in case of say:

struct Handle { field: () }
struct Something { handle: Handle }
fn x(handl: Handle) -> Something { 
     Something { handle: Handle } // could be both forgotten initialization and typo, and Handle can be initialized, because its interior not private in this context.
}

@Freyskeyd
Copy link
Contributor Author

Mmh i don't think it will check for both hints. I will check if i can do it.

@petrochenkov
Copy link
Contributor

r- from me
the point of #39226 is that suggestion Handle { /* fields */ } is unusable due to private fields, so the context dependent help should perform field privacy check.
Prioritizing semi-random Levenshtein over manually crafted help seems like a bad idea in general.

@petrochenkov
Copy link
Contributor

Showing all applicable labels is an alternative too, but I'd like to see first how the result looks visually.

@mrhota
Copy link
Contributor

mrhota commented Feb 23, 2017

@Freyskeyd ping. what's the story here?

@Freyskeyd
Copy link
Contributor Author

hi @mrhota, I didn't work on it for a while (no time for the moment).

I can close this PR if it's a problem.

@arielb1
Copy link
Contributor

arielb1 commented Mar 7, 2017

@bors r=nrc

You are more familiar with this code.

@bors
Copy link
Collaborator

bors commented Mar 7, 2017

📌 Commit 3d38dbd has been approved by nrc

@bors
Copy link
Collaborator

bors commented Mar 7, 2017

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Collaborator

bors commented Mar 7, 2017

📌 Commit 3d38dbd has been approved by nrc

@bors
Copy link
Collaborator

bors commented Mar 9, 2017

🔒 Merge conflict

@Freyskeyd Freyskeyd force-pushed the check_context_E0423 branch 3 times, most recently from a4b67d3 to eece90f Compare March 9, 2017 13:22
@bors
Copy link
Collaborator

bors commented Mar 12, 2017

☔ The latest upstream changes (presumably #40455) made this pull request unmergeable. Please resolve the merge conflicts.

@Freyskeyd Freyskeyd force-pushed the check_context_E0423 branch 3 times, most recently from 46d4f1a to dc56bb1 Compare March 13, 2017 08:29
@alexcrichton
Copy link
Member

@Freyskeyd gah sorry for the delay here!

It looks like there's some errors on Travis though that would prevent this from landing?

@leoyvens
Copy link
Contributor

Is this supposed to be approved? I think @arielb1 meant to r? nrc rather than r=nrc

@arielb1
Copy link
Contributor

arielb1 commented Apr 13, 2017

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned arielb1 Apr 13, 2017
@Mark-Simulacrum Mark-Simulacrum added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 14, 2017
@carols10cents carols10cents 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-review Status: Awaiting review from the assignee but also interested parties. labels Apr 17, 2017
@carols10cents
Copy link
Member

Yeah, looks like there are some test failures: https://travis-ci.org/rust-lang/rust/jobs/210479172#L4366

Let us know if you need any help @Freyskeyd!

@Freyskeyd
Copy link
Contributor Author

@carols10cents I will make an update this week. I will let you know if I need some help :)

thank's!

@Freyskeyd Freyskeyd force-pushed the check_context_E0423 branch 4 times, most recently from 0f3dbd7 to c487396 Compare April 19, 2017 12:38
Copy link
Contributor Author

@Freyskeyd Freyskeyd left a comment

Choose a reason for hiding this comment

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

Can I have your opinion on the reference modification please? cc @carols10cents

@@ -5,6 +5,7 @@ error[E0423]: expected value, found struct `Z`
| ^
| |
| did you mean `Z { /* fields */ }`?
| did you mean `S`?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's unrevelante here. Right?

Copy link
Member

Choose a reason for hiding this comment

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

Are you asking if it's ok that your code change changes these suggestions? I'm not sure :-/ since nrc is on paternity leave right now... @jonathandturner are you the next best person to help out around error message suggestions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I'm asking if it's ok to update that part of suggestion or not. We keep both suggest but is it valid to tell user that, maybe, he misstyped it?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's ok, but Levenshtein suggestions should probably be turned off globally for single-letter identifiers (not necessarily in this PR).

| ^^^ did you mean `Bar`?
| ^^^
| |
| not found in this scope
Copy link
Contributor

Choose a reason for hiding this comment

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

Fall-back labels should not be reported if any other labels are reported.

Copy link
Member

Choose a reason for hiding this comment

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

Hi @petrochenkov, could you clarify a bit on how @Freyskeyd would fix this so that fall-back labels aren't reported?

Copy link
Contributor

Choose a reason for hiding this comment

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

// Try Levenshtein if nothing else worked.
if let Some(candidate) = this.lookup_typo_candidate(path, ns, is_expected) {
err.span_label(ident_span, &format!("did you mean `{}`?", candidate));
// return err;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you also remove this return instead of commenting it out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@petrochenkov Yep, I just let it here to validate behavior with you.

@arielb1
Copy link
Contributor

arielb1 commented Apr 25, 2017

ping @petrochenkov & @Freyskeyd - making sure this PR doesn't disappear.

@Freyskeyd
Copy link
Contributor Author

@arielb1 I'm working on it^^

@Freyskeyd Freyskeyd force-pushed the check_context_E0423 branch from c487396 to 75b550d Compare April 25, 2017 10:33
@petrochenkov petrochenkov assigned petrochenkov and unassigned nrc Apr 25, 2017
@Freyskeyd Freyskeyd force-pushed the check_context_E0423 branch 3 times, most recently from 76e3faa to 5379203 Compare April 28, 2017 15:00
// Fallback label.
err.span_label(base_span, &fallback_label);
if err.span.span_labels().is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Freyskeyd
IIRC, span_labels().is_empty() had quirks and didn't work as expected.
From the tests it looks like it still doesn't work.
You can just set some boolean flag if Levenshtein worked and check it here.

@petrochenkov
Copy link
Contributor

@Freyskeyd
GitHub doesn't seem to send notifications on rebases, so I missed the update, sorry.
Could you leave some comment here after the next update? I'll r+ immediately then.

Signed-off-by: Freyskeyd <simon.paitrault@gmail.com>
@Freyskeyd Freyskeyd force-pushed the check_context_E0423 branch from 5379203 to 0d7e6cf Compare April 28, 2017 18:40
@Freyskeyd
Copy link
Contributor Author

ping @petrochenkov @carols10cents :)

@petrochenkov
Copy link
Contributor

@bors r+
Thanks!

@bors
Copy link
Collaborator

bors commented Apr 29, 2017

📌 Commit 0d7e6cf has been approved by petrochenkov

@bors
Copy link
Collaborator

bors commented Apr 29, 2017

⌛ Testing commit 0d7e6cf with merge b4d3ed6...

bors added a commit that referenced this pull request Apr 29, 2017
Checker:: Execute levenshtein before other context checking

As explain [here]() i think it's better to check for a miss typing before checking context dependent help.

```rust
struct Handle {}

struct Something {
     handle: Handle
}

fn main() {
     let handle: Handle = Handle {};

     let s: Something = Something {
         // Checker detect an error and propose a solution with `Handle { /* ... */ }`
         // but it's a miss typing of `handle`
         handle: Handle
    };
}
```

Ping: @nagisa for #39226

Signed-off-by: Freyskeyd <simon.paitrault@gmail.com>
@bors
Copy link
Collaborator

bors commented Apr 29, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing b4d3ed6 to master...

@bors bors merged commit 0d7e6cf into rust-lang:master Apr 29, 2017
@Freyskeyd Freyskeyd deleted the check_context_E0423 branch April 29, 2017 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.