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

Add approximate suggestions for rustfix #47540

Merged
merged 3 commits into from
Feb 1, 2018
Merged

Conversation

Manishearth
Copy link
Member

This adds span_approximate_suggestion() that lets you emit a
suggestion marked as "non-machine applicable" in the JSON output. UI
users see no difference. This is for when rustc and clippy wish to
emit suggestions which will make sense to the reader (e.g. they may
have placeholders like <type>) but are not source-applicable, so that
rustfix/etc can ignore these.

fixes #39254

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@Manishearth
Copy link
Member Author

Not tested yet, but will test soon

@Manishearth
Copy link
Member Author

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned nikomatsakis Jan 18, 2018
@kennytm kennytm added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 18, 2018
@nrc nrc added I-nominated T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. labels Jan 18, 2018
@nrc
Copy link
Member

nrc commented Jan 18, 2018

I've opposed this in the past, because I don't think it is ever possible to mechanically apply suggestions without user input. However, this might be something different, let's discuss at the meeting.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 18, 2018

With the rfc being closed due to an experimental implementation getting greenlit (rust-lang/rfcs#1941 (comment)) I assumed that this was fine.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 18, 2018

rereading the RFC, the json output should only be changed if -Zunstable-features is enabled, so we don't start emitting the flag unless explicitly desired. Maybe even under its own -Z flag

@Manishearth
Copy link
Member Author

@nrc rustfix already does this pretty well. Of course there will still be human confirmation of the diff, but we can at least try and remove things we know are not source suggestions.

And yeah, I was under the impression we had already agreed to add this API in the RFC. I can put it behind a flag.

@nrc
Copy link
Member

nrc commented Jan 19, 2018

Yeah, I'd forgotten where we'd landed with the RFC. We were all broadly in favour at the dev-tools meeting.

For handling the unstable-ness, rather than have a flag, we should have some API to turn this on, so that only tools which extend the compiler can activate it. I think that is both simpler to implement and gives better safeguards than a flag. killercup was ok with this at the meeting for rustfix.

Copy link
Member

@nrc nrc left a comment

Choose a reason for hiding this comment

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

Looks fine, modulo the comments inline and adding using a function to turn on the flag.

@@ -121,6 +121,8 @@ struct DiagnosticSpan {
/// If we are suggesting a replacement, this will contain text
/// that should be sliced in atop this span.
suggested_replacement: Option<String>,
/// If the suggestion is machine-applicable
suggestion_machine_applicable: Option<bool>,
Copy link
Member

Choose a reason for hiding this comment

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

Why is this an Option<bool> rather than just a bool?

@@ -220,7 +222,7 @@ impl Diagnostic {

impl DiagnosticSpan {
fn from_span_label(span: SpanLabel,
suggestion: Option<&String>,
suggestion: Option<(&String, bool)>,
Copy link
Member

Choose a reason for hiding this comment

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

I find it a bit weird that we have three different ways to represent the suggestion and whether it is machine applicable (two options, one option and a bool, one option of a tuple). It would be good to stick to one representation, if possible.

@Manishearth
Copy link
Member Author

Manishearth commented Jan 19, 2018 via email

@Manishearth
Copy link
Member Author

Gah. So it turns out that rustc-serialize's JSON stuff will unconditionally output suggestion: machine_applicable: null in case we disable it, which is not something we wish to happen. I'm not sure what to do here, rustc-serialize just isn't that configurable. I could easily add a "skip if null" gated attribute that we only use internally but that feels like scope creep. Alternatively I can define a second struct and add a .json() function that formats it. Kinda icky but not really.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 19, 2018

Can't we do it like with MIR output? Just tell everyone that the field is unstable and should not be used by naming it __do_not_use_machine_applicable?

@Manishearth
Copy link
Member Author

Manishearth commented Jan 19, 2018 via email

@bors
Copy link
Contributor

bors commented Jan 23, 2018

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

@Manishearth
Copy link
Member Author

Rebased. I tweaked rustc-serialize with a small unstable attribute that lets fields opt out of serialization if they are None.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 24, 2018

tidy error: /checkout/src/libsyntax_ext/deriving/encodable.rs:215: trailing whitespace

@nrc
Copy link
Member

nrc commented Jan 29, 2018

Code looks fine (thanks for the changes!), I do still have some qualms about the naming, however: there is one concept here, but two names: machine_applicable and approximate and unfortunately, they have opposite truth values. I think it would be best to choose one or the other and only use that term. I would prefer machine_applicable, but that would mean that the default for the suggestion functions would be false and you would use machine_applicable_suggestion, etc. (I actually think that is the right default, but I'm willing to believe it is not).

Anyway, I'm happy either way, but I would like just one term.

@Manishearth
Copy link
Member Author

I'll use approximate so that the default continues to make sense.

This adds `span_approximate_suggestion()` that lets you emit a
suggestion marked as "approximate" in the JSON output. UI
users see no difference. This is for when rustc and clippy wish to
 emit suggestions which will make sense to the reader (e.g. they may
have placeholders like `<type>`) but are not source-applicable, so that
rustfix/etc can ignore these.

fixes rust-lang#39254
@Manishearth
Copy link
Member Author

Done. r?

@nrc
Copy link
Member

nrc commented Feb 1, 2018

Thanks!

@bors: r+

@bors
Copy link
Contributor

bors commented Feb 1, 2018

📌 Commit 540f95d has been approved by nrc

@bors
Copy link
Contributor

bors commented Feb 1, 2018

⌛ Testing commit 540f95d with merge 26792f0...

bors added a commit that referenced this pull request Feb 1, 2018
Add approximate suggestions for rustfix

This adds `span_approximate_suggestion()` that lets you emit a
suggestion marked as "non-machine applicable" in the JSON output. UI
users see no difference. This is for when rustc and clippy wish to
 emit suggestions which will make sense to the reader (e.g. they may
have placeholders like `<type>`) but are not source-applicable, so that
rustfix/etc can ignore these.

fixes #39254
@bors
Copy link
Contributor

bors commented Feb 1, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nrc
Pushing 26792f0 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Differentiate between suggestions which are programmatically applicable and those which are not
7 participants