Commit Graph

746 Commits

Author SHA1 Message Date
Michael Goulet
f361b591ef
Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errors
Cleanup error handlers: round 5

More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171.

r? ````@compiler-errors````
2024-01-05 10:57:21 -05:00
Nicholas Nethercote
453fface11 Add some comments to Emitter.
There are three functions only used for the JSON format.
2024-01-05 10:49:35 +11:00
Nicholas Nethercote
c4d63c7f76 Rename AnnotateSnippetEmitterWriter as AnnotateSnippetEmitter.
For consistency with other `Emitter` impls.
2024-01-05 10:37:44 +11:00
Nicholas Nethercote
cb9abcae79 Rename EmitterWriter as HumanEmitter.
For consistency with other `Emitter` impls, such as `JsonEmitter`,
`SilentEmitter`, `SharedEmitter`, etc.
2024-01-05 10:02:40 +11:00
Nicholas Nethercote
cf9484e615 Remove -Zreport-delayed-bugs.
It's not used within the repository in any way (e.g. in tests), and
doesn't seem useful.
2024-01-04 17:16:07 +11:00
Nicholas Nethercote
8388112970 Remove is_lint field from Level::Error.
Because it's redundant w.r.t. `Diagnostic::is_lint`, which is present
for every diagnostic level.

`struct_lint_level_impl` was the only place that set the `Error` field
to `true`, and it's also the only place that calls
`Diagnostic::is_lint()` to set the `is_lint` field.
2024-01-04 16:09:31 +11:00
vuittont60
b2db793f30
compiler: fix typos
librustdoc: fix typos
2024-01-04 10:08:54 +08:00
Nicholas Nethercote
1e92223925 Remove unused DiagnosticBuilder::struct_almost_fatal.
`create_almost_fatal` and `emit_almost_fatal` are always used instead.
2024-01-04 07:55:59 +11:00
Nicholas Nethercote
b4a6239984 Fix forward! so it doesn't require trailing commas in some cases. 2024-01-03 19:40:43 +11:00
Nicholas Nethercote
caefa55347 Fix up forward! decls.
- Move comments onto corresponding `Diagnostic` methods.
- Make formatting more consistent.
2024-01-03 19:40:43 +11:00
Nicholas Nethercote
096b844a2b Remove forward for downgrade_to_delayed_bug.
It's not used, and doesn't quite fit the general pattern.

Also, `Diagnostic::downgrade_to_delayed_bug` doesn't need to return
`&mut Self` for the same reason.
2024-01-03 19:40:43 +11:00
Nicholas Nethercote
505c1371d0 Rename some Diagnostic setters.
`Diagnostic` has 40 methods that return `&mut Self` and could be
considered setters. Four of them have a `set_` prefix. This doesn't seem
necessary for a type that implements the builder pattern. This commit
removes the `set_` prefixes on those four methods.
2024-01-03 19:40:20 +11:00
Martin Nordholts
231dbbcb6a rustc_lint: Make LintLevelsProvider::current_specs() return &FxIndexMap
So that lint iteration order becomes predicitable. Discovered with
`rustc::potential_query_instability`.
2023-12-31 14:35:28 +01:00
Nicholas Nethercote
99472c7049 Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
Nicholas Nethercote
d51db05d7e Remove ParseSess methods that duplicate DiagCtxt methods.
Also add missing `#[track_caller]` attributes to `DiagCtxt` methods as
necessary to keep tests working.
2023-12-24 07:59:21 +11:00
Nicholas Nethercote
2cd14bc939 Remove DiagnosticBuilder::forget_guarantee.
It's unused. And this means `DiagnosticBuilderInner` no longer needs to
be separate from `DiagnosticBuilder`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
3db58e636f Fix a comment.
There are quite a few hand-written `IntoDiagnostic` impls.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
394430166e Use pub(crate) in a couple of places. 2023-12-23 13:23:28 +11:00
Nicholas Nethercote
e0461f93c9 Take full advantage of a use Level::*;.
Some of the `Level::` qualifiers in this file are omitted. This commit
removes the remainder.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
49040d088a Remove LabelKind.
It has three variants, but only `LabelKind::Label` is ever used. This
means `SingleLabelManySpans::kind` can also be removed.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
ce0f703554 Remove SubDiagnostic::render_span.
It's only ever set to `None`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
125337bd68 Remove render_span args from Diagnostic::{sub,sub_with_highlight}.
They're always `None`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
824667f753 Improve some names.
Lots of vectors of messages called `message` or `msg`. This commit
pluralizes them.

