Commit Graph

1005 Commits

Author SHA1 Message Date
Xiretza
6974e9cf70 Move "elided lifetime in path" to subdiagnostic struct
This requires nested subdiagnostics.
2024-04-21 07:45:03 +00:00
Xiretza
b220b741c6 Fix source ordering of IntoDiagArg impls 2024-04-21 07:45:03 +00:00
Xiretza
5646b65cf5 Pass translation closure to add_to_diag_with() as reference 2024-04-21 07:45:03 +00:00
Daniel Sedlak
be564a8add Print note with closure signature on type mismatch 2024-04-20 15:48:27 +02:00
Nicholas Nethercote
0d97669a17 Simplify static_assert_sizes.
We want to run them on all 64-bit platforms.
2024-04-18 15:36:25 +10:00
Matthias Krüger
ffea7e2a9b
Rollup merge of #123204 - notriddle:notriddle/include-str-span, r=pnkfelix
rustdoc: point at span in `include_str!`-ed md file

Fixes #118549
2024-04-12 17:41:32 +02:00
Michael Goulet
03c901fd35 Add redundant_lifetime_args lint 2024-04-09 12:15:27 -04:00
Jacob Pratt
4332498a6d
Rollup merge of #123401 - Zalathar:assert-size-aarch64, r=fmease
Check `x86_64` size assertions on `aarch64`, too

(Context: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Checking.20size.20assertions.20on.20aarch64.3F)

Currently the compiler has around 30 sets of `static_assert_size!` for various size-critical data structures (e.g. various IR nodes), guarded by `#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]`.

(Presumably this cfg avoids having to maintain separate size values for 32-bit targets and unusual 64-bit targets. Apparently it may have been necessary before the i128/u128 alignment changes, too.)

This is slightly incovenient for people on aarch64 workstations (e.g. Macs), because the assertions normally aren't checked until we push to a PR. So this PR adds `aarch64` to the `#[cfg(..)]` guarding all of those assertions in the compiler.

---

Implemented with a simple find/replace. Verified by manually inspecting each `static_assert_size!` in `compiler/`, and checking that either the replacement succeeded, or adding aarch64 wouldn't have been appropriate.
2024-04-03 20:17:06 -04:00
Matthias Krüger
32c8c5cb7e
Rollup merge of #121595 - strottos:issue_116615, r=compiler-errors
Better reporting on generic argument mismatchs

This allows better reporting as per issue #116615 .

If you have a function:
```
fn foo(a: T, b: T) {}
```
and call it like so:
```
foo(1, 2.)
```
it'll give improved error reported similar to the following:
```
error[E0308]: mismatched types
 --> generic-mismatch-reporting-issue-116615.rs:6:12
  |
6 |     foo(1, 2.);
  |     --- -  ^^ expected integer, found floating-point number
  |     |   |
  |     |   expected argument `b` to be an integer because that argument needs to match the type of this parameter
  |     arguments to this function are incorrect
  |
note: function defined here
 --> generic-mismatch-reporting-issue-116615.rs:1:4
  |
1 | fn foo<T>(a: T, b: T) {}
  |    ^^^ -  ----  ----
  |        |  |     |
  |        |  |     this parameter needs to match the integer type of `a`
  |        |  `b` needs to match the type of this parameter
  |        `a` and `b` all reference this parameter T
```

Open question, do we need to worry about error message translation into other languages? Not sure what the status of that is in Rust.

NB: Needs some checking over and some tests have altered that need sanity checking, but overall this is starting to get somewhere now. Will take out of draft PR status when this has been done, raising now to allow feedback at this stage, probably 90% ready.
2024-04-03 22:10:59 +02:00
Zalathar
2d47cd77ac Check x86_64 size assertions on aarch64, too
This makes it easier for contributors on aarch64 workstations (e.g. Macs) to
notice when these assertions have been violated.
2024-04-03 16:53:03 +11:00
Michael Howell
1c41dd6320 diagnostics: fix crash on completely empty included file 2024-03-29 18:22:44 -07:00
Matthias Krüger
3fe9f66133
Rollup merge of #122737 - ytmimi:conditionally_ignore_fatal_diagnostic, r=davidtwco
conditionally ignore fatal diagnostic in the SilentEmitter

This change is primarily meant to allow rustfmt to ignore all diagnostics when using the `SilentEmitter`. Back in #121301 the `SilentEmitter` was shared between rustc and rustfmt. This changed rustfmt's behavior from ignoring all diagnostic to emitting fatal diagnostics, which lead to https://github.com/rust-lang/rustfmt/issues/6109.

These changes allow rustfmt to maintain its previous behaviour when using the `SilentEmitter`, while allowing rustc code to still emit fatal diagnostics.
2024-03-24 17:08:15 +01:00
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
Yacin Tmimi
d49d136b3a conditionally ignore fatal diagnostic in the SilentEmitter
This change is primarily meant to allow rustfmt to ignore all
diagnostics when using the `SilentEmitter`. Back in PR 121301 the
`SilentEmitter` was shared between rustc and rustfmt. This changed
rustfmt's behavior from ignoring all diagnostic to emitting fatal
diagnostics.

