-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Move lint level source explanation to the bottom #101986
Move lint level source explanation to the bottom #101986
Conversation
Some changes occurred in src/tools/clippy cc @rust-lang/clippy Some changes occurred in const_evaluatable.rs cc @lcnr
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki
cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
/// A workaround for "good path" ICEs when formatting types in disables lints. | ||
/// | ||
/// Delays formatting until `.into(): DiagnosticMessage` is used. | ||
pub struct DelayDm<F>(pub F); |
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.
Will this go away after the migration to translatable messages?
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.
Yes, this is the intention.
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.
Should we add a rustc lint to detect when we're using Ty: Display
without wrapping it in this? (Maybe not to address in this PR, but I know I'm bound to make that mistake myself at some point in the future.)
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 think we should add a lint, yes.
@@ -561,26 +565,28 @@ fn check_for_bindings_named_same_as_variants( | |||
BINDINGS_WITH_VARIANT_NAME, | |||
p.hir_id, | |||
p.span, | |||
DelayDm(|| format!( |
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.
Idle thought: maybe let's make this argument always DelayDm
(or maybe "just" the closure?) That way you make it less likely to make the mistake? Not necessary for this PR (just a thought so we don't impl yet another complex internal lint.)
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.
That is an option. Maybe a trait like IntoLintMessage
implemented for F: FnOnce() -> String
and the fluent
thing. We could also do the same with Into<SubdiagnosticMessage>
, but that would also affect non-lints, so idk.
You'll need to re |
I forget that clippy exists every time xd |
85dcef6
to
6b5ba20
Compare
The Miri subtree was changed cc @rust-lang/miri |
f256d8e
to
d3bf085
Compare
I think this should be at least |
☔ The latest upstream changes (presumably #102064) made this pull request unmergeable. Please resolve the merge conflicts. |
r=me after rebasing |
d3bf085
to
6bc1170
Compare
I got more conflicts, while rebasing ✌️ brb rebasing again |
6bc1170
to
ca532df
Compare
Finished benchmarking commit (744e397): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
The tiny icount regressions are matched or exceeded by the tiny icount improvements. This seems fine. @rustbot label: +perf-regression-triaged |
…illot Remove a couple lifetimes that can be infered From the review: rust-lang#101986 (comment) r? `@cjgillot`
…ottom, r=estebank Move lint level source explanation to the bottom So, uhhhhh r? `@estebank` ## User-facing change "note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic: ```diff - = note: `#[warn(unsupported_calling_conventions)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue rust-lang#87678 <rust-lang#87678> + = note: `#[warn(unsupported_calling_conventions)]` on by default ``` Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO. ## Developer-facing change `struct_span_lint` and similar methods have a different signature. Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)` After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion. Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere. ## Subtle problem By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings... I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate. ## P.S. I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
@@ -373,12 +386,12 @@ pub fn struct_lint_level<'s, 'd>( | |||
if let Level::Expect(_) = level { | |||
let name = lint.name_lower(); | |||
err.code(DiagnosticId::Lint { name, has_future_breakage, is_force_warn: false }); | |||
decorate(LintDiagnosticBuilder::new(err)); | |||
|
|||
decorate(&mut err); |
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 does decorate have a return vale, if it is being ignored?
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.
To optimize the most common case, #101986 (comment)
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.
Could you add doc comments explaining that to all functions that take such a strangely typed closure? I spent 15min digging through the code to figure out what the return value does...
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.
yeah, sure xD
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. :)
Slightly tweak comments wrt `lint_overflowing_range_endpoint` From the review: rust-lang#101986 (comment) It _seemed_ that the lint was not emitted when the `if` check failed, but _actually_ this happens already in a special case and the lint is emitted outside of this function, if this function doesn't. I've cleared up the code/comments a bit, so it's more obvious :) r? `@estebank`
Slightly tweak comments wrt `lint_overflowing_range_endpoint` From the review: rust-lang#101986 (comment) It _seemed_ that the lint was not emitted when the `if` check failed, but _actually_ this happens already in a special case and the lint is emitted outside of this function, if this function doesn't. I've cleared up the code/comments a bit, so it's more obvious :) r? ``@estebank``
Slightly tweak comments wrt `lint_overflowing_range_endpoint` From the review: rust-lang#101986 (comment) It _seemed_ that the lint was not emitted when the `if` check failed, but _actually_ this happens already in a special case and the lint is emitted outside of this function, if this function doesn't. I've cleared up the code/comments a bit, so it's more obvious :) r? ```@estebank```
…ottom, r=estebank Move lint level source explanation to the bottom So, uhhhhh r? `@estebank` ## User-facing change "note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic: ```diff - = note: `#[warn(unsupported_calling_conventions)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue rust-lang#87678 <rust-lang#87678> + = note: `#[warn(unsupported_calling_conventions)]` on by default ``` Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO. ## Developer-facing change `struct_span_lint` and similar methods have a different signature. Before: `..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)` After: `..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>` The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion. Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere. ## Subtle problem By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings... I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate. ## P.S. I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
Remove a couple lifetimes that can be infered From the review: rust-lang/rust#101986 (comment) r? `@cjgillot`
Remove a couple lifetimes that can be infered From the review: rust-lang/rust#101986 (comment) r? `@cjgillot`
So, uhhhhh
r? @estebank
User-facing change
"note:
#[warn(...)]
on by default" and such are moved to the bottom of the diagnostic:Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO.
Developer-facing change
struct_span_lint
and similar methods have a different signature.Before:
..., impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>)
After:
..., impl Into<DiagnosticMessage>, impl for<'a, 'b> FnOnce(&'b mut DiagnosticBuilder<'a, ()>) -> &'b mut DiagnosticBuilder<'a, ()>
The reason for this is that
struct_span_lint
needs to edit the diagnostic afterdecorate
closure is called. This also makes lint code a little bit nicer in my opinion.Another option is to use
impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>
altough I don't really see reasons to dolet lint = lint.build(message)
everywhere.Subtle problem
By moving the message outside of the closure (that may not be called if the lint is disabled)
format!(...)
is executed earlier, possibly formattingTy
which may call a query that trims paths that crashes the compiler if there were no warnings...I don't think it's that big of a deal, considering that we move from
format!(...)
tofluent
(which is lazy by-default) anyway, however this required adding a workaround which is unfortunate.P.S.
I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