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

Remove usages of span_suggestion without Applicability #54241

Merged
merged 13 commits into from
Sep 20, 2018

Conversation

vi
Copy link
Contributor

@vi vi commented Sep 15, 2018

Use Applicability::Unspecified for all of them instead.

Shall deprecations for the non-_with_applicability functions be added?

Shall clippy be addressed somehow?

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2018
@zackmdavis
Copy link
Member

Use Applicability::Unspecified for all of them instead.

I'd rather we make the call between MachineApplicable and MaybeIncorrect at the same time we change to _with_applicability; otherwise, we'll just have to do it later in order to get the benefits. It's OK to guess and let reviewers—or, if we're unlucky, bug reporters (recent example)—debate and iterate on which diagnostics should have which applicability values.

@vi
Copy link
Contributor Author

vi commented Sep 15, 2018

@zackmdavis , There is advantage of doing it in two steps, given influx of new span_suggestion without applicability and each decision about concrete applicability being a potential subject of debate.

First step is obvious and doesn't make any decisions about applicability of litens, yet prevents [accidental] creation of new lints with unspecified applicability.

Second step can be gradual and dialogue-heavy, without time pressure.

@vi
Copy link
Contributor Author

vi commented Sep 15, 2018

Just noticed there are also span_suggestions and multipart_suggestion.

@rust-highfive

This comment has been minimized.

@killercup
Copy link
Member

It would be great to add rustfix tests as well. That should probably happen in increments, though, because it leads to much larger diffs.

@vi
Copy link
Contributor Author

vi commented Sep 15, 2018

Implemented similar pull request for Clippy: rust-lang/rust-clippy#3191

Both pull reqeusts should come as one package.

@bors

This comment has been minimized.

@vi vi force-pushed the suggest_with_applicability branch from 4ebfa7b to 3be24c6 Compare September 16, 2018 18:43
@rust-highfive

This comment has been minimized.

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.

Thank you so much for taking the work of going through these!

I'm asking for a bunch of changes, mainly fixing indentation to match the current style (arguments on their own line and one indentation level down when they don't fit in a single line) and using an appropriate Applicability when it makes sense.

Other than that, r=me.

src/librustc/session/mod.rs Outdated Show resolved Hide resolved
src/librustc_borrowck/borrowck/mod.rs Outdated Show resolved Hide resolved
src/librustc_borrowck/borrowck/mod.rs Outdated Show resolved Hide resolved
src/librustc_borrowck/borrowck/mod.rs Outdated Show resolved Hide resolved
src/librustc_borrowck/borrowck/mod.rs Outdated Show resolved Hide resolved
src/librustc_typeck/check/op.rs Outdated Show resolved Hide resolved
src/libsyntax/config.rs Outdated Show resolved Hide resolved
src/libsyntax/ext/tt/macro_rules.rs Outdated Show resolved Hide resolved
src/libsyntax/parse/parser.rs Outdated Show resolved Hide resolved
src/libsyntax_ext/format.rs Outdated Show resolved Hide resolved
@estebank
Copy link
Contributor

It would be great to add rustfix tests as well. That should probably happen in increments, though, because it leads to much larger diffs.

@killercup how does rustfix handle when there are multiple suggestions to change the same piece of code (for example, multiple mutable access to immutable binding suggesting to add mut to the binding)?

@estebank estebank 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 Sep 16, 2018
@vi
Copy link
Contributor Author

vi commented Sep 16, 2018

... using an appropriate Applicability when it makes sense.

I expected that it's better to split "mechanical" refactoring to explicit Unspecified and "political" task of assigning concrete applicability levels to two separate pull requests: the first deprecates the function (preventing influx of new underspecified lints) and is more time-sensitive, the second can be done gradually, lint after lint and be discussed thoroughly.

Or is the whole problem just not big enough to warrant such approach?

@estebank
Copy link
Contributor

Or is the whole problem just not big enough to warrant such approach?