These changes allow rustfmt to maintain it's previous behaviour when
using the SilentEmitter, while allowing rustc code to still emit fatal
diagnostics.
2024-03-19 13:48:07 -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
Steven Trotter
8a5245e7dd Refactored a few bits:
- Firstly get all the information about generics matching out of the HIR
- Secondly the labelling for the function is more coherent now
- Lastly a few error message improvements
2024-03-15 13:37:41 +00:00
Steven Trotter
df93364057 Added ability to report on generic argument mismatch better
Needs some checking over and some tests have altered that need sanity checking, but overall this is starting to get somewhere now.
2024-03-15 08:37:32 +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
Nicholas Nethercote
199be469ec Refactor DiagCtxtInner::flush_delayed.
This commit:
- Moves the ICE file create/open outside the loop. (Redoing it on every
  loop iteration works, but is really weird.)
- Moves the explanatory note emission above the loop, which removes the
  need for the `enumerate` call.
- Introduces a `decorate` local.
2024-02-29 11:07:42 +11:00
Nicholas Nethercote
3fbdec4937 Add a comment about how IntoDiagnostic should be impl'd. 2024-02-29 11:07:08 +11:00
Nicholas Nethercote
9b3520e876 Rename DiagnosticStyledString as DiagStyledString. 2024-02-28 08:55:37 +11:00
Nicholas Nethercote
6280a8c3fe Rename DiagnosticSymbolList as DiagSymbolList. 2024-02-28 08:55:37 +11:00
Nicholas Nethercote
e3c19a2928 Rename DiagnosticLocation as DiagLocation. 2024-02-28 08:55:37 +11:00
Nicholas Nethercote
d0ef108ce9 Rename DiagnosticArgFromDisplay as DiagArgFromDisplay. 2024-02-28 08:55:37 +11:00
Nicholas Nethercote
8199632aa8 Rename DiagnosticArg{,Map,Name,Value} as DiagArg{,Map,Name,Value}. 2024-02-28 08:55:37 +11:00
Nicholas Nethercote
899cb40809 Rename DiagnosticBuilder as Diag.
Much better!

Note that this involves renaming (and updating the value of)
`DIAGNOSTIC_BUILDER` in clippy.
2024-02-28 08:55:35 +11:00
Nicholas Nethercote
4e1f9bd528 Rename SubDiagnostic as Subdiag.
Note the change of the `D` to `d`, to match all the other names that
have `Subdiag` in them, such as `SubdiagnosticMessage` and
`derive(Subdiagnostic)`.
2024-02-28 08:33:25 +11:00
Nicholas Nethercote
366536ba2b Rename DelayedDiagnostic as DelayedDiagInner. 2024-02-28 08:33:25 +11:00
Nicholas Nethercote
6588f5b749 Rename Diagnostic as DiagInner.
I started by changing it to `DiagData`, but that didn't feel right.
`DiagInner` felt much better.
2024-02-28 08:33:25 +11:00
Matthias Krüger
86a7fc840f compiler: clippy::complexity fixes 2024-02-23 19:56:35 +01:00
bors
f70f19fef4 Auto merge of #121129 - nnethercote:codegen-Diags, r=estebank
Improve codegen diagnostic handling

Clarify the workings of the temporary `Diagnostic` type used to send diagnostics from codegen threads to the main thread.

r? `@estebank`
2024-02-22 08:01:37 +00:00
Nicholas Nethercote
b38ed1afa6 Overhaul Diagnostic args.
First, introduce a typedef `DiagnosticArgMap`.

Second, make the `args` field public, and remove the `args` getter and
`replace_args` setter. These were necessary previously because the getter
had a `#[allow(rustc::potential_query_instability)]` attribute, but that
was removed in #120931 when the args were changed from `FxHashMap` to
`FxIndexMap`. (All the other `Diagnostic` fields are public.)
2024-02-22 12:51:05 +11:00
Nicholas Nethercote
4da67fff61 Replace unnecessary abort_if_errors.
Replace `abort_if_errors` calls that are certain to abort -- because
we emit an error immediately beforehand -- with `FatalErro.raise()`.
2024-02-22 08:03:47 +11:00
Nicholas Nethercote
72b172bdf6 Overhaul the handling of errors at the top-level.
Currently `emit_stashed_diagnostic` is called from four(!) different
places: `print_error_count`, `DiagCtxtInner::drop`, `abort_if_errors`,
and `compile_status`.

And `flush_delayed` is called from two different places:
`DiagCtxtInner::drop` and `Queries`.

This is pretty gross! Each one should really be called from a single
place, but there's a bunch of entanglements. This commit cleans up this
mess.

Specifically, it:
- Removes all the existing calls to `emit_stashed_diagnostic`, and adds
  a single new call in `finish_diagnostics`.