Note that `emit_message_default` and `emit_messages_default` both
already existed, and both process a vector, so I renamed the former
`emit_messages_default_inner` because it's called by the latter.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
d7a3b6291c Remove Diagnostic::new_with_code.
Its single use can be replaced with `Diagnostic::new_with_messages`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
1f08bfa383 Remove DiagCtxtInner::span_bug.
`DiagCtxt::span_bug` is different to the other `DiagCtxt::span_*`
methods. This commit makes it the same, which requires changing
`DiagCtxt::span_delayed_bug` to not do everything within the
`inner.borrow_mut()`.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
1502596ca2 Introduce DiagCtxt::treat_next_err_as_bug.
To fix a FIXME.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
6f147afea9 Remove unnecessary line breaks from two string literals. 2023-12-23 13:23:28 +11:00
Nicholas Nethercote
a108a3bd8e Tweak flush_delayed.
- Take a `Vec` instead of an iterator, because that's all that is
  needed.
- Do an early return for the "no bugs" case.
- Use `enumerate` and an `i == 0` test to identify the first bug.

Those changes mean the `no_bug` variable can be removed, which I found
hard to read.
2023-12-23 13:23:28 +11:00
Nicholas Nethercote
757d6f6ef8 Give DiagnosticBuilder a default type.
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the
most common diagnostic level. It makes sense to do likewise for the
closely-related (and much more widely used) `DiagnosticBuilder` type,
letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just
`DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many
multi-line things becoming single line things.
2023-12-23 13:23:10 +11:00
Nicholas Nethercote
aec78dd695 Fix a couple of left-over references to Handler. 2023-12-23 13:18:50 +11:00
Nicholas Nethercote
1b3695887f Improve use items in compiler/rustc_errors/src/lib.rs.
There are a bunch of them about 400 lines down, which is weird and
annoying. This commit moves them up and puts them in a more sensible
order.
2023-12-23 13:18:50 +11:00
Nicholas Nethercote
de303b87c9 Streamline struct_lint_level.
We can just get the error level in the `match` and then use
`DiagnosticBuilder::new`. This then means a number of `DiagCtxt`
functions are no longer needed, because this was the one place that used
them.

Note: the commit changes the treatment of spans for `Expect`, which was
different to all the other cases, but this has no apparent effect.
2023-12-23 13:18:50 +11:00
Nicholas Nethercote
c8c1615df0 Add comments to Level.
There is room for improvement on some of these, but something is better
than nothing.
2023-12-23 13:18:50 +11:00
Nicholas Nethercote
006446e373 Remove unused DiagCtxt::span_bug_no_panic. 2023-12-19 20:58:49 +11:00
Nicholas Nethercote
286329870d De-weirdify fatally_break_rust.
The easter egg ICE on `break rust` is weird: it's the one ICE in the
entire compiler that doesn't immediately abort, which makes it
annoyingly inconsistent.

This commit changes it to abort. As part of this, the extra notes are
now appended onto the bug dignostic, rather than being printed as
individual note diagnostics, which changes the output format a bit.
These changes don't interferes with the joke, but they do help with my
ongoing cleanups to error handling.
2023-12-19 20:58:45 +11:00
Nicholas Nethercote
072c157d68 Introduce DiagCtxt::struct_bug.
This makes `DiagCtxt::bug` look like the other similar functions.
2023-12-19 09:52:19 +11:00
Nicholas Nethercote
9ed87336b0 Factor out common emit_producing_guarantee code. 2023-12-19 09:52:19 +11:00
Nicholas Nethercote
f5459201e0 Add EmitResult associated type to EmissionGuarantee.
This lets different error levels share the same return type from
`emit_*`.

- A lot of inconsistencies in the `DiagCtxt` API are removed.
- `Noted` is removed.
- `FatalAbort` is introduced for fatal errors (abort via `raise`),
  replacing the `EmissionGuarantee` impl for `!`.
- `Bug` is renamed `BugAbort` (to avoid clashing with `Level::Bug` and
  to mirror `FatalAbort`), and modified to work in the new way with bug
  errors (abort via panic).
- Various diagnostic creators and emitters updated to the new, better
  signatures. Note that `DiagCtxt::bug` no longer needs to call
  `panic_any`, because `emit` handles that.

Also shorten the obnoxiously long
`diagnostic_builder_emit_producing_guarantee` name.
2023-12-19 09:52:02 +11:00
Nicholas Nethercote
3a5f28f7e8 Remove struct_diagnostic and G::make_diagnostic_builder.
`EmissionGuarantee` no longer determines the error level, the `create_*`
functions do.
2023-12-19 09:19:29 +11:00
Nicholas Nethercote
e7724a2e31 Add level arg to into_diagnostic.
And make all hand-written `IntoDiagnostic` impls generic, by using
`DiagnosticBuilder::new(dcx, level, ...)` instead of e.g.
`dcx.struct_err(...)`.

This means the `create_*` functions are the source of the error level.
This change will let us remove `struct_diagnostic`.

Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`,
it's necessary to pass diagnostics tests now that it's used in
`into_diagnostic` functions.
2023-12-19 09:19:25 +11:00
Nicholas Nethercote
cea683c08f Use .into_diagnostic() less.
This commit replaces this pattern:
```
err.into_diagnostic(dcx)
```
with this pattern:
```
dcx.create_err(err)
```
in a lot of places.

