Commit Graph

890 Commits

Author SHA1 Message Date
bors
a128516cf9 Auto merge of #122754 - Mark-Simulacrum:bootstrap-bump, r=albertlarsan68
Bump to 1.78 bootstrap compiler

https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-03-20 13:43:41 +00:00
Mark Rousskov
02f1930595 step cfgs 2024-03-20 08:49:13 -04:00
Esteban Küber
cc9631a371 When displaying multispans, ignore empty lines adjacent to ...
```
error[E0308]: `match` arms have incompatible types
   --> tests/ui/codemap_tests/huge_multispan_highlight.rs:98:18
    |
6   |       let _ = match true {
    |               ---------- `match` arms have incompatible types
7   |           true => (
    |  _________________-
8   | |             // last line shown in multispan header
...   |
96  | |
97  | |         ),
    | |_________- this is found to be of type `()`
98  |           false => "
    |  __________________^
...   |
119 | |
120 | |         ",
    | |_________^ expected `()`, found `&str`

error[E0308]: `match` arms have incompatible types
   --> tests/ui/codemap_tests/huge_multispan_highlight.rs:215:18
    |
122 |       let _ = match true {
    |               ---------- `match` arms have incompatible types
123 |           true => (
    |  _________________-
124 | |
125 | |         1 // last line shown in multispan header
...   |
213 | |
214 | |         ),
    | |_________- this is found to be of type `{integer}`
215 |           false => "
    |  __________________^
216 | |
217 | |
218 | |         1 last line shown in multispan
...   |
237 | |
238 | |         ",
    | |_________^ expected integer, found `&str`
```
2024-03-18 16:25:36 +00:00
Michael Goulet
6e4cd8b7cc Make SubdiagMessageOp well-formed 2024-03-14 13:13:08 -04:00
Matthias Krüger
fce6e752ab
Rollup merge of #120699 - nnethercote:rm-useless-TRACK_DIAGNOSTIC-calls, r=oli-obk
Document `TRACK_DIAGNOSTIC` calls.

r? ```````@cjgillot```````
2024-03-14 11:09:57 +01:00
Matthias Krüger
0b127d82f3
Rollup merge of #122194 - oli-obk:stash_delay_bug, r=nnethercote
Enable creating backtraces via -Ztreat-err-as-bug when stashing errors

r? `@nnethercote`

Otherwise I can't debug stashed errors because I can't find their source
2024-03-12 06:29:03 +01:00
Jubilee
671fc18ba2
Rollup merge of #122299 - compiler-errors:bt-for-must-diag, r=nnethercote
Store backtrace for `must_produce_diag`

This makes it significantly easier to debug a `must_produce_diag` ICE, since we have no other way to know where the heck the bug originates from.

Backtrace rendering kinda sucks right now since we're just printing it in the panic message; happy to apply some suggestions to make it prettier or reuse other bug printing machinery, but also don't want to iterate too much on the rendering since this really is just for debug purposes.

r? nnethercote
2024-03-11 09:29:37 -07:00
Oli Scherer
cfbc1b96d5 Enable creating backtraces via -Ztreat-err-as-bug when stashing errors 2024-03-11 08:46:58 +00:00
Michael Goulet
73fc170544 Store backtrace for must_produce_diag 2024-03-10 23:22:30 -04:00
Nicholas Nethercote
e9f0d9be0e Rename DecorateLint as LintDiagnostic.
To match `derive(LintDiagnostic)`.
2024-03-11 10:04:50 +11:00
Nicholas Nethercote
541d7cc65c Rename AddToDiagnostic as Subdiagnostic.
To match `derive(Subdiagnostic)`.

Also rename `add_to_diagnostic{,_with}` as `add_to_diag{,_with}`.
2024-03-11 10:04:49 +11:00
Nicholas Nethercote
7a294e998b Rename IntoDiagnostic as Diagnostic.
To match `derive(Diagnostic)`.

Also rename `into_diagnostic` as `into_diag`.
2024-03-11 09:15:09 +11:00
Nicholas Nethercote
a09b1d33a7 Rename IntoDiagnosticArg as IntoDiagArg.
Also rename `into_diagnostic_arg` as `into_diag_arg`, and
`NotIntoDiagnosticArg` as `NotInotDiagArg`.
2024-03-11 09:12:19 +11:00
Matthias Krüger
efe9deace8
Rollup merge of #121382 - nnethercote:rework-untranslatable_diagnostic-lint, r=davidtwco
Rework `untranslatable_diagnostic` lint

Currently it only checks calls to functions marked with `#[rustc_lint_diagnostics]`. This PR changes it to check calls to any function with an `impl Into<{D,Subd}iagnosticMessage>` parameter. This greatly improves its coverage and doesn't rely on people remembering to add `#[rustc_lint_diagnostics]`. It also lets us add `#[rustc_lint_diagnostics]` to a number of functions that don't have an `impl Into<{D,Subd}iagnosticMessage>`, such as `Diag::span`.