- Removes the early `flush_delayed` call in `codegen_and_build_linker`,
  replacing it with a simple early return if delayed bugs are present.
- Changes `DiagCtxtInner::drop` and `DiagCtxtInner::flush_delayed` so
  they both assert that the stashed diagnostics are empty (i.e.
  processed beforehand).
- Changes `interface::run_compiler` so that any errors emitted during
  `finish_diagnostics` (i.e. late-emitted stashed diagnostics) are
  counted and cannot be overlooked. This requires adding
  `ErrorGuaranteed` return values to several functions.
- Removes the `stashed_err_count` call in `analysis`. This is possible
  now that we don't have to worry about calling `flush_delayed` early
  from `codegen_and_build_linker` when stashed diagnostics are pending.
- Changes the `span_bug` case in `handle_tuple_field_pattern_match` to a
  `delayed_span_bug`, because it now can be reached due to the removal
  of the `stashed_err_count` call in `analysis`.
- Slightly changes the expected output of three tests. If no errors are
  emitted but there are delayed bugs, the error count is no longer
  printed. This is because delayed bugs are now always printed after the
  error count is printed (or not printed, if the error count is zero).

There is a lot going on in this commit. It's hard to break into smaller
pieces because the existing code is very tangled. It took me a long time
and a lot of effort to understand how the different pieces interact, and
I think the new code is a lot simpler and easier to understand.
2024-02-22 08:03:47 +11:00
Nicholas Nethercote
46f4983356 Adjust the has_errors* methods.
Currently `has_errors` excludes lint errors. This commit changes it to
include lint errors.

The motivation for this is that for most places it doesn't matter
whether lint errors are included or not. But there are multiple places
where they must be includes, and only one place where they must not be
included. So it makes sense for `has_errors` to do the thing that fits
the most situations, and the new `has_errors_excluding_lint_errors`
method in the one exceptional place.

The same change is made for `err_count`. Annoyingly, this requires the
introduction of `err_count_excluding_lint_errs` for one place, to
preserve existing error printing behaviour. But I still think the change
is worthwhile overall.
2024-02-22 08:03:47 +11:00
Nicholas Nethercote
1e16927ef3 Remove an out-of-date comment. 2024-02-22 08:03:39 +11:00
Nicholas Nethercote
1407057b16 Remove some no-longer-needed pub(crate) markers. 2024-02-21 11:03:33 +11:00
Nicholas Nethercote
8f20a54c6d Merge diagnostic_builder.rs into diagnostic.rs.
Because:
- `diagnostic_builder.rs` is small (282 lines),
- `Diagnostic` and `DiagnosticBuilder` are closely related types, and
- there's already an `impl DiagnosticBuilder` block in `diagnostic.rs`.

At the same time, reorder a few of things already in `diagnostic.rs`,
e.g. move `struct Diagnostic` just before `impl Diagnostic`.

This commit only moves code around. There are no functional changes.
2024-02-21 11:03:31 +11:00
bors
29f87ade9d Auto merge of #120576 - nnethercote:merge-Diagnostic-DiagnosticBuilder, r=davidtwco
Overhaul `Diagnostic` and `DiagnosticBuilder`

Implements the first part of https://github.com/rust-lang/compiler-team/issues/722, which moves functionality and use away from `Diagnostic`, onto `DiagnosticBuilder`.

Likely follow-ups:
- Move things around, because this PR was written to minimize diff size, so some things end up in sub-optimal places. E.g. `DiagnosticBuilder` has impls in both `diagnostic.rs` and `diagnostic_builder.rs`.
- Rename `Diagnostic` as `DiagInner` and `DiagnosticBuilder` as `Diag`.

r? `@davidtwco`
2024-02-20 12:05:09 +00:00
Nicholas Nethercote
f6f8779843 Reduce capabilities of Diagnostic.
Currently many diagnostic modifier methods are available on both
`Diagnostic` and `DiagnosticBuilder`. This commit removes most of them
from `Diagnostic`. To minimize the diff size, it keeps them within
`diagnostic.rs` but changes the surrounding `impl Diagnostic` block to
`impl DiagnosticBuilder`. (I intend to move things around later, to give
a more sensible code layout.)

`Diagnostic` keeps a few methods that it still needs, like `sub`,
`arg`, and `replace_args`.

The `forward!` macro, which defined two additional methods per call
(e.g. `note` and `with_note`), is replaced by the `with_fn!` macro,
which defines one additional method per call (e.g. `with_note`). It's
now also only used when necessary -- not all modifier methods currently
need a `with_*` form. (New ones can be easily added as necessary.)

All this also requires changing `trait AddToDiagnostic` so its methods
take `DiagnosticBuilder` instead of `Diagnostic`, which leads to many
mechanical changes. `SubdiagnosticMessageOp` gains a type parameter `G`.