The reality is that there's a small amount of people that know wether a given suggestion is always (or even a majority of the time) correct, namely the person that wrote it and the person that reviewed it (at best, sometimes the interactions can be too subtle even for the writer). We sometimes do get it wrong and have to go back and change them, which is why when in doubt I lean towards marking as much as possible as MachineApplicable and change if we find errors in the wild. It is also true that if we misjudge something as MaybeApplicable few people would complain, and it is a "safe" failure mode because no one would be adversely affected.

I understand your position and I would tend to agree in the general case as the correct approach for this kind of changes, but for this task you're already doing the brunt of the work, highlighting the places where the changes need to happen. I (and others in this thread) have enough context to suggest with a high degree of confidence the appropriate Applicability level, which makes me think it is worth it to include that change in this PR. I also invite @zackmdavis, @killercup, @michaelwoerister @oli-obk and @varkor to take a look at the suggested Applicability levels in case I severely misjudged any of them.

@vi
Copy link
Contributor Author

vi commented Sep 16, 2018

OK, I'll make changing Applicability from Unspecified to something a separate commit.

@vi
Copy link
Contributor Author

vi commented Sep 17, 2018

Applied the Applicabilitiyies. There are at least 10 remaining occurrences of Unspecified:

$ git grep Applicability::Unspecified | grep -v src/librustc_errors/diagnostic.rs
src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs:            Applicability::Unspecified,
src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs:                                Applicability::Unspecified,
src/librustc/session/mod.rs:                                                                    Applicability::Unspecified,
src/librustc_borrowck/borrowck/mod.rs:                                                                      Applicability::Unspecified,
src/librustc_borrowck/borrowck/mod.rs:                                                                      Applicability::Unspecified,
src/librustc_borrowck/borrowck/mod.rs:                                Applicability::Unspecified,
src/librustc_mir/borrow_check/move_errors.rs:                        Applicability::Unspecified,
src/librustc_mir/borrow_check/move_errors.rs:                        Applicability::Unspecified,
src/librustc_resolve/lib.rs:                                                Applicability::Unspecified);
src/librustc_typeck/check/cast.rs:                                              Applicability::Unspecified,

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.

Thanks for the changes. However consistency with the style guide lowers the mental burden for people that come later to read the code.

When foo(bar, baz, quz); doesn't fit in one line under 100 cols, the appropriate indentation is

foo(
    bar,
    baz,
    qux,
);

There are multiple instances of

foo(bar,
    baz,
    qux);

from before the current style guide was arrived to, which is why you'll see inconsistencies, but we're slowly moving to the new style.

Would you mind making that change wherever the method calls that you're already modifying don't match that style?

Beyond that, the PR is in good shape. r=me.

@@ -39,7 +39,7 @@ pub struct DiagnosticBuilder<'a> {
/// it easy to declare such methods on the builder.
macro_rules! forward {
// Forward pattern for &self -> &Self
(pub fn $n:ident(&self, $($name:ident: $ty:ty),*) -> &Self) => {
(pub fn $n:ident(&self, $($name:ident: $ty:ty,)*) -> &Self) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for this change? It seems to me that including the , inside the repetition makes it slightly more annoying to use elsewhere in the file, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Inside the macro call, it was requested to update it to new style (each argument on separate line). This looks better with trailing commas, but original macro didn't support trailing commas. Seeing no easy way to make it accept optional trailing comma, I just made it accept non-optional trailing comma. This cascaded into changing all invocations (and one-line invocations just got in the way).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

slightly more annoying

For me diff/merge-friendliness brought by trailing commas typically trumps niceness for eye. So if there can only be one, it should be with the commas.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Remembered that there's $(,)* trick, now it can be both with and without.

@estebank
Copy link
Contributor

Applied the Applicabilitiyies. There are at least 10 remaining occurrences of Unspecified

We can deal with them in a separate PR :)

@killercup
Copy link
Member

I'll have a quick look at the chosen applicability levels but I generally trust @estebank's judgement in that regard.

It would be great to add rustfix tests as well. That should probably happen in increments, though, because it leads to much larger diffs.

@killercup how does rustfix handle when there are multiple suggestions to change the same piece of code (for example, multiple mutable access to immutable binding suggesting to add mut to the binding)?

@estebank right now, it'll do weird things. Sadly, the rustfix mode of the compile tests is not as powerful as cargo-fix. We should update it sooner rather than later :)

Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

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

Great work! There are some small nits but otherwise r=me, too!

message,
suggestion,
Applicability::Unspecified,
);
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see what the formatting commits were about now: Please, for all the people who like split diffs, indent the arguments just one level and not visually :)

