-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Conversation
I'd rather we make the call between |
@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. |
Just noticed there are also span_suggestions and multipart_suggestion. |
This comment has been minimized.
This comment has been minimized.
It would be great to add rustfix tests as well. That should probably happen in increments, though, because it leads to much larger diffs. |
Implemented similar pull request for Clippy: rust-lang/rust-clippy#3191 Both pull reqeusts should come as one package. |
This comment has been minimized.
This comment has been minimized.
Use Applicability::Unspecified for all of them instead.
4ebfa7b
to
3be24c6
Compare
This comment has been minimized.
This comment has been minimized.
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.
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.
@killercup how does |
I expected that it's better to split "mechanical" refactoring to explicit 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 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 |
OK, I'll make changing |
Also fix some formatting along the way.
Applied the
|
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.
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) => { |
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.
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?
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.
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).
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.
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.
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.
Remembered that there's $(,)*
trick, now it can be both with and without.
We can deal with them in a separate PR :) |
I'll have a quick look at the chosen applicability levels but I generally trust @estebank's judgement in that regard.
@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 :) |
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.
Great work! There are some small nits but otherwise r=me, too!
src/librustc/session/mod.rs
Outdated
message, | ||
suggestion, | ||
Applicability::Unspecified, | ||
); |
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.
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 :)
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.
@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, |
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.
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.
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.
@killercup Won't it cause the final code to be something along the lines of let mut mut mut mut x
?
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.
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, |
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.
"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.
src/librustc_typeck/check/cast.rs
Outdated
"try casting to a `Box` instead", | ||
format!("Box<{}>", s)); | ||
format!("Box<{}>", s), | ||
Applicability::MachineApplicable, |
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.
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
src/libsyntax/ext/tt/macro_rules.rs
Outdated
comma_span, | ||
"missing comma here", | ||
", ".to_string(), | ||
Applicability::MachineApplicable, |
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.
This might be the first syntax error fix we have -- are we sure this is 100% correct in this case, @estebank?
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 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.
src/libsyntax_ext/format.rs
Outdated
diag.multipart_suggestion_with_applicability( | ||
"format specifiers use curly braces", | ||
suggestions, | ||
Applicability::MachineApplicable, |
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 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).
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. |
What's more to be done? |
18f25bd
to
d0790c4
Compare
@bors r+ |
📌 Commit d0790c4 has been approved by |
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
☀️ Test successful - status-appveyor, status-travis |
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