There are three subdiagnostics -- `DelayedAtWithoutNewline`,
`DelayedAtWithNewline`, and `InvalidFlushedDelayedDiagnosticLevel` --
that are created within the diagnostics machinery and appended to
external diagnostics. These are handled at the `Diagnostic` level, which
means it's now hard to construct them via `derive(Diagnostic)`, so
instead we construct them by hand. This has no effect on what they look
like when printed.

There are lots of new `allow` markers for `untranslatable_diagnostics`
and `diagnostics_outside_of_impl`. This is because
`#[rustc_lint_diagnostics]` annotations were present on the `Diagnostic`
modifier methods, but missing from the `DiagnosticBuilder` modifier
methods. They're now present.
2024-02-20 13:22:17 +11:00
Nicholas Nethercote
b18f3e11fa Prefer DiagnosticBuilder over Diagnostic in diagnostic modifiers.
There are lots of functions that modify a diagnostic. This can be via a
`&mut Diagnostic` or a `&mut DiagnosticBuilder`, because the latter type
wraps the former and impls `DerefMut`.

This commit converts all the `&mut Diagnostic` occurrences to `&mut
DiagnosticBuilder`. This is a step towards greatly simplifying
`Diagnostic`. Some of the relevant function are made generic, because
they deal with both errors and warnings. No function bodies are changed,
because all the modifier methods are available on both `Diagnostic` and
`DiagnosticBuilder`.
2024-02-19 20:23:20 +11:00
bors
c9c83cca51 Auto merge of #121265 - klensy:bump-18-02-24, r=Mark-Simulacrum
bump some deps

First commit dedupes darling* crates and remove one more syn 1.* dep
Second one bumps windows crate to 0.52
2024-02-18 16:54:15 +00:00
klensy
35fe26757a windows bump to 0.52 2024-02-18 16:02:16 +03:00
Matthias Krüger
45d5773704
Rollup merge of #121085 - davidtwco:always-eager-diagnostics, r=nnethercote
errors: only eagerly translate subdiagnostics

Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context.

This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change).

r? ```@nnethercote```
2024-02-17 18:47:40 +01:00
Guillaume Gomez
670bdbf808
Rollup merge of #121111 - trevyn:associated-type-suggestion, r=davidtwco
For E0038, suggest associated type if available

Closes #116434
2024-02-16 17:08:12 +01:00
bors
1be468815c Auto merge of #120486 - reitermarkus:use-generic-nonzero, r=dtolnay
Use generic `NonZero` internally.

Tracking issue: https://github.com/rust-lang/rust/issues/120257
2024-02-16 07:46:31 +00:00
bors
cbddf31863 Auto merge of #121142 - GuillaumeGomez:rollup-5qmksjw, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #120449 (Document requirements for unsized {Rc,Arc}::from_raw)
 - #120505 (Fix BTreeMap's Cursor::remove_{next,prev})
 - #120672 (std::thread update freebsd stack guard handling.)
 - #121088 (Implicitly enable evex512 if avx512 is enabled)
 - #121104 (Ignore unsized types when trying to determine the size of the original type)
 - #121107 (Fix msg for verbose suggestions with confusable capitalization)
 - #121113 (Continue compilation even if inherent impl checks fail)
 - #121120 (Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-15 17:00:55 +00:00
Guillaume Gomez
3c8705402a
Rollup merge of #121107 - estebank:capitalization-suggestion, r=michaelwoerister
Fix msg for verbose suggestions with confusable capitalization

When encountering a verbose/multipart suggestion that has changes that are only caused by different capitalization of ASCII letters that have little differenciation, expand the message to highlight that fact (like we already do for inline suggestions).

The logic to do this was already present, but implemented incorrectly.
2024-02-15 14:33:02 +01:00
bors
fa9f77ff35 Auto merge of #120931 - chenyukang:yukang-cleanup-hashmap, r=michaelwoerister
Clean up potential_query_instability with FxIndexMap and UnordMap

From https://github.com/rust-lang/rust/pull/120485#issuecomment-1916437191

r? `@michaelwoerister`
2024-02-15 12:36:37 +00:00
David Wood
b80fc5d4e8
errors: only eagerly translate subdiagnostics
Subdiagnostics don't need to be lazily translated, they can always be
eagerly translated. Eager translation is slightly more complex as we need
to have a `DiagCtxt` available to perform the translation, which involves
slightly more threading of that context.

This slight increase in complexity should enable later simplifications -
like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages
into the diagnostic structs rather than having them in separate files
(working on that was what led to this change).

Signed-off-by: David Wood <david@davidtw.co>
2024-02-15 10:34:41 +00:00
Markus Reiter
746a58d435
Use generic NonZero internally. 2024-02-15 08:09:42 +01:00
trevyn
220e8a7484 For E0038, suggest associated type if available 2024-02-14 12:42:32 -08:00
Esteban Küber
8d4d572e4d Fix msg for verbose suggestions with confusable capitalization
When encountering a verbose/multipart suggestion that has changes
that are only caused by different capitalization of ASCII letters that have
little differenciation, expand the message to highlight that fact (like we
already do for inline suggestions).