Copy link
Contributor

Choose a reason for hiding this comment

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

@vi the only thing left is the formatting here (and elsewhere) should have the arguments indented one level (four spaces):

                    diag_builder.span_suggestion_with_applicability(
                        span,
                        message,
                        suggestion,
                        Applicability::Unspecified,
                    );

// reference, I don't know how rustfix handles it, it might
// attempt fixing them multiple times.
// @estebank
Applicability::Unspecified,
Copy link
Member

Choose a reason for hiding this comment

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

cargo fix will actually try to iteratively apply suggestions when necessary: rust-lang/cargo#5842. IIUC, this will generate the same suggestion over and over again? This should work.

Copy link
Contributor

Choose a reason for hiding this comment

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

@killercup Won't it cause the final code to be something along the lines of let mut mut mut mut x?

Copy link
Member

Choose a reason for hiding this comment

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

rustfix works by replacing specific byte ranges. Once a part of the file has been replaced, rustfix will yell at you when you try to replace it against. cargo-fix will then try to resolve this in some ways (see link above)

upvar_ident.span,
"consider changing this to be mutable",
format!("mut {}", upvar_ident.name),
Applicability::MachineApplicable,
Copy link
Member

Choose a reason for hiding this comment

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

"Upvar" implies this is only for closures and closure-like things (maybe generators?), right? I'm asking because I'm not sure I'd want use to change function signatures -- which are potentially public API. Actually, scratch that, if it's a valid fix, we should fix it.

"try casting to a `Box` instead",
format!("Box<{}>", s));
format!("Box<{}>", s),
Applicability::MachineApplicable,
Copy link
Member

Choose a reason for hiding this comment

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

Side question: If I read this correctly, s is a trait here. Should we suggest Box<dyn {}> here? (That's how you use the dyn keyword, right?) Probably the same for "try casting to a reference …" above

comma_span,
"missing comma here",
", ".to_string(),
Applicability::MachineApplicable,
Copy link
Member

Choose a reason for hiding this comment

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

This might be the first syntax error fix we have -- are we sure this is 100% correct in this case, @estebank?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is the first one, but this suggestion will always be syntactically correct, as in the new code will match one of the macro matches. I can imagine cases where that wouldn't be the expected case, but I'm pretty sure >90% we'll be correct.

diag.multipart_suggestion_with_applicability(
"format specifiers use curly braces",
suggestions,
Applicability::MachineApplicable,
Copy link
Member

Choose a reason for hiding this comment

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

I love this fix. This is just magic. I hope it actually works each time it yields suggestions :D

(Not sure if it is correct although).
@michaelwoerister
Copy link
Member

I took a quick look but I don't know the intricacies about most of the things touched, so I can't really help here.

@vi
Copy link
Contributor Author

vi commented Sep 17, 2018

S-waiting-on-author

What's more to be done?

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 17, 2018
@vi vi force-pushed the suggest_with_applicability branch from 18f25bd to d0790c4 Compare September 17, 2018 17:26
@estebank
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 17, 2018

📌 Commit d0790c4 has been approved by estebank

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 17, 2018
@bors
Copy link
Contributor

bors commented Sep 20, 2018

⌛ Testing commit d0790c4 with merge 992d1e4...

bors added a commit that referenced this pull request Sep 20, 2018
Remove usages of span_suggestion without Applicability

Use `Applicability::Unspecified` for all of them instead.

Shall deprecations for the non-`_with_applicability` functions be added?

Shall clippy be addressed somehow?

r? @estebank
@bors
Copy link
Contributor

bors commented Sep 20, 2018

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

@bors bors merged commit d0790c4 into rust-lang:master Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants