-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Not tested yet, but will test soon |
r? @nrc |
997e25c
to
8855ee8
Compare
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. |
With the rfc being closed due to an experimental implementation getting greenlit (rust-lang/rfcs#1941 (comment)) I assumed that this was fine. |
rereading the RFC, the json output should only be changed if |
@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. |
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. |
There was a problem hiding this 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.
src/libsyntax/json.rs
Outdated
@@ -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>, |
There was a problem hiding this comment.
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)>, |
There was a problem hiding this comment.
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.
It has to be option<bool> so that it will be excluded from the JSON output
when it's not a suggestion (also if the feature is off)
It's a separate field so as not to break consumers of the suggestion field.
|
5a854c4
to
065a108
Compare
Gah. So it turns out that rustc-serialize's JSON stuff will unconditionally output |
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 |
that works for me. @nrc ?
…-Manish Goregaokar
On Fri, Jan 19, 2018 at 4:03 PM, Oliver Schneider ***@***.***> wrote:
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?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#47540 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABivSMvuXNbHxW8E3kfg6IUo7kIs4h8xks5tMG9tgaJpZM4RizYF>
.
|
☔ The latest upstream changes (presumably #47678) made this pull request unmergeable. Please resolve the merge conflicts. |
065a108
to
0131ed1
Compare
Rebased. I tweaked rustc-serialize with a small unstable attribute that lets fields opt out of serialization if they are None. |
|
0131ed1
to
a85e891
Compare
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: Anyway, I'm happy either way, but I would like just one term. |
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
…he field only exist in the json if the flag is passed
a85e891
to
540f95d
Compare
Done. r? |
Thanks! @bors: r+ |
📌 Commit 540f95d has been approved by |
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
☀️ Test successful - status-appveyor, status-travis |
This adds
span_approximate_suggestion()
that lets you emit asuggestion 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 thatrustfix/etc can ignore these.
fixes #39254