It's a little shorter, makes the error level explicit, avoids some
`IntoDiagnostic` imports, and is a necessary prerequisite for the next
commit which will add a `level` arg to `into_diagnostic`.

This requires adding `track_caller` on `create_err` to avoid mucking up
the output of `tests/ui/track-diagnostics/track4.rs`. It probably should
have been there already.
2023-12-18 20:46:13 +11:00
Nicholas Nethercote
f6aa418c9f Rename many DiagCtxt and EarlyDiagCtxt locals. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
f422dca3ae Rename many DiagCtxt arguments. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
20cb12ede1 Rename SilentEmitter::fatal_handler as SilentEmitter::fatal_dcx. 2023-12-18 16:06:22 +11:00
Nicholas Nethercote
9f3f1ca8c4 Rename DiagnosticBuilder::handler as DiagnosticBuilder::dcx. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
9b1f87c7e8 Rename HandlerFlags as DiagCtxtFlags. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
45f347681d Rename HandlerInner as DiagCtxtInner. 2023-12-18 16:06:21 +11:00
Nicholas Nethercote
cde19c016e Rename Handler as DiagCtxt. 2023-12-18 16:06:19 +11:00
Jubilee
30231d9afa
Rollup merge of #118993 - jyn514:cfg-color, r=WaffleLapkin,Nilstrieb
use `if cfg!` instead of `#[cfg]`

this pr is specifically for waffle because i love it <3

fixes https://github.com/rust-lang/rust/pull/118756#discussion_r1421767649

r? `@WaffleLapkin`
2023-12-15 21:32:59 -08:00
Michael Goulet
108bec6723 Simplify lint decorator derive too 2023-12-16 02:07:01 +00:00
jyn
4845665f6a use if cfg instead of #[cfg]
this pr is specifically for waffle because i love it <3
2023-12-15 13:15:40 -05:00
Matthias Krüger
d5af762fe5
Rollup merge of #118888 - compiler-errors:uplift-more-things, r=jackh726
Uplift `TypeAndMut` and `ClosureKind` to `rustc_type_ir`