The logic to do this was already present, but implemented incorrectly.
2024-02-14 20:15:13 +00:00
Oli Scherer
bad2cb08de
Rollup merge of #121015 - nnethercote:opt-delayed-bug, r=oli-obk
Optimize `delayed_bug` handling.

Once we have emitted at least one error, delayed bugs won't be used. So we can (a) we can (a) discard any existing delayed bugs, and (b) stop recording any new delayed bugs.

This eliminates a longstanding `FIXME` comment. There should be no soundness issues because it's not possible to un-emit an error.

r? `@oli-obk`
2024-02-14 11:53:40 +01:00
yukang
3f27e4b3ea clean up potential_query_instability with FxIndexMap and UnordMap 2024-02-14 18:36:37 +08:00
bors
cc1c0990ab Auto merge of #120454 - clubby789:cargo-update, r=Nilstrieb
`cargo update`

Run `cargo update`, with some pinning and fixes necessitated by that. This *should* unblock #112865

There's a couple of places where I only pinned a dependency in one location - this seems like a bit of a hack, but better than duplicating the FIXME across all `Cargo.toml` where a dependency is introduced.

cc `@Nilstrieb`
2024-02-14 05:27:31 +00:00
Nicholas Nethercote
71f2e3a095 Optimize delayed_bug handling.
Once we have emitted at least one error, delayed bugs won't be used. So
we can (a) we can (a) discard any existing delayed bugs, and (b) stop
recording any new delayed bugs.

This eliminates a longstanding `FIXME` comment. There should be no
soundness issues because it's not possible to un-emit an error.
2024-02-14 08:13:06 +11:00
clubby789
4de3a3af4a Bump indexmap
`swap` has been deprecated in favour of `swap_remove` - the behaviour
is the same though.
2024-02-13 21:03:34 +00:00
Nicholas Nethercote
56b451a67a Fix DiagCtxtInner::reset_err_count.
Several fields were not being reset. Using destructuring makes it much
harder to miss a field.
2024-02-14 07:54:05 +11:00
Nicholas Nethercote
c1ffb0b675 Remove force_print_diagnostic.
There are a couple of places where we call
`inner.emitter.emit_diagnostic` directly rather than going through
`inner.emit_diagnostic`, to guarantee the diagnostic is printed. This
feels dubious to me, particularly the bypassing of `TRACK_DIAGNOSTIC`.

This commit removes those.
- In `print_error_count`, it uses `ForceWarning` instead of `Warning`.
- It removes `DiagCtxtInner::failure_note`, because it only has three
  uses and direct use of `emit_diagnostic` is consistent with other
  similar locations.
- It removes `force_print_diagnostic`, and adds `struct_failure_note`,
  and updates `print_query_stack` accordingly, which makes it more
  normal. That location doesn't seem to need forced printing anyway.
2024-02-14 07:51:53 +11:00
Nicholas Nethercote
bdc6d82f9a Make struct_span_note call struct_note.
So it follows the same pattern as all the other `struct_span_*` methods.
2024-02-14 07:50:54 +11:00
Nicholas Nethercote
9f2aa09765 Remove good_path_delayed_bug.
It's only has a single remaining purpose: to ensure that a diagnostic is
printed when `trimmed_def_paths` is used. It's an annoying mechanism:
weak, with odd semantics, badly named, and gets in the way of other
changes.

This commit replaces it with a simpler `must_produce_diag` mechanism,
getting rid of a diagnostic `Level` along the way.
2024-02-13 09:33:35 +11:00
Matthias Krüger
f08ece38a8
Rollup merge of #120833 - nnethercote:more-internal-emit_diagnostics-cleanups, r=oli-obk
More internal emit diagnostics cleanups

Miscellaneous improvements.

r? ``@oli-obk``
2024-02-12 18:04:07 +01:00
Matthias Krüger
d0873c7a11 constify a couple thread_local statics 2024-02-12 16:25:39 +01:00
Nicholas Nethercote
1f39c8b08f Change level used in print_error_count.
From `Fatal` to `Error`. It has no functional effect, but `Error` makes
more sense and lines up better with the `Warning` level used just above.
2024-02-12 18:39:20 +11:00
Nicholas Nethercote
d4b77f64e4 Tweak delayed bug mentions.
Now that we have both `delayed_bug` and `span_delayed_bug`, it makes
sense to use the generic term "delayed bug" more.
2024-02-12 18:39:20 +11:00
Nicholas Nethercote
30774b0061 Remove final unwanted unchecked_error_guaranteed calls.
Now that error counts can't go up and down due to stashing/stealing, we
have a nice property:

  (err_count > 0) iff (an ErrorGuaranteed has been produced)

So we can now record `ErrorGuaranteed`s within `DiagCtxt` and use that
in methods like `has_error`, instead of checking that the count is
greater than 0 and calling `unchecked_error_guaranteed` to create the
`ErrorGuaranteed`.

In fact, we can record a `Vec<ErrorGuaranteed>` and use its length to
count the number, instead of maintaining a separate count.
2024-02-12 18:29:19 +11:00
Nicholas Nethercote
b7b6ebca0c Fix inconsistencies in the diagnostic API methods.
- Remove low-value comments about functionality that is obvious.

- Add missing `track_caller` attributes -- every method should have one.

- Adjust `rustc_lint_diagnostic` attributes. Every method involving a
  `impl Into<DiagnosticMessage>` or `impl Into<SubdiangnosticMessage>`
  argument should have one, except for those producing bugs, which
  aren't user-facing.
2024-02-12 09:16:48 +11:00
Nicholas Nethercote
c35983a748 Reorder the diagnostic API methods.
The current order is almost perfectly random. This commit puts them into
a predictable order in their own impl block, going from the highest
level (`Block`) to the lowest (`Expect`). Within each level this is the
order:

- struct_err, err
- struct_span_err, span_err
- create_err, emit_err

The first one in each pair creates a diagnostic, the second one creates
*and* emits a diagnostic. Not every method is present for every level.

The diff is messy, but other than moving methods around, the only thing
it does is create the new `impl DiagCtxt` block with its own comment.
2024-02-12 09:16:45 +11:00
Matthias Krüger
e525bc9592
Rollup merge of #120272 - long-long-float:suppress-suggestions-in-derive-macro, r=oli-obk
Suppress suggestions in derive macro

close #118809

I suppress warnings inside derive macros.

For example, the compiler emits following error by a program described in https://github.com/rust-lang/rust/issues/118809#issuecomment-1852256687 with a suggestion that indicates invalid syntax.

```
error[E0308]: `?` operator has incompatible types
 --> src/main.rs:3:17
  |
3 | #[derive(Debug, Deserialize)]
  |                 ^^^^^^^^^^^ expected `u32`, found `u64`
  |
  = note: `?` operator cannot convert from `u64` to `u32`
  = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can convert a `u64` to a `u32` and panic if the converted value doesn't fit
  |
3 | #[derive(Debug, Deserialize.try_into().unwrap())]
  |                            ++++++++++++++++++++

For more information about this error, try `rustc --explain E0308`.
error: could not compile `serde_test` (bin "serde_test") due to 2 previous errors
```

In this PR, suggestions to cast are suppressed.

```
error[E0308]: `?` operator has incompatible types
 --> src/main.rs:3:17
  |
3 | #[derive(Debug, Deserialize)]
  |                 ^^^^^^^^^^^ expected `u32`, found `u64`
  |
  = note: `?` operator cannot convert from `u64` to `u32`
  = note: this error originates in the derive macro `Deserialize` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0308`.