r? ``@davidtwco``
2024-03-06 22:02:46 +01:00
Nicholas Nethercote
3591e77b35 Add missing #[rustc_lint_diagnostics] attributes.
Prior to the previous commit, `#[rust_lint_diagnostics]` attributes
could only be used on methods with an `impl Into<{D,Subd}iagMessage>`
parameter. But there are many other nearby diagnostic methods (e.g.
`Diag::span`) that don't take such a parameter and should have the
attribute.

This commit adds the missing attribute to these `Diag` methods. This
requires adding some missing
`#[allow(rustc::diagnostic_outside_of_impl)]` markers at call sites to
these methods.
2024-03-06 14:19:38 +11:00
David Wood
2ee0409f32
errors: share SilentEmitter between rustc and rustfmt
Signed-off-by: David Wood <david@davidtw.co>
2024-03-05 10:14:36 +00:00
Nicholas Nethercote
d602394827 Change message type in bug functions.
From `impl Into<DiagnosticMessage>` to `impl Into<Cow<'static, str>>`.

Because these functions don't produce user-facing output and we don't
want their strings to be translated.
2024-03-05 17:11:42 +11:00
Nicholas Nethercote
1cd957498b Adjust Diag::new signature.
Make it use `impl Into<DiagMessage>` like all the other methods nearby.
2024-03-05 12:15:13 +11:00
Nicholas Nethercote
573267cf3c Rename SubdiagnosticMessageOp as SubdiagMessageOp. 2024-03-05 12:14:49 +11:00
Nicholas Nethercote
60ea6e2831 Rename SubdiagnosticMessage as SubdiagMessage. 2024-03-05 12:14:49 +11:00
Nicholas Nethercote
18715c98c6 Rename DiagnosticMessage as DiagMessage. 2024-03-05 12:14:49 +11:00
Matthias Krüger
706fe0b7d8
Rollup merge of #120976 - matthiaskrgr:constify_TL_statics, r=lcnr
constify a couple thread_local statics
2024-03-04 22:16:30 +01:00
Matthias Krüger
3c89280684
Rollup merge of #120305 - clubby789:unused-import-line, r=estebank
Delete line if suggestion would replace it with an empty line

Fixes #120296
2024-03-01 22:38:45 +01:00
clubby789
367126d49a If suggestion would leave an empty line, delete it 2024-03-01 13:48:20 +00:00
Nicholas Nethercote
7ef605be3f Make the match in emit_diagnostic complete.
This match is complex enough that it's a good idea to enumerate every
variant.

This also means `can_be_top_or_sub` can just be `can_be_subdiag`.
2024-03-01 13:56:24 +11:00
Nicholas Nethercote
a7d926265f Add comments about TRACK_DIAGNOSTIC use.
Also add an assertion for the levels allowed with `has_future_breakage`.
2024-03-01 13:34:31 +11:00
Nicholas Nethercote
aec4bdb0a2 Move Expect/ForceWarning handling into the match.
Note that `self.suppressed_expected_diag` is no longer set for
`ForceWarning`, which is good. Nor is `TRACK_DIAGNOSTIC` called for
`Allow`, which is also good.
2024-03-01 13:34:31 +11:00
Nicholas Nethercote
c81767e7cb Reorder has_future_breakage handling.
This will enable additional refactorings.
2024-03-01 13:34:31 +11:00
Nicholas Nethercote
272e60bd3e Move DelayedBug handling into the match.
It results in a tiny bit of duplication (another
`self.treat_next_err_as_bug()` condition) but I think it's worth it to
get more code into the main `match`.
2024-03-01 13:34:29 +11:00
Nicholas Nethercote
ecd3718bc0 Inline and remove Level::get_diagnostic_id.
It has a single call site, and this will enable subsequent refactorings.
2024-03-01 13:27:50 +11:00
Nicholas Nethercote
bf62d5913a Give TRACK_DIAGNOSTIC a return value.
This means `DiagCtxtInner::emit_diagnostic` can return its result
directly, rather than having to modify a local variable.
2024-03-01 13:27:47 +11:00
Nicholas Nethercote
44f0043e82 Handle stashing of delayed bugs.
By just emitting them immediately, because it does happen in practice,
when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the
callsite. This commit changes things so it's handled within
`stash_diagnostic` instead, because #121812 identified a second case,
and it's possible there are more.

Fixes #121812.
2024-03-01 10:18:54 +11:00
Nicholas Nethercote
721c741756 Remove unnecessary Level:: qualifiers.
We have `use Level::*;` in this file.
2024-03-01 09:54:27 +11:00
Guillaume Gomez
0e9f02d6fa
Rollup merge of #121783 - nnethercote:emitter-cleanups, r=oli-obk
Emitter cleanups

Some cleanups I made when reading emitter code. In particular, `HumanEmitter` and `JsonEmitter` have gone from three constructors to one.

r? `@oli-obk`
2024-02-29 17:08:38 +01:00
Guillaume Gomez
a5945b5d8d
Rollup merge of #121669 - nnethercote:count-stashed-errs-again, r=estebank
Count stashed errors again

Stashed diagnostics are such a pain. Their "might be emitted, might not" semantics messes with lots of things.

#120828 and #121206 made some big changes to how they work, improving some things, but still leaving some problems, as seen by the issues caused by #121206. This PR aims to fix all of them by restricting them in a way that eliminates the "might be emitted, might not" semantics while still allowing 98% of their benefit. Details in the individual commit logs.

r? `@oli-obk`
2024-02-29 17:08:38 +01:00
Nicholas Nethercote
607bf653c2 Avoid unnecessary color local variable. 2024-02-29 20:12:43 +11:00
Nicholas Nethercote
58f45059a5 Add a useful comment.
It took me a while to work this out.
2024-02-29 17:50:26 +11:00
Nicholas Nethercote
9ff4487999 Make JsonEmitter more like HumanEmitter.
Use `derive(Setters)` to derive setters, and then change
`JsonEmitter::new` to only have the arguments that are always used.
2024-02-29 17:50:26 +11:00
Nicholas Nethercote
2999d8dc72 Inline and remove JsonEmitter::{basic,stderr}.
They are so similar to `JsonEmitter::new` it's not worth having separate
functions, it makes the code harder to read.
2024-02-29 17:50:26 +11:00
Nicholas Nethercote
067d7c3d00 Inline and remove HumanEmitter::stderr.
Because `HumanEmitter::new` is enough, in conjunction with the (renamed)
`stderr_destination` function.
2024-02-29 17:50:23 +11:00
Nicholas Nethercote
437325bdd4 Inline and remove HumanReadableErrorType::new_emitter.
And likewise with `ColorConfig::suggests_using_colors`. They both have a
single call site. And note that `BufWriter::supports_color()` always
returns false, which enables a small bit of constant folding along the
way.
2024-02-29 17:16:27 +11:00
Nicholas Nethercote
d3727413ed Merge HumanEmitter::{new,create}.
They have the same signature, and the former just calls the latter.
2024-02-29 16:30:12 +11:00
Nicholas Nethercote
880c1c585f Rename DiagCtxt::with_emitter as DiagCtxt::new.
Because it's now the only constructor.
2024-02-29 16:30:12 +11:00
Nicholas Nethercote
f9eef38e32 Inline and remove DiagCtxt::with_tty_emitter
It only has two call sites, and one of those doesn't set the source map.
2024-02-29 16:30:12 +11:00
Nicholas Nethercote
ca5b79ddf7 Remove unnecessary output local variable. 2024-02-29 16:30:12 +11:00
Nicholas Nethercote
3c3f15cafe Use Destination more. 2024-02-29 16:30:12 +11:00
Nicholas Nethercote
869bd03a04 Simplify UnusedExterns lifetimes.
In practice, 'a and 'b and 'c are always the same. This change makes
`UnusedExterns` more like `ArtifactNotification`, which uses a single
lifetime 'a in multiple ways.
2024-02-29 16:30:12 +11:00
Nicholas Nethercote
c1f01638af Minor visibility and formatting improvements. 2024-02-29 16:30:09 +11:00
Nicholas Nethercote
82961c0abc Reinstate emit_stashed_diagnostics in DiagCtxtInner::drop.
I removed it in #121206 because I thought thought it wasn't necessary.
But then I had to add an `emit_stashed_diagnostics` call elsewhere in
rustfmt to avoid the assertion failure (which took two attempts to get
right, #121487 and #121615), and now there's an assertion failure in
clippy as well (https://github.com/rust-lang/rust-clippy/issues/12364).

So this commit just reinstates the call in `DiagCtxtInner::drop`. It
also reverts the rustfmt changes from #121487 and #121615, though it
keeps the tests added for those PRs.
2024-02-29 11:08:29 +11:00
Nicholas Nethercote
260ae70140 Overhaul how stashed diagnostics work, again.
Stashed errors used to be counted as errors, but could then be
cancelled, leading to `ErrorGuaranteed` soundness holes. #120828 changed
that, closing the soundness hole. But it introduced other difficulties
because you sometimes have to account for pending stashed errors when
making decisions about whether errors have occured/will occur and it's
easy to overlook these.

This commit aims for a middle ground.
- Stashed errors (not warnings) are counted immediately as emitted
  errors, avoiding the possibility of forgetting to consider them.
- The ability to cancel (or downgrade) stashed errors is eliminated, by
  disallowing the use of `steal_diagnostic` with errors, and introducing
  the more restrictive methods `try_steal_{modify,replace}_and_emit_err`
  that can be used instead.

Other things:
- `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both
  return `Option<ErrorGuaranteed>`, which enables the removal of two
  `delayed_bug` calls and one `Ty::new_error_with_message` call. This is
  possible because we store error guarantees in
  `DiagCtxt::stashed_diagnostics`.
- Storing the guarantees also saves us having to maintain a counter.
- Calls to the `stashed_err_count` method are no longer necessary
  alongside calls to `has_errors`, which is a nice simplification, and
  eliminates two more `span_delayed_bug` calls and one FIXME comment.
- Tests are added for three of the four fixed PRs mentioned below.
- `issue-121108.rs`'s output improved slightly, omitting a non-useful
  error message.

Fixes #121451.
Fixes #121477.
Fixes #121504.
Fixes #121508.
2024-02-29 11:08:27 +11:00