Uplifts `TypeAndMut` and `ClosureKind`

I know I said I was just going to get rid of `TypeAndMut` (https://github.com/rust-lang/types-team/issues/124) but I think this is much simpler, lol

r? `@jackh726` or `@lcnr`
2023-12-15 06:50:18 +01:00
Nicholas Nethercote
9a78412511 Split Handler::emit_diagnostic in two.
Currently, `emit_diagnostic` takes `&mut self`.

This commit changes it so `emit_diagnostic` takes `self` and the new
`emit_diagnostic_without_consuming` function takes `&mut self`.

I find the distinction useful. The former case is much more common, and
avoids a bunch of `mut` and `&mut` occurrences. We can also restrict the
latter with `pub(crate)` which is nice.
2023-12-15 10:13:12 +11:00
Nicholas Nethercote
2c2c7f13a6 Remove Handler::emit_diag_at_span.
Compare `Handler::warn` and `Handler::span_warn`. Conceptually they are
almost identical. But their implementations are weirdly different.

`warn`:
- calls `DiagnosticBuilder::<()>::new(self, Warning(None), msg)`, then `emit()`
- which calls `G::diagnostic_builder_emit_producing_guarantee(self)`
- which calls `handler.emit_diagnostic(&mut db.inner.diagnostic)`

`span_warn`:
- calls `self.emit_diag_at_span(Diagnostic::new(Warning(None), msg), span)`
- which calls `self.emit_diagnostic(diag.set_span(sp))`

I.e. they both end up at `emit_diagnostic`, but take very different
routes to get there.

This commit changes `span_*` and similar ones to not use
`emit_diag_at_span`. Instead they just call `struct_span_*` + `emit`.

Some nice side-effects of this:
- `span_fatal` and `span_fatal_with_code` don't need
  `FatalError.raise()`, because `emit` does that.
- `span_err` and `span_err_with_code` doesn't need `unwrap`.
- `struct_span_note`'s `span` arg type is changed from `Span` to
  `impl Into<MultiSpan>` like all the other functions.
2023-12-15 09:48:00 +11:00
Nicholas Nethercote
b0d5b442e9 Avoid DiagnosticBuilder::<T>::new calls.
The `Handler` functions that directly emit diagnostics can be more
easily implemented using `struct_foo(msg).emit()`. This mirrors
`Handler::emit_err` which just does `create_err(err).emit()`.

`Handler::bug` is not converted because of weirdness involving
conflation bugs and fatal errors with `EmissionGuarantee`. I'll fix that
later.
2023-12-15 09:42:14 +11:00
Nicholas Nethercote
19d28a4f28 Change msg: impl Into<String> for bug diagnostics.
To `msg: impl Into<DiagnosticMessage>`, like all the other diagnostics.
For consistency.
2023-12-15 09:42:14 +11:00
Nicholas Nethercote
7bdb227567 Avoid struct_diagnostic where possible.
It's necessary for `derive(Diagnostic)`, but is best avoided elsewhere
because there are clearer alternatives.

This required adding `Handler::struct_almost_fatal`.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote
dc05a30996 Inline and remove HandlerInner::emit_diag_at_span.
It has a single call site.
2023-12-14 15:53:55 +11:00
Nicholas Nethercote
43a0f55506 Remove unused Handler::treat_err_as_bug. 2023-12-14 15:53:55 +11:00
Michael Goulet
b8ea6e686f Uplift ClosureKind 2023-12-12 23:24:44 +00:00
Matthias Krüger
dfc5ffacd3
Rollup merge of #118756 - jyn514:colors, r=estebank
use bold magenta instead of bold white for highlighting

according to a poll of gay people in my phone, purple is the most popular color to use for highlighting

| color      | percentage |
| ---------- | ---------- |
| bold white | 6%         |
| blue       | 14%        |
| cyan       | 26%        |
| purple     | 37%        |
| magenta    | 17%        |

unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason.
until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it.

instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty.

before:
![image](https://github.com/rust-lang/rust/assets/23638587/9a89eee2-8b89-422e-8554-812827bb2a23)

after:
![image](https://github.com/rust-lang/rust/assets/23638587/5bf3a917-8a20-4afd-af3e-f9491d0d57f5)

other colors for comparison:
blue: ![image](https://github.com/rust-lang/rust/assets/23638587/6f199c7b-d598-4009-8ffc-6b7b1d0d1f8c)
cyan: ![image](https://github.com/rust-lang/rust/assets/23638587/a77e4fe3-563e-4aa5-ae92-745bb67287d1)
purple: ![image](https://github.com/rust-lang/rust/assets/23638587/ffe603fb-d811-4106-95a9-4dd4c955924c)
magenta without bolding: ![image](https://github.com/rust-lang/rust/assets/23638587/cf927e5f-8b25-4dc2-b8e7-32905a11a459)

r? ``@estebank``
2023-12-12 06:52:49 +01:00
surechen
40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Guillaume Gomez
0865eefcaf
Rollup merge of #118057 - bvanjoi:fix-118048, r=cjgillot
dedup for duplicate suggestions

Fixes #118048

An easy fix.
2023-12-09 14:05:09 +01:00
jyn
96b027f35d use magenta instead of bold for highlighting
according to a poll of gay people in my phone, purple is the most popular color to use for highlighting

| color      | percentage |
| ---------- | ---------- |
| bold white | 6%         |
| blue       | 14%        |
| cyan       | 26%        |
| purple     | 37%        |
| magenta    | 17%        |

unfortunately, purple is not supported by 16-color terminals, which rustc apparently wants to support for some reason.
until we require support for full 256-color terms (e.g. by doing the same feature detection as we currently do for urls), we can't use it.

instead, i have collapsed the purple votes into magenta on the theory that they're close, and also because magenta is pretty.
2023-12-08 14:30:48 -05:00
jyn
9f0c6f15ce Simplify and comment the special-casing for Windows colors 2023-12-08 14:21:16 -05:00
Nicholas Nethercote
7811c976d1 Inline and remove fatal_no_raise.
This makes `Handler::fatal` more like `Handler::{err,warn,bug,note}`.
2023-12-04 18:57:42 +11:00
Nicholas Nethercote
3ab05caa4d Make Handler::{err,bug} more like Handler::{warn,note}. 2023-12-04 18:57:42 +11:00
Nicholas Nethercote
883bdb7fda Remove HandlerInner::emit.
This is weird: `HandlerInner::emit` calls
`HandlerInner::emit_diagnostic`, but only after doing a
`treat-err-as-bug` check. Which is fine, *except* that there are
multiple others paths for an `Error` or `Fatal` diagnostic to be passed
to `HandlerInner::emit_diagnostic` without going through
`HandlerInner::emit`, e.g. `Handler::span_err` call
`Handler::emit_diag_at_span`, which calls `emit_diagnostic`.
So that suggests that the coverage for `treat-err-as-bug` is incomplete.

This commit removes `HandlerInner::emit` and moves the
`treat-err-as-bug` check to `HandlerInner::emit_diagnostic`, so it
cannot by bypassed.
2023-12-04 18:57:42 +11:00
Nicholas Nethercote
a8ff867d5c Move some HandlerInner functions to Handler.
`Handler` is a wrapper around `HanderInner`. Some functions on
on `Handler` just forward to the samed-named functions on
`HandlerInner`.

This commit removes as many of those as possible, implementing functions
on `Handler` where possible, to avoid the boilerplate required for
forwarding. The commit is moderately large but it's very mechanical.
2023-12-04 18:57:42 +11:00
Nicholas Nethercote
8c20ad6a08 Use DiagnosticBuilder::new more.
By making it generic, instead of only for `EmissionGuarantee = ()`, we
can use it everywhere.
2023-12-04 18:57:42 +11:00
Nicholas Nethercote
d51b3dbfc6 Remove some unused code, and downgrade some pubs. 2023-12-04 18:57:42 +11:00
Nicholas Nethercote
32dc78ede8 Avoid Diagnostic::new_with_code(..., None, ...).
`Diagnostic::new` can be used instead.
2023-12-04 18:57:42 +11:00
Nicholas Nethercote
ed95f397cf Always use G for EmissionGuarantee type variables.
That's what is mostly used. This commit changes a few `EM` and `E` and
`T` type variables to `G`.
2023-12-04 18:57:42 +11:00
Nicholas Nethercote
ab640ca86b Inline and remove more DiagnosticBuilder::new_diagnostic_* functions.
They each have a single call site.

Note: the `make_diagnostic_builder` calls in `lib.rs` will be replaced
in a subsequent commit.
2023-12-04 18:57:35 +11:00
Nicholas Nethercote
d4933aaf1f Inline and remove DiagnosticBuilder::new_diagnostic_* functions.
They each have a single call site.
2023-12-04 15:42:12 +11:00
Nicholas Nethercote
114380d215 Give Handler::fatal and Session::fatal the same return type.
Currently, `Handler::fatal` returns `FatalError`. But `Session::fatal`
returns `!`, because it calls `Handler::fatal` and then calls `raise` on
the result. This inconsistency is unfortunate.

This commit changes `Handler::fatal` to do the `raise` itself, changing
its return type to `!`. This is safe because there are only two calls to
`Handler::fatal`, one in `rustc_session` and one in
`rustc_codegen_cranelift`, and they both call `raise` on the result.

`HandlerInner::fatal` still returns `FatalError`, so I renamed it
`fatal_no_raise` to emphasise the return type difference.
2023-12-04 15:42:06 +11:00
bohan
199098b71b dedup for duplicate suggestions 2023-12-04 10:43:10 +08:00
Nicholas Nethercote
6e9573936f Handler tweaks.
- Avoid unnecessary `inner` local variables.
- Use `borrow_mut` everywhere (instead of the synonym `lock`).
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
c9008c6c8b Rename Handler::delay_good_path_bug as Handler::good_path_delayed_bug.
In line with the previous commits.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
2c337a072c Rename HandlerInner::delayed_span_bugs as HandlerInner::span_delayed_bugs.
For reasons similar to the previous commit.
2023-12-02 09:01:34 +11:00
Nicholas Nethercote
5d1d384443 Rename HandlerInner::delay_span_bug as HandlerInner::span_delayed_bug.
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug`
follows the pattern used everywhere else: `span_err`, `span_warning`,
etc.
2023-12-02 09:01:19 +11:00
Nicholas Nethercote
57d6f840b9 Rename *note_without_error as *note.
Because the variant name in `Level` is `Note`, and the `without_error`
suffix is omitted in similar cases like `struct_allow` and
`struct_help`.
2023-12-02 08:58:25 +11:00
Nicholas Nethercote
c3628bb970 Rename HandlerInner::failure as HandlerInner::failure_note.
To match the `FailureNote` variant of `Level`.
2023-12-02 08:58:25 +11:00
Nicholas Nethercote
7138845f61 Rename Handler::span_note_diag as struct_span_note.
Because `span_note_diag` doesn't follow the naming structure used for
the error reporting functions.
2023-12-02 08:58:25 +11:00
Nicholas Nethercote
95be8b2189 Remove an unnecessary local variable. 2023-12-02 08:58:25 +11:00
Nicholas Nethercote
b2a856ea3c Return ErrorGuaranteed from span_err_with_code methods.
`ErrorGuaranteed` should be used for all error methods involving the
`Error` level, e.g. as is done for the corresponding `span_err` methods.
2023-12-02 08:58:24 +11:00
Nicholas Nethercote
f7e3d05aa7 Inline and remove DiagnosticBuilder::new_diagnostic_fatal.
It has a single call site.
2023-12-02 08:58:24 +11:00
Nicholas Nethercote
57cd5e6551 Use rustc_fluent_macro::fluent_messages! directly.
Currently we always do this:
```
use rustc_fluent_macro::fluent_messages;
...
fluent_messages! { "./example.ftl" }
```
But there is no need, we can just do this everywhere:
```
rustc_fluent_macro::fluent_messages! { "./example.ftl" }
```
which is shorter.
2023-11-26 08:38:40 +11:00
Nilstrieb
41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Nilstrieb
21a870515b Fix clippy::needless_borrow in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`.

Then I had to remove a few unnecessary parens and muts that were exposed
now.
2023-11-21 20:13:40 +01:00
bors
85c42b751e Auto merge of #115691 - jsgf:typed-json-diags, r=est31,dtolnay
Add `$message_type` field to distinguish json diagnostic outputs

Currently the json-formatted outputs have no way to unambiguously determine which kind of message is being output. A consumer can look for specific fields in the json object (eg "message"), but there's no guarantee that in future some other kind of output will have a field of the same name.

This PR adds a `"type"` field to add json outputs which can be used to unambiguously determine which kind of output it is. The mapping is:

`diagnostic`: regular compiler diagnostics
`artifact`: artifact notifications
`future_incompat`: Future incompatibility report
`unused_extern`: Unused crate warnings/errors

This matches the "internally tagged" representation for serde enums.
2023-11-21 06:30:14 +00:00
David Tolnay
fe50c5359e
Update some more cases of "type" -> "$message_type" 2023-11-20 16:02:59 -08:00
Esteban Küber
1dfec45dc9 Remove unnecessary .collect() 2023-11-19 17:50:47 +00:00
Esteban Küber
f1ae02f4bd Don't sort span_suggestions, leave that to caller 2023-11-19 17:50:45 +00:00
Esteban Küber
42aa1273b0 When encountering struct fn call literal with private fields, suggest all builders
When encountering code like `Box(42)`, suggest `Box::new(42)` and *all*
other associated functions that return `-> Box<T>`.
2023-11-19 17:47:41 +00:00
Mark Rousskov
db3e2bacb6 Bump cfg(bootstrap)s 2023-11-15 19:41:28 -05:00
cui fliter
a44a4edc0e Fix some typos
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-11-14 23:06:50 +08:00
bors
85b8450466 Auto merge of #116866 - slanterns:inspect-stabilize, r=BurntSushi
Stabilize `result_option_inspect`

This PR stabilizes `result_option_inspect`:

```rust
// core::option

impl Option<T> {
    pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self;
}

// core::result

impl Result<T, E> {
    pub fn inspect<F: FnOnce(&T)>(self, f: F) -> Self;
    pub fn inspect_err<F: FnOnce(&E)>(self, f: F) -> Self;
}
```

<br>

Tracking issue: https://github.com/rust-lang/rust/issues/91345.
Implementation PR: https://github.com/rust-lang/rust/pull/91346.

Closes https://github.com/rust-lang/rust/issues/91345.
2023-11-13 19:46:18 +00:00
Nicholas Nethercote
1b3733e5a4 rustc: minor changes suggested by clippy perf lints. 2023-11-08 08:57:57 +11:00
Matthias Krüger
6bbe22c966
Rollup merge of #117397 - compiler-errors:dont-emit-good-path-on-panic, r=TaKO8Ki
Don't emit delayed good-path bugs on panic

This should fix #117381, cc ``@RalfJung``

As opposed to delayed bugs, delayed *good path* bugs really don't make sense to show on panics.
2023-11-01 11:29:41 +01:00