error: could not compile `serde_test` (bin "serde_test") due to 2 previous errors
```
2024-02-11 01:37:54 +01:00
long-long-float
1e59e66225 Fix to use for loop 2024-02-11 02:43:55 +09:00
Zalathar
a2479a4ae7 Remove unnecessary min_specialization after bootstrap
These crates all needed specialization for `newtype_index!`, which will no
longer be necessary when the current nightly eventually becomes the next
bootstrap compiler.
2024-02-10 18:15:11 +11:00
Matthias Krüger
2f1ac412ec
Rollup merge of #120828 - nnethercote:fix-stash-steal, r=oli-obk
Fix `ErrorGuaranteed` unsoundness with stash/steal.

When you stash an error, the error count is incremented. You can then use the non-zero error count to get an `ErrorGuaranteed`. You can then steal the error, which decrements the error count. You can then cancel the error.

Example code:
```
fn unsound(dcx: &DiagCtxt) -> ErrorGuaranteed {
    let sp = rustc_span::DUMMY_SP;
    let k = rustc_errors::StashKey::Cycle;
    dcx.struct_err("bogus").stash(sp, k);           // increment error count on stash
    let guar = dcx.has_errors().unwrap();           // ErrorGuaranteed from error count > 0
    let err = dcx.steal_diagnostic(sp, k).unwrap(); // decrement error count on steal
    err.cancel();                                   // cancel error
    guar                                            // ErrorGuaranteed with no error emitted!
}
```

This commit fixes the problem in the simplest way: by not counting stashed errors in `DiagCtxt::{err_count,has_errors}`.

However, just doing this without any other changes leads to over 40 ui test failures. Mostly because of uninteresting extra errors (many saying "type annotations needed" when type inference fails), and in a few cases, due to delayed bugs causing ICEs when no normal errors are printed.

To fix these, this commit adds `DiagCtxt::stashed_err_count`, and uses it in three places alongside `DiagCtxt::{has_errors,err_count}`. It's dodgy to rely on it, because unlike `DiagCtxt::err_count` it can go up and down. But it's needed to preserve existing behaviour, and at least the three places that need it are now obvious.

r? oli-obk
2024-02-09 14:41:52 +01:00
Matthias Krüger
46a0448405
Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwco
Invert diagnostic lints.

That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.

r? ````@davidtwco````
2024-02-09 14:41:50 +01:00
Nicholas Nethercote
7619792107 Fix ErrorGuaranteed unsoundness with stash/steal.
When you stash an error, the error count is incremented. You can then
use the non-zero error count to get an `ErrorGuaranteed`. You can then
steal the error, which decrements the error count. You can then cancel
the error.

Example code:
```
fn unsound(dcx: &DiagCtxt) -> ErrorGuaranteed {
    let sp = rustc_span::DUMMY_SP;
    let k = rustc_errors::StashKey::Cycle;
    dcx.struct_err("bogus").stash(sp, k);           // increment error count on stash
    let guar = dcx.has_errors().unwrap();           // ErrorGuaranteed from error count > 0
    let err = dcx.steal_diagnostic(sp, k).unwrap(); // decrement error count on steal
    err.cancel();                                   // cancel error
    guar                                            // ErrorGuaranteed with no error emitted!
}
```

This commit fixes the problem in the simplest way: by not counting
stashed errors in `DiagCtxt::{err_count,has_errors}`.

However, just doing this without any other changes leads to over 40 ui
test failures. Mostly because of uninteresting extra errors (many saying
"type annotations needed" when type inference fails), and in a few
cases, due to delayed bugs causing ICEs when no normal errors are
printed.

To fix these, this commit adds `DiagCtxt::stashed_err_count`, and uses
it in three places alongside `DiagCtxt::{has_errors,err_count}`. It's
dodgy to rely on it, because unlike `DiagCtxt::err_count` it can go up
and down. But it's needed to preserve existing behaviour, and at least
the three places that need it are now obvious.
2024-02-09 13:50:03 +11:00
long-long-float
4e7941c2c5 Check with overlaps_or_adjacent 2024-02-09 01:03:38 +09:00
Oli Scherer
6af2d3cc90 Fix span_bug! backtraces 2024-02-08 14:44:52 +00:00
Matthias Krüger
87e1e05aa1
Rollup merge of #120734 - nnethercote:SubdiagnosticMessageOp, r=compiler-errors
Add `SubdiagnosticMessageOp` as a trait alias.

It avoids a lot of repetition.

r? matthewjasper
2024-02-08 09:06:36 +01:00
Nicholas Nethercote
6b175a848d Add SubdiagnosticMessageOp as a trait alias.
It avoids a lot of repetition.
2024-02-08 13:02:44 +11:00
Nicholas Nethercote
6889fe3806 Rename unchecked_claim_error_was_emitted as unchecked_error_guaranteed.
It's more to-the-point.
2024-02-07 19:30:59 +11:00
Nicholas Nethercote
97c157fe1e Tighten up ErrorGuaranteed handling.
- In `emit_producing_error_guaranteed`, only allow `Level::Error`.
- In `emit_diagnostic`, only produce `ErrorGuaranteed` for `Level` and
  `DelayedBug`. (Not `Bug` or `Fatal`. They don't need it, because the
  relevant `emit` methods abort.)
- Add/update various comments.
2024-02-07 18:57:47 +11:00
Nicholas Nethercote
8d1c20a539 Remove return value from emit_stashed_diagnostics.
It's never used.
2024-02-07 09:54:59 +11:00
Matthias Krüger
a3d3ccf098
Rollup merge of #120575 - nnethercote:simplify-codegen-diag-handling, r=estebank
Simplify codegen diagnostic handling

Some nice improvements. Details in the individual commit logs.

r? ````@estebank````
2024-02-06 19:40:06 +01:00
Matthias Krüger
5587be8164
Rollup merge of #120520 - nnethercote:rename-good-path, r=oli-obk
Some cleanups around diagnostic levels.

Plus some refactoring in and around diagnostic levels and emission. Details in the individual commit logs.

r? ````@oli-obk````
2024-02-06 19:40:06 +01:00
Nicholas Nethercote
0ac1195ee0 Invert diagnostic lints.
That is, change `diagnostic_outside_of_impl` and
`untranslatable_diagnostic` from `allow` to `deny`, because more than
half of the compiler has be converted to use translated diagnostics.

This commit removes more `deny` attributes than it adds `allow`
attributes, which proves that this change is warranted.
2024-02-06 13:12:33 +11:00
long-long-float
4909258ae8 Check in push_suggestion 2024-02-06 00:32:19 +09:00
Nicholas Nethercote
d9508a1fd2 Make Emitter::emit_diagnostic consuming.
All the other `emit`/`emit_diagnostic` methods were recently made
consuming (e.g. #119606), but this one wasn't. But it makes sense to.

Much of this is straightforward, and lots of `clone` calls are avoided.
There are a couple of tricky bits.
- `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and
  returns a pair. Instead it takes the two fields from `Diagnostic` that
  it used (`span` and `suggestions`) as `&mut`, and modifies them. This
  is necessary to avoid the cloning of `diag.children` in two emitters.
- `from_errors_diagnostic` is rearranged so various uses of `diag` occur
  before the consuming `emit_diagnostic` call.
