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

syntax: recovery for incorrect associated item paths like [T; N]::clone #46788

Merged
merged 1 commit into from
Dec 17, 2017

Conversation

petrochenkov
Copy link
Contributor

cc #44970
Fixes #42187
r? @estebank

@petrochenkov petrochenkov requested review from estebank and removed request for estebank December 17, 2017 17:32
Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

Other than the wording nitpicks, I really like the approach. r=me once wording has been changed.

--> $DIR/bad-assoc-pat.rs:13:9
|
13 | [u8]::AssocItem => {}
| ^^^^^^^^^^^^^^^ help: try: `<[u8]>::AssocItem`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestions are reserved for cases where our level of certainty that they're correct is very high (sometimes going to the length of continuing parsing to verify our theory). Because this error happens at the parser level, we don't know whether AssocItem is an associated item or not, so normally we would suggest using a span_label instead. Despite this, in this case I'm ok with the use of a span_suggestion, but I would reword it to something more descriptive, like "if you meant to use an associated item, surround the type with brackets:", or something shorter (long suggestion messages make the suggestion be presented on it's own).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC, @oli-obk in the recent months moved everything containing code snippets to span_suggestion, regardless of suggestion reliability.
(FWIW, I'd also estimate this recovery as pretty reliable.)

"if you meant to use an associated item, surround the type with brackets:"

The primary message already says roughly this, so I avoided repeating it in the label (I also like really short labels in general).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm working on suggestion levels. Just make everything a suggestion and let me worry about the probablitity of it being correct

Copy link
Contributor

Choose a reason for hiding this comment

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

@oli-obk I've been thinking about making the error more structured, basically having a struct for each possible error the compiler generates, that way we can start playing with having the --explain content inline with the actual code being compiled (similar output to what Elm produces). This would require suggestions to be reworked slightly as well. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Making the errors more explicit is definitely a good idea. Currently analysis code and error reporting is quite mangled. Maybe we can get it separated with this method.

The most important thing is that the diagnostics API stays as usable as it is now. Making it more complex will only unnecessarily hold up regular development

Copy link
Contributor

Choose a reason for hiding this comment

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

@oli-obk I definitely agree. The only thing that worries me is decoupling the place where the error is emitted and where it is "defined" in different files might lead to harder maintenance, but the way I'm thinking about it it should still allow the current ad-hoc DiagnosticBuilder usage to keep the current flexibility (and allowing a gradual migration to these structured errors).

fn to_string(&self) -> String {
pprust::ty_to_string(self)
}
const PATH_STYLE: PathStyle = PathStyle::Type;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is customary to have the consts at the beginning of an impl, but don't bother to change it here, this is short enough to not make a difference :)

@estebank
Copy link
Contributor

Let's merge this, we can change the wording later :)

@bors r+

@bors
Copy link
Contributor

bors commented Dec 17, 2017

📌 Commit 70e5c37 has been approved by estebank

@bors
Copy link
Contributor

bors commented Dec 17, 2017

⌛ Testing commit 70e5c37 with merge dc39c31...

bors added a commit that referenced this pull request Dec 17, 2017
syntax: recovery for incorrect associated item paths like `[T; N]::clone`

cc #44970
Fixes #42187
r? @estebank
@bors
Copy link
Contributor

bors commented Dec 17, 2017

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

@bors bors merged commit 70e5c37 into rust-lang:master Dec 17, 2017
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Dec 21, 2017
syntax: Follow-up to the incorrect qpath recovery PR

cc rust-lang#46788

Add tests checking that "priority" of qpath recovery is higher than priority of unary and binary operators
Fix regressed parsing of paths with fn-like generic arguments
r? @estebank
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Mar 22, 2019
 syntax: Better recovery for `$ty::AssocItem` and `ty!()::AssocItem`

This PR improves on rust-lang#46788 covering a few missing cases.

Fixes rust-lang#52307
Fixes rust-lang#53776
r? @estebank
bors added a commit that referenced this pull request Mar 23, 2019
 syntax: Better recovery for `$ty::AssocItem` and `ty!()::AssocItem`

This PR improves on #46788 covering a few missing cases.

Fixes #52307
Fixes #53776
r? @estebank
@petrochenkov petrochenkov deleted the assocrecov branch June 5, 2019 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants