rust/compiler/rustc_middle/src
bors 744e397d88 Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, 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 #87678 <https://github.com/rust-lang/rust/issues/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 😢
2022-10-01 10:44:25 +00:00
..
dep_graph Move the codegen_unit debug assert from rustc_query_system to query_impl 2022-09-25 12:08:36 -05:00
hir create def ids for impl traits during ast lowering 2022-09-30 15:12:01 -03:00
infer Const unification is already infallible, remove the error handling logic 2022-09-22 08:20:13 +00:00
middle Refactor rustc lint API 2022-10-01 10:03:06 +00:00
mir remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
query rustdoc: Queryify is_notable_trait 2022-09-27 17:44:54 -07:00
thir Use boxed slices in PatKind. 2022-09-02 07:26:22 +10:00
traits Neither require nor imply lifetime bounds on opaque type for well formedness 2022-09-21 13:11:54 +00:00
ty Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebank 2022-10-01 10:44:25 +00:00
util span: move MultiSpan 2022-04-05 07:01:00 +01:00
arena.rs cache collect_trait_impl_trait_tys 2022-09-14 20:50:52 +00:00
error.rs UPDATE - rename SessionSubdiagnostic macro to Subdiagnostic 2022-09-21 11:39:53 -04:00
lib.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
lint.rs Move lint level source explanation to the bottom 2022-10-01 10:03:06 +00:00
macros.rs impl TypeVisitable in type traversal macros 2022-07-05 22:25:33 +01:00
metadata.rs rustc: Parameterize ty::Visibility over used ID 2022-09-07 13:35:41 +04:00
tests.rs
thir.rs remove cfg(bootstrap) 2022-09-26 10:14:45 +02:00
values.rs Make HandleCycleError an enum instead of a macro-generated closure 2022-09-06 19:26:08 -05:00