2024-02-05 21:27:01 +11:00
Matthias Krüger
ca36ed27be
Rollup merge of #119600 - aDotInTheVoid:comment-fix, r=compiler-errors
Remove outdated references to librustc_middle

The relevant comment is now in 791a53f380/compiler/rustc_middle/src/tests.rs (L3-L13)
2024-02-05 06:37:14 +01:00
Nicholas Nethercote
59e0bc2de7 Split Level::DelayedBug in two.
The two kinds of delayed bug have quite different semantics so a
stronger conceptual separation is nice. (`is_error` is a good example,
because the two kinds have different behaviour.)

The commit also moves the `DelayedBug` variant after `Error` in `Level`,
to reflect the fact that it's weaker than `Error` -- it might trigger an
error but also might not. (The pre-existing `downgrade_to_delayed_bug`
function also reflects the notion that delayed bugs are lower/after
normal errors.)

Plus it condenses some of the comments on `Level` into a table, for
easier reading, and introduces `can_be_top_or_sub` to indicate which
levels can be used in top-level diagnostics vs. subdiagnostics.

Finally, it renames `DiagCtxtInner::span_delayed_bugs` as
`DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because
some delayed bugs don't have a span.
2024-02-05 10:03:01 +11:00
Nicholas Nethercote
c367386832 Refactor emit_diagnostic.
- Combine two different blocks involving
  `diagnostic.level.get_expectation_id()` into one.
- Combine several `if`s involving `diagnostic.level` into a single
  `match`.

This requires reordering some of the operations, but this has no
functional effect.
2024-02-05 10:02:26 +11:00
Nicholas Nethercote
5dd0431386 Tighten the assertion in downgrade_to_delayed_bug.
I.e. `Bug` and `Fatal` level diagnostics are never downgraded.
2024-02-05 08:16:30 +11:00
Nicholas Nethercote
e8c3cbf44b Make Diagnostic::is_error return false for Level::FailureNote.
It doesn't affect behaviour, but makes sense with (a) `FailureNote` having
`()` as its emission guarantee, and (b) in `Level` the `is_error` levels
now are all listed before the non-`is_error` levels.
2024-02-05 08:16:30 +11:00
Matthias Krüger
019d28151d
Rollup merge of #120573 - nnethercote:rm-BorrowckErrors-tainted_by_errors, r=oli-obk
Remove `BorrowckErrors::tainted_by_errors`

This PR removes one of the `tainted_by_errors` occurrences, replacing it with direct use of `ErrorGuaranteed`.

r? `@oli-obk`
2024-02-03 21:29:43 +01:00
Nicholas Nethercote
be64802854 Use StringPart more. 2024-02-03 09:02:50 +11:00
Nicholas Nethercote
0621cd46f2 Simplify future breakage control flow.
`emit_future_breakage` calls
`self.dcx().take_future_breakage_diagnostics()` and then passes the
result to `self.dcx().emit_future_breakage_report(diags)`. This commit
removes the first of these and lets `emit_future_breakage_report` do the
taking.

It also inlines and removes what is left of `emit_future_breakage`,
which has a single call site.
2024-02-03 09:02:50 +11:00
Nicholas Nethercote
6fdaf3ef7f Use DiagnosticArgName in a few more places. 2024-02-03 09:02:50 +11:00
Nicholas Nethercote
df322fc29f Remove some unnecessary clone calls. 2024-02-03 09:02:50 +11:00
Nicholas Nethercote
8ba25d0989 SilentEmitter::fatal_note doesn't need to be optional. 2024-02-03 09:02:50 +11:00
Nicholas Nethercote
a9a2e1565a Diagnostic cleanups
- `emitted_at` isn't used outside the crate.
- `code` and `messages` are public fields, so there's no point have
  trivial getters/setters for them.
- `suggestions` is public, so the comment about "functionality on
  `Diagnostic`" isn't needed.
2024-02-03 09:02:50 +11:00
Nicholas Nethercote
585367f15f Remove an out-of-date comment.
`DiagnosticBuilderInner` was removed some time ago.
2024-02-03 09:02:50 +11:00
Nicholas Nethercote
2e6bea5968 Inline and remove DiagnosticBuilder::into_diagnostic.
It now has a single call site.
2024-02-02 14:35:51 +11:00
Nicholas Nethercote
2621f7fd9b Rework StringPart.
When there are two possibilities, both of which use a `String`, it's
nicer to use a struct than an enum. Especially when mapping the contents
into a tuple.
2024-02-01 19:23:01 +11:00
Nicholas Nethercote
26eb6da4e7 Fit more values into DiagnosticArgValue::Number.
It contains an `i128`, but when creating them we convert any number
outside the range -100..100 to a string, because Fluent uses an `f64`.
It's all a bit strange.

This commit changes the `i128` to an `i32`, which fits safely in
Fluent's `f64`, and removes the -100..100 range check. This means that
only integers outside the range of `i32` will be converted to strings.
2024-02-01 19:18:45 +11:00