Commit Graph

934 Commits

Author SHA1 Message Date
Michael Goulet
eb79bc0470 Good path bugs are just a flavor of delayed bug 2024-01-12 03:29:59 +00:00
Nicholas Nethercote
3330940f7f Avoid repetition in flush_delayed calls.
There are two places that handle normal delayed bugs. This commit
factors out some repeated code.

Also, we can use `std::mem::take` instead of `std::mem::replace`.
2024-01-12 10:25:22 +11:00
Matthias Krüger
b3d15ebb08
Rollup merge of #119853 - klensy:rustfmt-ignore, r=cuviper
rustfmt.toml: don't ignore just any tests path, only root one

Previously ignored any `tests` path, now only /tests at repo root.

For reference, https://git-scm.com/docs/gitignore#_pattern_format
2024-01-11 19:42:53 +01:00
Matthias Krüger
f5387a1c38
Rollup merge of #119841 - nnethercote:rm-DiagnosticBuilder-buffer, r=oli-obk
Remove `DiagnosticBuilder::buffer`

`DiagnosticBuilder::buffer` doesn't do much, and part of what it does (for `-Ztreat-err-as-bug`) it shouldn't.

This PR strips it back, replaces its uses, and finally removes it, making a few cleanups in the vicinity along the way.

r? ``@oli-obk``
2024-01-11 19:42:51 +01:00
Matthias Krüger
fe97e93166
Rollup merge of #119448 - klensy:annotate-snippets-0.10, r=davidtwco
annotate-snippets: update to 0.10

Ports `annotate-snippets` to 0.10, temporary dupes versions; other crates left that depends on 0.9 is `ui_test` and `rustfmt`.
2024-01-11 19:42:49 +01:00
klensy
aa696c5a22 apply fmt 2024-01-11 15:04:48 +03:00
Nicholas Nethercote
4fd1db1aa5 Remove DiagnosticBuilder::buffer.
All its uses have been removed.
2024-01-11 18:38:05 +11:00
Nicholas Nethercote
fbe68bc40c Stop using DiagnosticBuilder::buffer in BorrowckErrors.
But we can't easily switch from `Vec<Diagnostic>` to
`Vec<DiagnosticBuilder<G>>` because there's a mix of errors and warnings
which result in different `G` types. So we must make
`DiagnosticBuilder::into_diagnostic` public, but that's ok, and it will
get more use in subsequent commits.
2024-01-11 16:55:10 +11:00
Nicholas Nethercote
552bed8048 Remove DiagnosticBuilder::into_diagnostic from -Ztreat-err-as-bug consideration.
It seems very wrong to have a `-Ztreat-err-as-bug` check here before the
error is even emitted.

Once that's done:
- `into_diagnostic` is infallible, so its return type doesn't need the
  `Option`;
- the `&'a DiagCtxt` also isn't needed, because only one callsite uses
  it, and it already have access to it via `self.dcx`;
- the comments about dcx disabling buffering are no longer true, this is
  unconditional now;
- and the `debug!` seems unnecessary... the comment greatly overstates
  its importance because few diagnostics come through `into_diagnostic`,
  and `-Ztrack-diagnostics` exists anyway.
2024-01-11 16:55:10 +11:00
Nicholas Nethercote
a0f5431e23 Move code around.
No point computing `warnings` and `errors` if we're going to return
early before they're used.
2024-01-11 16:55:10 +11:00
Nicholas Nethercote
2aac288c18 Use the right level with -Ztreat-err-as-bug.
Errors in `DiagCtxtInner::emit_diagnostic` are never set to
`Level::Bug`, because the condition never succeeds, because
`self.treat_err_as_bug()` is called *before* the error counts are
incremented.

This commit switches to `self.treat_next_err_as_bug()`, fixing the
problem. This changes the error message output to actually say "internal
compiler error".
2024-01-11 16:55:10 +11:00
Nicholas Nethercote
f0a3684c1e Inline and remove DiagCtxtInner::bump_{lint_err,err}_count.
They have one and two call sites respectively, and they just make the
code harder to read.
2024-01-11 16:54:22 +11:00
Nicholas Nethercote
dd61eba3c3 Simplify lint error counting.
Of the error levels satisfying `is_error`, `Level::Error` is the only
one that can be a lint, so there's no need to check for it.

(And even if it wasn't, it would make more sense to include
non-`Error`-but-`is_error` lints under `lint_err_count` than under
`err_count`.)
2024-01-11 07:56:20 +11:00
Nicholas Nethercote
56c3265c7b Replace warn_count.
There are four functions that adjust error and warning counts:
- `stash_diagnostic` (increment)
- `steal_diagnostic` (decrement)
- `emit_stashed_diagnostics) (decrement)
- `emit_diagnostic` (increment)

The first three all behave similarly, and only update `warn_count` for
forced warnings. But the last one updates `warn_count` for both forced
and non-forced warnings.

Seems like a bug. How should it be fixed? Well, `warn_count` is only
used in one place: `DiagCtxtInner::drop`, where it's part of the
condition relating to the printing of `good_path_delayed_bugs`. The
intention of that condition seems to be "have any errors been printed?"
so this commit replaces `warn_count` with `has_printed`, which is set
when printing occurs. This is simpler than all the ahead-of-time
incrementing and decrementing.
2024-01-11 07:56:20 +11:00
Nicholas Nethercote
8866780d02 Move DiagCtxtInner::deduplicated_warn_count.
To put it next to a similar field.
2024-01-11 07:56:20 +11:00
Nicholas Nethercote
12ba450d14 Reset lint_err_count in DiagCtxt::reset_err_count.
It's missing but should obviously be included.
2024-01-11 07:56:20 +11:00
Nicholas Nethercote
0e388f2192 Change how force-warn lint diagnostics are recorded.
`is_force_warn` is only possible for diagnostics with `Level::Warning`,
but it is currently stored in `Diagnostic::code`, which every diagnostic
has.

This commit:
- removes the boolean `DiagnosticId::Lint::is_force_warn` field;
- adds a `ForceWarning` variant to `Level`.

Benefits:
- The common `Level::Warning` case now has no arguments, replacing
  lots of `Warning(None)` occurrences.
- `rustc_session::lint::Level` and `rustc_errors::Level` are more
  similar, both having `ForceWarning` and `Warning`.
2024-01-11 07:56:17 +11:00
Nicholas Nethercote
06cf881969 Rename TRACK_DIAGNOSTICS as TRACK_DIAGNOSTIC.
Because the values put into it are functions named `track_diagnostic`
and `default_track_diagnostic`.
2024-01-11 07:55:03 +11:00
Nicholas Nethercote
700a396520 Add missing DiagnosticBuilder::eager_diagnostic method.
This lets us avoid the use of `DiagnosticBuilder::into_diagnostic` in
miri, when then means that `DiagnosticBuilder::into_diagnostic` can
become private, being now only used by `stash` and `buffer`.
2024-01-10 07:40:44 +11:00
Nicholas Nethercote
ed76b0b882 Rename consuming chaining methods on DiagnosticBuilder.
In #119606 I added them and used a `_mv` suffix, but that wasn't great.

A `with_` prefix has three different existing uses.
- Constructors, e.g. `Vec::with_capacity`.
- Wrappers that provide an environment to execute some code, e.g.
  `with_session_globals`.
- Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`.

The third case is exactly what we want, so this commit changes
`DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`.

Thanks to @compiler-errors for the suggestion.
2024-01-10 07:40:00 +11:00
Nicholas Nethercote
2ea7a37e11 Add DiagCtxt::delayed_bug.
We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit
adds `delayed_bug`, which matches pairs like `err`/`span_err` and
`warn`/`span_warn`.
2024-01-10 07:33:07 +11:00
Nicholas Nethercote
3c4f1d85af Rename {create,emit}_warning as {create,emit}_warn.
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`,
all of which use an abbreviated form.
2024-01-10 07:33:06 +11:00
Nicholas Nethercote
4864cb8aef Rename struct_span_err! as struct_span_code_err!.
Because it takes an error code after the span. This avoids the confusing
overlap with the `DiagCtxt::struct_span_err` method, which doesn't take
an error code.
2024-01-10 07:33:04 +11:00
Nicholas Nethercote
99b1b0f85c Fix incorrect comment. 2024-01-10 07:17:55 +11:00
Nicholas Nethercote
a2b765fc37 Remove -Zdont-buffer-diagnostics.
It was added in #54232. It seems like it was aimed at NLL development,
which is well in the past. Also, it looks like `-Ztreat-err-as-bug` can
be used to achieve the same effect. So it doesn't seem necessary.
2024-01-09 09:47:36 +11:00
Nicholas Nethercote
db09eb2d3a Remove {DiagCtxt,DiagCtxtInner}::emit_diagnostic_without_consuming.
They are no longer used, because
`{DiagCtxt,DiagCtxtInner}::emit_diagnostic` are used everywhere instead.

This also means `track_diagnostic` can become consuming.
2024-01-08 16:18:55 +11:00
Nicholas Nethercote
2d91c6d1bf Remove DiagnosticBuilderState.
Currently it's used for two dynamic checks:
- When a diagnostic is emitted, has it been emitted before?
- When a diagnostic is dropped, has it been emitted/cancelled?

The first check is no longer need, because `emit` is consuming, so it's
impossible to emit a `DiagnosticBuilder` twice. The second check is
still needed.

This commit replaces `DiagnosticBuilderState` with a simpler
`Option<Box<Diagnostic>>`, which is enough for the second check:
functions like `emit` and `cancel` can take the `Diagnostic` and then
`drop` can check that the `Diagnostic` was taken.

The `DiagCtxt` reference from `DiagnosticBuilderState` is now stored as
its own field, removing the need for the `dcx` method.

As well as making the code shorter and simpler, the commit removes:
- One (deprecated) `ErrorGuaranteed::unchecked_claim_error_was_emitted`
  call.
- Two `FIXME(eddyb)` comments that are no longer relevant.
- The use of a dummy `Diagnostic` in `into_diagnostic`.

Nice!
2024-01-08 16:18:54 +11:00
Nicholas Nethercote
0cb486bc5b Make emit_producing_{guarantee,nothing} consuming.
This is now possible, thanks to changes in previous commits.
2024-01-08 16:08:19 +11:00
Nicholas Nethercote
4752a923af Remove DiagnosticBuilder::delay_as_bug_without_consuming.
The existing uses are replaced in one of three ways.
- In a function that also has calls to `emit`, just rearrange the code
  so that exactly one of `delay_as_bug` or `emit` is called on every
  path.
- In a function returning a `DiagnosticBuilder`, use
  `downgrade_to_delayed_bug`. That's good enough because it will get
  emitted later anyway.
- In `unclosed_delim_err`, one set of errors is being replaced with
  another set, so just cancel the original errors.
2024-01-08 16:07:14 +11:00
Nicholas Nethercote
d406278180 Remove DiagnosticBuilder::emit_without_consuming.
A nice cleanup: it's now impossible to directly emit a
`DiagnosticBuilder` without consuming it.
2024-01-08 16:06:53 +11:00
Nicholas Nethercote
6682f243dc Remove all eight DiagnosticBuilder::*_with_code methods.
These all have relatively low use, and can be perfectly emulated with
a simpler construction method combined with `code` or `code_mv`.
2024-01-08 16:00:34 +11:00
Nicholas Nethercote
589591efde Use chaining in DiagnosticBuilder construction.
To avoid the use of a mutable local variable, and because it reads more
nicely.
2024-01-08 15:43:07 +11:00
Nicholas Nethercote
b1b9278851 Make DiagnosticBuilder::emit consuming.
This works for most of its call sites. This is nice, because `emit` very
much makes sense as a consuming operation -- indeed,
`DiagnosticBuilderState` exists to ensure no diagnostic is emitted
twice, but it uses runtime checks.

For the small number of call sites where a consuming emit doesn't work,
the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will
be removed in subsequent commits.)

Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes
consuming, while `delay_as_bug_without_consuming` is added (which will
also be removed in subsequent commits.)

All this requires significant changes to `DiagnosticBuilder`'s chaining
methods. Currently `DiagnosticBuilder` method chaining uses a
non-consuming `&mut self -> &mut Self` style, which allows chaining to
be used when the chain ends in `emit()`, like so:
```
    struct_err(msg).span(span).emit();
```
But it doesn't work when producing a `DiagnosticBuilder` value,
requiring this:
```
    let mut err = self.struct_err(msg);
    err.span(span);
    err
```
This style of chaining won't work with consuming `emit` though. For
that, we need to use to a `self -> Self` style. That also would allow
`DiagnosticBuilder` production to be chained, e.g.:
```
    self.struct_err(msg).span(span)
```
However, removing the `&mut self -> &mut Self` style would require that
individual modifications of a `DiagnosticBuilder` go from this:
```
    err.span(span);
```
to this:
```
    err = err.span(span);
```
There are *many* such places. I have a high tolerance for tedious
refactorings, but even I gave up after a long time trying to convert
them all.

Instead, this commit has it both ways: the existing `&mut self -> Self`
chaining methods are kept, and new `self -> Self` chaining methods are
added, all of which have a `_mv` suffix (short for "move"). Changes to
the existing `forward!` macro lets this happen with very little
additional boilerplate code. I chose to add the suffix to the new
chaining methods rather than the existing ones, because the number of
changes required is much smaller that way.

This doubled chainging is a bit clumsy, but I think it is worthwhile
because it allows a *lot* of good things to subsequently happen. In this
commit, there are many `mut` qualifiers removed in places where
diagnostics are emitted without being modified. In subsequent commits:
- chaining can be used more, making the code more concise;
- more use of chaining also permits the removal of redundant diagnostic
  APIs like `struct_err_with_code`, which can be replaced easily with
  `struct_err` + `code_mv`;
- `emit_without_diagnostic` can be removed, which simplifies a lot of
  machinery, removing the need for `DiagnosticBuilderState`.
2024-01-08 15:24:49 +11:00
Nicholas Nethercote
ca2fc426a9 Remove Clone impl for DiagnosticBuilder.
It seems like a bad idea, just asking for diagnostics to be emitted
multiple times.
2024-01-08 12:05:40 +11:00
klensy
5b153b52a2 annotate-snippets: update to 0.10 2024-01-07 16:53:32 +03:00
Alona Enraght-Moony
16e117cf96 Remove outdated references to librustc_middle. 2024-01-05 16:34:52 +00:00
Michael Goulet
da700b39df
Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obk
`Emitter` cleanups

Some improvements I found while looking at this code.

r? `@oli-obk`
2024-01-05 10:57:24 -05:00
Michael Goulet
c28715bf78
Rollup merge of #119567 - nnethercote:rm-Zreport-delayed-bugs, r=oli-obk
Remove `-Zreport-delayed-bugs`.

It's not used within the repository in any way (e.g. in tests), and doesn't seem useful.

It was added in #52568.

r? ````@oli-obk````
2024-01-05 10:57:22 -05:00
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
Michael Goulet
8076414f89 Don't emit delayed good-path bugs on panic 2023-10-30 10:14:43 -04:00
Nicholas Nethercote
8ff624a9f2 Clean up rustc_*/Cargo.toml.
- Sort dependencies and features sections.
- Add `tidy` markers to the sorted sections so they stay sorted.
- Remove empty `[lib`] sections.
- Remove "See more keys..." comments.

Excluded files:
- rustc_codegen_{cranelift,gcc}, because they're external.
- rustc_lexer, because it has external use.
- stable_mir, because it has external use.
2023-10-30 08:46:02 +11:00
Michael Goulet
1836c1fbbd Stash and cancel cycle errors for auto trait leakage in opaques 2023-10-26 17:58:02 +00:00
bors
f31316f7a9 Auto merge of #116962 - estebank:issue-63835, r=oli-obk
Do not bold main message in `--error-format=short`

Fix #63835.

Before:

<img width="484" alt="Screenshot 2023-10-19 at 3 52 53 PM" src="https://github.com/rust-lang/rust/assets/1606434/9bd6cbd5-a4ce-4cc3-8c5f-60a8d3ad38da">

After:

<img width="492" alt="Screenshot 2023-10-19 at 3 52 32 PM" src="https://github.com/rust-lang/rust/assets/1606434/0cf2417a-08f2-4074-860c-a88a838a4209">
2023-10-20 10:52:24 +00:00
Esteban Küber
fd49590ee0 Do not bold main message in --error-format=short
Fix #63835.
2023-10-19 22:52:30 +00:00
Gurinder Singh
0091166b57 Fix duplicate labels emitted in render_multispan_macro_backtrace()
Using hash set instead of vec to weed out duplicates
2023-10-19 08:03:40 +05:30
Slanterns
ed512e91d0
Remove #![feature(result_option_inspect)] from the compiler 2023-10-18 07:35:57 +08:00
Matthias Krüger
1de910fc0d
Rollup merge of #115196 - chenyukang:yukang-fix-86094, r=estebank
Suggest adding `return` if the for semi which can coerce to the fn return type

Fixes #86094
r? `@estebank`
2023-10-16 06:26:20 +02:00
yukang
25d38c48c3 Suggest adding return if the type of unused semi return value can coerce to the fn return type 2023-10-15 22:57:03 +08:00
bors
a48396984a Auto merge of #116688 - compiler-errors:rustfmt-up, r=WaffleLapkin,Nilstrieb
Format all the let-chains in compiler crates

Since rust-lang/rustfmt#5910 has landed, soon we will have support for formatting let-chains (as soon as rustfmt syncs and beta gets bumped).

This PR applies the changes [from master rustfmt to rust-lang/rust eagerly](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/out.20formatting.20of.20prs/near/374997516), so that the next beta bump does not have to deal with a 200+ file diff and can remain concerned with other things like `cfg(bootstrap)` -- #113637 was a pain to land, for example, because of let-else.

I will also add this commit to the ignore list after it has landed.

The commands that were run -- I'm not great at bash-foo, but this applies rustfmt to every compiler crate, and then reverts the two crates that should probably be formatted out-of-tree.
```
~/rustfmt $ ls -1d ~/rust/compiler/* | xargs -I@ cargo run --bin rustfmt -- `@/src/lib.rs` --config-path ~/rust --edition=2021 # format all of the compiler crates
~/rust $ git checkout HEAD -- compiler/rustc_codegen_{gcc,cranelift} # revert changes to cg-gcc and cg-clif
```

cc `@rust-lang/rustfmt`
r? `@WaffleLapkin` or `@Nilstrieb` who said they may be able to review this purely mechanical PR :>

cc `@Mark-Simulacrum` and `@petrochenkov,` who had some thoughts on the order of operations with big formatting changes in https://github.com/rust-lang/rust/pull/95262#issue-1178993801. I think the situation has changed since then, given that let-chains support exists on master rustfmt now, and I'm fairly confident that this formatting PR should land even if *bootstrap* rustfmt doesn't yet format let-chains in order to lessen the burden of the next beta bump.
2023-10-15 13:23:55 +00:00
Jeremy Fitzhardinge
8f0845862c Use $message_type as the tag
`type` turned out to be controversial.
2023-10-13 15:50:01 -07:00
Michael Goulet
b2d2184ede Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
Urgau
001a65c4b0 check-cfg: only print the list of expected names once 2023-10-12 18:39:35 +02:00
Michael Howell
c6e6ecb1af rustdoc: remove rust logo from non-Rust crates 2023-10-08 20:17:53 -07:00
Alex Macleod
5453a9f34d Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
bors
01903944d8 Auto merge of #115690 - ShE3py:Z-treat-err-as-bug, r=petrochenkov
Allow `-Z treat-err-as-bug=0`

Makes `-Z treat-err-as-bug=0` behave as if the option wasn't present instead of asking the value to be &GreaterSlantEqual; 1. This enables a quick on/off of the option, as you only need to change one character instead of removing the whole `-Z`.

Also update some text, e.g.
```bash
$ rustc -Z help | grep treat-err-as-bug
    -Z                      treat-err-as-bug=val -- treat error number `val` that occurs as bug
```
where the value could be interpreted as an error code instead of an ordinal.
2023-09-22 13:01:30 +00:00
Lieselotte
3dd0419ea9
Allow -Z treat-err-as-bug=0
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2023-09-22 13:33:55 +02:00
Ralf Jung
e888d470e9 give FutureIncompatibilityReason variants more explicit names 2023-09-22 08:51:18 +02:00
Oli Scherer
9c762b58ba Prevent promotion of const fn calls in inline consts 2023-09-21 09:00:22 +00:00
Jeremy Fitzhardinge
00adbb2d5a Use serde_json::to_writer for JsonEmitter::emit
Avoids an unnecessary intermediate string.
2023-09-19 14:17:02 -07:00
Jeremy Fitzhardinge
62ad57b95a Make sure nested Diagnostics in FutureIncompat are also typed for consistency. 2023-09-19 14:17:02 -07:00
Jeremy Fitzhardinge
5c8170656b Add type field to 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: Report of future incompatibility
unused_extern: Unused crate warnings/errors

This matches the "internally tagged" representation for serde enums.
2023-09-19 14:17:02 -07:00
Pietro Albini
d695b95e3b
implement -Z ignore-directory-in-diagnostics-source-blocks 2023-09-15 16:22:50 +02:00
bors
26f4b72724 Auto merge of #115418 - Zoxc:freeze-source, r=oli-obk
Use `Freeze` for `SourceFile`

This uses the `Freeze` type in `SourceFile` to let accessing `external_src` and `lines` be lock-free.

Behavior of `add_external_src` is changed to set `ExternalSourceKind::AbsentErr` on a hash mismatch which matches the documentation. `ExternalSourceKind::Unneeded` was removed as it's unused.

Based on https://github.com/rust-lang/rust/pull/115401.
2023-09-08 17:20:23 +00:00
John Kåre Alsaker
c5996b80be Use Freeze for SourceFile.external_src 2023-09-07 13:04:23 +02:00
Michael Goulet
e10262ca0a Implement refinement lint for RPITIT 2023-09-07 00:49:09 +00:00
Urgau
eba5b44729 Add OnceHelp lint level (same as OnceNote, except for help) 2023-09-04 13:54:20 +02:00
bors
bf1e3f31f9 Auto merge of #115513 - Urgau:normalize-msg-after-translate, r=petrochenkov
Don't forget to normalize the translated message

This PR adds a missing call to `normalize_whitespace` after translating an label.

Fixes https://github.com/rust-lang/rust/issues/115498
2023-09-04 10:02:57 +00:00
Urgau
ec0975dd6b Don't forget to normalize the translated message 2023-09-03 17:10:42 +02:00
Christian Legnitto
6e6031e094
Add comment so pub items are not removed
As suggested in https://github.com/rust-lang/rust/pull/115393, add a comment so someone doesn't clean these up.
2023-09-01 13:22:03 -04:00
Christian Legnitto
da86cdf3a5
Make termcolor types public in rustc_errors
After https://github.com/rust-lang/rust/pull/114104, `rust-gpu` is unable to create a custom `Emitter` as the bounds have changed to include `WriteColor`.

I was able to work around this by adding `termcolor` as a direct dependency, but I believe this should be exposed as part of `rustc_errors` proper.

See https://github.com/rust-lang/rust/pull/102992 for why `rust-gpu` needs to create a custom emitter.
2023-08-30 16:06:49 -04:00
John Kåre Alsaker
5739349e96 Use conditional synchronization for Lock 2023-08-30 06:10:02 +02:00
allaboutevemirolive
a8827eea27 Add comment to the push_trailing function 2023-08-24 17:09:14 -04:00
Mark Rousskov
0a916062aa Bump cfg(bootstrap) 2023-08-23 20:05:14 -04:00
Kyle Lin
713e78cdd8 fix 2023-08-18 15:19:23 +08:00
Kyle Lin
f0b2cca185 lint links 2023-08-18 15:19:23 +08:00
bors
fe896efa97 Auto merge of #114104 - oli-obk:syn2, r=compiler-errors
Lots of tiny incremental simplifications of `EmitterWriter` internals

ignore the first commit, it's https://github.com/rust-lang/rust/pull/114088 squashed and rebased, but it's needed to use to use `derive_setters`, as they need a newer `syn` version.

Then this PR starts out with removing many arguments that are almost always defaulted to `None` or `false` and replace them with builder methods that can set these fields in the few cases that want to set them.

After that it's one commit after the other that removes or merges things until everything becomes some very simple trait objects
2023-08-04 18:46:19 +00:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Oli Scherer
375d8f1b25 Sanity check that we actually flush all buffers 2023-07-31 09:34:36 +00:00
Oli Scherer
d9deaf4b8a Get rid of the thin wrapper type that is Destination and just write to the Writer trait object directly 2023-07-31 09:34:36 +00:00
Oli Scherer
2131eee179 Turn a single-variant enum into a struct 2023-07-31 09:34:36 +00:00
Oli Scherer
10da30f540 Merge all Destination variants 2023-07-31 09:34:36 +00:00
Oli Scherer
826a8ef52e Remove a now-redundant single-variant enum 2023-07-31 09:34:36 +00:00
Oli Scherer
1e2167f5b5 Move WritableDst method onto Style directly 2023-07-31 09:34:36 +00:00
Oli Scherer
00074698a7 Merge buffered destination into raw destination 2023-07-31 09:34:36 +00:00
Oli Scherer
339890e186 Remove an enum variant that can be covered by another 2023-07-31 09:34:36 +00:00
Oli Scherer
51c22154f5 Remove a bool for color in favor of the WriteColor trait wrapping colored and uncolored printing 2023-07-31 09:34:36 +00:00
Oli Scherer
0e7ec9683d Use builder pattern instead of lots of arguments for EmitterWriter::new 2023-07-31 09:34:30 +00:00
Oli Scherer
29de70da1b Replace the many arguments of EmitterWriter::stderr with builder methods 2023-07-31 07:19:23 +00:00
Matthias Krüger
a964f948d5
Rollup merge of #114068 - matthiaskrgr:fmt_args_rustc_1, r=WaffleLapkin
inline format!() args up to and including rustc_middle (2)

r? `@WaffleLapkin`
2023-07-30 14:25:09 +02:00
Matthias Krüger
427f3d3266
Rollup merge of #114018 - Enselic:multi-annotation, r=b-naber
Make `--error-format human-annotate-rs` handle multiple files

Closes #64205 which is E-help-wanted
2023-07-30 14:25:09 +02:00
Matthias Krüger
23815467a2 inline format!() args up to and including rustc_middle 2023-07-30 13:18:33 +02:00
bors
2dc661037d Auto merge of #113099 - bvanjoi:fix-112713-2, r=petrochenkov
fix(resolve): update the ambiguity glob binding as warning recursively

Fixes #47525
Fixes #56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility.
Fixes #98467
Fixes #105235
Fixes #112713

This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint.

More details: https://github.com/rust-lang/rust/pull/112743

r? `@petrochenkov`
2023-07-29 06:04:41 +00:00
Matthias Krüger
02f1e2ada7
Rollup merge of #114128 - estebank:delayed-span-bug-dump, r=davidtwco
When flushing delayed span bugs, write to the ICE dump file even if it doesn't exist

Fix #113881.
2023-07-28 19:51:15 +02:00
bohan
cac0bd0bef fix(resolve): update the ambiguity glob binding as warning recursively 2023-07-29 00:19:50 +08:00
bors
0eb5efc7ae Auto merge of #113298 - tgross35:update-bless-envs, r=oli-obk
Unite bless environment variables under `RUST_BLESS`

Currently, Clippy and Miri both use an environment variable to indicate that output should be blessed, but they use different variable names. In order to improve consistency, this patch applies the following changes:

- Rename the variable `MIRI_BLESS` (as used in the Miri subtree) to `RUST_BLESS`
- Rename the variable `BLESS` (as used in the Clippy subtree) to `RUST_BLESS`
- Move emitting `RUST_BLESS` into `prepare_cargo_test` so it is always available (I need this for a WIP PR)

---

I prefer something like `RUST_BLESS` to `BLESS` just for a lower chance of conflict (not super common but other tools [do use `BLESS`](https://grep.app/search?q=%22BLESS%22&case=true&words=true&filter[lang][0]=Text&filter[lang][1]=Rust&filter[lang][2]=Python&filter[lang][3]=C%2B%2B&filter[lang][4]=Markdown&filter[lang][5]=C&filter[lang][6]=JSON)), but I can change it to whatever is preferred.

Original discussion: https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/BLESS.20env.20var.3A.20rename.20to.20CLIPPY_BLESS

r? `@oli-obk`
cc `@flip1995`
2023-07-27 17:45:11 +00:00
Esteban Küber
656213cc83 When flushing delayed span bugs, write to the ICE dump file even if it doesn't exist
Fix #113881.
2023-07-27 14:06:27 +00:00
bors
f239bb6bea Auto merge of #113281 - dayo05:master, r=davidtwco
Implement diagnostic translation for rustc-errors

This is my first PR to rustc yeah~

I'm going to implement diagnostic translation on rustc-errors crate.

This PR is WIP, the reason of opening this as draft, I want to show my code to prevent the issue caused by misunderstanding and also I have few questions.

Some error messages are processed by `pluralize!` macro which determines to use plural word or not. From now, I make two kinds of keys and combine with enum but I'm not sure is this best method to do it.

Is there any prefered method to do this? => This resolved on conversation on PR.

I'll remain to perform force-push until my first implementation looks good to me
2023-07-27 09:20:40 +00:00
Trevor Gross
9439e02fb2 Unite bless environment variables under RUSTC_BLESS
Currently, Clippy, Miri, Rustfmt, and rustc all use an environment variable to
indicate that output should be blessed, but they use different variable names.
In order to improve consistency, this patch applies the following changes:

- Emit `RUSTC_BLESS` within `prepare_cargo_test` so it is always
  available
- Change usage of `MIRI_BLESS` in the Miri subtree to use `RUSTC_BLESS`
- Change usage of `BLESS` in the Clippy subtree to `RUSTC_BLESS`
- Change usage of `BLESS` in the Rustfmt subtree to `RUSTC_BLESS`
- Adjust the blessable test in `rustc_errors` to use this same
  convention
- Update documentation where applicable

Any tools that uses `RUSTC_BLESS` should check that it is set to any value
other than `"0"`.
2023-07-26 16:54:02 -04:00
bors
52bdc37727 Auto merge of #114054 - oli-obk:cleanups, r=estebank
Split some functions with many arguments into builder pattern functions

r? `@estebank`

This doesn't resolve all of the ones in rustc, mostly because I need to do other cleanups in order to be able to use some builder derives from crates.io

Works around https://github.com/rust-lang/rust/issues/90672 by making `x test rustfmt --bless` format itself instead of testing that it is formatted
2023-07-26 11:17:35 +00:00
Matthias Krüger
8ecaf2ae57
Rollup merge of #114014 - davidtwco:issue-114010-env-rawstr, r=cjgillot
builtin_macros: expect raw strings too

Fixes #114010.

`expr_to_string` allows raw strings through so this code should be expected to handle those.
2023-07-25 19:21:37 +02:00
Oli Scherer
2b444672e1 Use a builder instead of boolean/option arguments 2023-07-25 13:51:15 +00:00
Oli Scherer
cf9f53c837 Remove a redundant field 2023-07-25 13:33:09 +00:00
Oli Scherer
b7f8eba9fd Inline a function that is only used once 2023-07-25 13:30:04 +00:00
Oli Scherer
8d60f7573d Remove some arguments that are always the same 2023-07-25 13:25:53 +00:00
David Wood
75df62d4a2
builtin_macros: raw str in diagnostic output
If a raw string was used in the `env!` invocation, then it should also
be shown in the diagnostic messages as a raw string.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-25 11:12:52 +01:00
Martin Nordholts
504acf8760 Make --error-format human-annotate-rs handle multiple files 2023-07-24 16:29:58 +02:00
Yuri Astrakhan
e36b901933 Optimize format usage
Per #112156, using `&` in `format!` may cause a small perf delay, so I tried to clean up one module at a time format usage. This PR includes a few removals of the ref in format (they do compile locally without the ref), as well as a few format inlining for consistency.
2023-07-24 00:08:09 -04:00
Oli Scherer
d97ec97b94 Don't translate compiler-internal bug messages 2023-07-20 09:51:47 +00:00
Matthias Krüger
770c8d0667
Rollup merge of #113871 - clubby789:derive-sugg-span, r=compiler-errors
Use the correct span for displaying the line following a derive sugge…

`span` here is the main span of the diagnostic. In the linked issue's case, this belongs to `main.rs`. However, the line numbers (and line we are trying to display) are in `name.rs`, so using `span_to_lines` gives us the wrong `FileLines`.

Use `parts[0].span` (the span of the suggestion) here like the rest of the code does to get the right file.

Not sure if this needs a dedicated test because this fixes an existing error in the UI suite

Fixes #113844
2023-07-20 07:08:43 +02:00
clubby789
20a3b9a215 Use the correct span for displaying the line following a derive suggestion 2023-07-19 23:48:43 +00:00
Esteban Küber
8eb5843a59 On nightly, dump ICE backtraces to disk
Implement rust-lang/compiler-team#578.

When an ICE is encountered on nightly releases, the new rustc panic
handler will also write the contents of the backtrace to disk. If any
`delay_span_bug`s are encountered, their backtrace is also added to the
file. The platform and rustc version will also be collected.
2023-07-19 14:10:07 +00:00
Dayo
05c856a760 Simplify implement diagnostic of errors_indicate_anonymous_lifetime 2023-07-17 15:00:39 +09:00
Mark Rousskov
cc907f80b9 Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
Dayo
d6c93b33d0 Implement diagnostic translation for expected lifetime parameter message 2023-07-07 15:56:01 +09:00
Trevor Gross
6a1c10bd85 Add a simple markdown parser for formatting rustc --explain
Currently, the output of `rustc --explain foo` displays the raw markdown in a
pager. This is acceptable, but using actual formatting makes it easier to
understand.

This patch consists of three major components:

1.  A markdown parser. This is an extremely simple non-backtracking recursive
    implementation that requires normalization of the final token stream
2.  A utility to write the token stream to an output buffer
3.  Configuration within rustc_driver_impl to invoke this combination for
    `--explain`. Like the current implementation, it first attempts to print to
    a pager with a fallback colorized terminal, and standard print as a last
    resort.

    If color is disabled, or if the output does not support it, or if printing
    with color fails, it will write the raw markdown (which matches current
    behavior).

    Pagers known to support color are: `less` (with `-r`), `bat` (aka `catbat`),
    and `delta`.

The markdown parser does not support the entire markdown specification, but
should support the following with reasonable accuracy:

-   Headings, including formatting
-   Comments
-   Code, inline and fenced block (no indented block)
-   Strong, emphasis, and strikethrough formatted text
-   Links, anchor, inline, and reference-style
-   Horizontal rules
-   Unordered and ordered list items, including formatting

This parser and writer should be reusable by other systems if ever needed.
2023-07-03 16:04:18 -04:00
The 8472
114d5f221c s/drain_filter/extract_if/ for Vec, Btree{Map,Set} and LinkedList 2023-06-14 09:28:54 +02:00
Nilstrieb
70980929b4 Respect RUST_BACKTRACE for delayed bugs
Sometimes, especially with MIR validation, the backtraces from delayed
bugs are noise and make it harder to look at them. Respect the
environment variable and don't print it when the user doesn't want it.
2023-06-06 19:24:33 +00:00
bors
8ebf04225d Auto merge of #112198 - compiler-errors:rollup-o2xe4of, r=compiler-errors
Rollup of 7 pull requests

Successful merges:

 - #111670 (Require that const param tys implement `ConstParamTy`)
 - #111914 (CFI: Fix cfi with async: transform_ty: unexpected GeneratorWitness(Bi…)
 - #112030 (Migrate `item_trait_alias` to Askama)
 - #112150 (Support 128-bit atomics on all x86_64 Apple targets)
 - #112174 (Fix broken link)
 - #112190 (Improve comments on `TyCtxt` and `GlobalCtxt`.)
 - #112193 (Check tuple elements are `Sized` in `offset_of`)

Failed merges:

 - #112071 (Group rfcs tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-06-02 07:57:21 +00:00
Michael Goulet
97bacbab57 Remove adt_const_params usage from compiler 2023-06-01 18:21:42 +00:00
Deadbeef
4f83717cf7 Use translatable diagnostics in rustc_const_eval 2023-06-01 14:45:18 +00:00
Nicholas Nethercote
781111ef35 Use Cow in {D,Subd}iagnosticMessage.
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment:
```
// FIXME(davidtwco): can a `Cow<'static, str>` be used here?
```
This commit answers that question in the affirmative. It's not the most
compelling change ever, but it might be worth merging.

This requires changing the `impl<'a> From<&'a str>` impls to `impl
From<&'static str>`, which involves a bunch of knock-on changes that
require/result in call sites being a little more precise about exactly
what kind of string they use to create errors, and not just `&str`. This
will result in fewer unnecessary allocations, though this will not have
any notable perf effects given that these are error paths.

Note that I was lazy within Clippy, using `to_string` in a few places to
preserve the existing string imprecision. I could have used `impl
Into<{D,Subd}iagnosticMessage>` in various places as is done in the
compiler, but that would have required changes to *many* call sites
(mostly changing `&format("...")` to `format!("...")`) which didn't seem
worthwhile.
2023-05-29 09:23:43 +10:00
bors
c86212f9bc Auto merge of #111858 - clubby789:fluent-alphabetical, r=jyn514,compiler-errors
Ensure Fluent messages are in alphabetical order

Fixes #111847

This adds a tidy check to ensure Fluent messages are in alphabetical order, as well as sorting all existing messages. I think the error could be worded better, would appreciate suggestions.

<details>
<summary>Script used to sort files</summary>

```py
import sys
import re

fn = sys.argv[1]
with open(fn, 'r') as f:
    data = f.read().split("\n")

chunks = []
cur = ""
for line in data:
    if re.match(r"^([a-zA-Z0-9_]+)\s*=\s*", line):
        chunks.append(cur)
        cur = ""
    cur += line + "\n"
chunks.append(cur)
chunks.sort()

with open(fn, 'w') as f:
    f.write(''.join(chunks).strip("\n\n") + "\n")
```
</details>
2023-05-26 03:31:04 +00:00
clubby789
f97fddab91 Ensure Fluent messages are in alphabetical order 2023-05-25 23:49:35 +00:00
Camille GILLOT
0919ec3ecc Remove ExpnKind::Inlined. 2023-05-25 16:43:14 +00:00
Maybe Waffle
307799a711 Use is_some_and/is_ok_and in less obvious spots 2023-05-24 14:33:43 +00:00
Maybe Waffle
fb0f74a8c9 Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
Michael Goulet
0307db4a59 Check opaques for mismatch during writeback 2023-05-22 23:33:34 +00:00
Matthias Krüger
cb5dd1d598
Rollup merge of #111745 - Badel2:emitter-add-overflow, r=compiler-errors
Fix overflow in error emitter

Fix #109854
Close #94171 (was already fixed before but missing test)

This bug happens when a multipart suggestion spans more than one line.

The fix is to update the `acc` variable, which didn't handle the case when the text to remove spans multiple lines but the text to add spans only one line.

Also, use `usize::try_from` instead of  `as usize` to detect overflows earlier in the future, and point to the source of the overflow (the original issue points to a different place where this value is used, not where the overflow had happened).

And finally add an `if start != end` check to avoid doing any extra work in case of empty ranges.

Long explanation:

Given this test case:

```rust
fn generate_setter() {
    String::with_capacity(
    //~^ ERROR this function takes 1 argument but 3 arguments were supplied
    generate_setter,
    r#"
pub(crate) struct Person<T: Clone> {}
"#,
     r#""#,
    );
}
```

The compiler will try to convert that code into the following:

```rust
fn generate_setter() {
    String::with_capacity(
    //~^ ERROR this function takes 1 argument but 3 arguments were supplied
    /* usize */,
    );
}
```

So it creates a suggestion with 3 separate parts:

```
// Replace "generate_setter" with "/* usize */"
SubstitutionPart { span: fuzz_input.rs:4:5: 4:20 (#0), snippet: "/* usize */" }
// Remove second arg (multiline string)
SubstitutionPart { span: fuzz_input.rs:4:20: 7:3 (#0), snippet: "" }
// Remove third arg (r#""#)
SubstitutionPart { span: fuzz_input.rs:7:3: 8:11 (#0), snippet: "" }
```

Each of this parts gets a separate `SubstitutionHighlight` (this marks the relevant text green in a terminal, the values are 0-indexed so `start: 4` means column 5):

```
SubstitutionHighlight { start: 4, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
SubstitutionHighlight { start: 18446744073709551614, end: 18446744073709551614 }
```

The 2nd and 3rd suggestion are empty (start = end) because they only remove text, so there are no additions to highlight. But the 3rd span has overflowed because the compiler assumes that the 3rd suggestion is on the same line as the first suggestion. The 2nd span starts at column 20 and the highlight starts at column 16 (15+1), so that suggestion is good. But since the 3rd span starts at column 3, the result is `3 - 4`, or column -1, which turns into -2 with 0-indexed, and that's equivalent to `18446744073709551614 as isize`.

With this fix, the resulting `SubstitutionHighlight` are:

```
SubstitutionHighlight { start: 4, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
SubstitutionHighlight { start: 15, end: 15 }
```

As expected. I guess ideally we shouldn't emit empty highlights when removing text, but I am too scared to change that.
2023-05-21 16:02:59 +02:00
Badel2
cbb41008fd Fix overflow in error emitter 2023-05-19 20:58:06 +02:00
jyn
e6a7fdedd7 Give a more useful location for where a span_bug was delayed
Before:
```
   = note: delayed at    0: <rustc_errors::HandlerInner>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: <rustc_errors::Handler>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
...
```

After:
```
   = note: delayed at compiler/rustc_parse/src/parser/diagnostics.rs:2158:28
              0: <rustc_errors::HandlerInner>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1335:29
              1: <rustc_errors::Handler>::emit_diagnostic
                        at ./compiler/rustc_errors/src/lib.rs:1124:9
```

This both makes the relevant frame easier to find without having to dig
through diagnostic internals, and avoids the weird-looking formatting
for the first frame.
2023-05-17 23:15:22 -05:00
mu001999
db64512422 Emits E0599 when meeting MyTrait::missing_method 2023-05-17 16:59:39 +08:00
bors
dd8ec9c88d Auto merge of #107586 - SparrowLii:parallel-query, r=cjgillot
Introduce `DynSend` and `DynSync` auto trait for parallel compiler

part of parallel-rustc #101566

This PR introduces `DynSend / DynSync` trait and `FromDyn / IntoDyn` structure in rustc_data_structure::marker. `FromDyn` can dynamically check data structures for thread safety when switching to parallel environments (such as calling `par_for_each_in`). This happens only when `-Z threads > 1` so it doesn't affect single-threaded mode's compile efficiency.

r? `@cjgillot`
2023-05-13 13:47:53 +00:00
klensy
3c03cce341 bump windows crate 0.46 -> 0.48 in workspace 2023-05-09 18:20:13 +03:00
Michael Goulet
68594142b1
Rollup merge of #111004 - clubby789:migrate-mir-transform, r=oli-obk
Migrate `mir_transform` to translatable diagnostics

cc #100717
2023-05-08 09:30:22 -07:00
SparrowLii
089a38880b correct literals for dyn thread safe 2023-05-06 09:34:53 +08:00
SparrowLii
b9746ce039 introduce DynSend and DynSync auto trait 2023-05-06 09:34:18 +08:00
Michael Goulet
6077fdd219 Mark ErrorGuaranteed constructor as deprecated so people don't use it 2023-05-05 17:58:46 +00:00
Nicholas Nethercote
6b62f37402 Restrict From<S> for {D,Subd}iagnosticMessage.
Currently a `{D,Subd}iagnosticMessage` can be created from any type that
impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static,
str>`, which are reasonable. It also includes `&String`, which is pretty
weird, and results in many places making unnecessary allocations for
patterns like this:
```
self.fatal(&format!(...))
```
This creates a string with `format!`, takes a reference, passes the
reference to `fatal`, which does an `into()`, which clones the
reference, doing a second allocation. Two allocations for a single
string, bleh.

This commit changes the `From` impls so that you can only create a
`{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static,
str>`. This requires changing all the places that currently create one
from a `&String`. Most of these are of the `&format!(...)` form
described above; each one removes an unnecessary static `&`, plus an
allocation when executed. There are also a few places where the existing
use of `&String` was more reasonable; these now just use `clone()` at
the call site.

As well as making the code nicer and more efficient, this is a step
towards possibly using `Cow<'static, str>` in
`{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing
the `From<&'a str>` impls to `From<&'static str>`, which is doable, but
I'm not yet sure if it's worthwhile.
2023-05-03 08:44:39 +10:00
clubby789
d5bc581f5d Migrate mir_transform to translatable diagnostics 2023-05-02 16:24:18 +01:00
Matthias Krüger
637d9ddc35
Rollup merge of #110578 - bvanjoi:fix-issue-110547, r=jackh726
fix(error): normalize whitespace during msg_to_buffer

close https://github.com/rust-lang/rust/issues/110547
2023-04-21 06:44:30 +02:00
bohan
a2f275da51 fix(error): normalize whitespace during msg_to_buffer 2023-04-21 08:40:00 +08:00
bors
d7f9e81650 Auto merge of #110407 - Nilstrieb:fluent-macro, r=davidtwco
Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`

Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-04-19 08:26:47 +00:00
bors
b3f1379509 Auto merge of #110083 - saethlin:encode-hashes-as-bytes, r=cjgillot
Encode hashes as bytes, not varint

In a few places, we store hashes as `u64` or `u128` and then apply `derive(Decodable, Encodable)` to the enclosing struct/enum. It is more efficient to encode hashes directly than try to apply some varint encoding. This PR adds two new types `Hash64` and `Hash128` which are produced by `StableHasher` and replace every use of storing a `u64` or `u128` that represents a hash.

Distribution of the byte lengths of leb128 encodings, from `x build --stage 2` with `incremental = true`

Before:
```
(  1) 373418203 (53.7%, 53.7%): 1
(  2) 196240113 (28.2%, 81.9%): 3
(  3) 108157958 (15.6%, 97.5%): 2
(  4)  17213120 ( 2.5%, 99.9%): 4
(  5)    223614 ( 0.0%,100.0%): 9
(  6)    216262 ( 0.0%,100.0%): 10
(  7)     15447 ( 0.0%,100.0%): 5
(  8)      3633 ( 0.0%,100.0%): 19
(  9)      3030 ( 0.0%,100.0%): 8
( 10)      1167 ( 0.0%,100.0%): 18
( 11)      1032 ( 0.0%,100.0%): 7
( 12)      1003 ( 0.0%,100.0%): 6
( 13)        10 ( 0.0%,100.0%): 16
( 14)        10 ( 0.0%,100.0%): 17
( 15)         5 ( 0.0%,100.0%): 12
( 16)         4 ( 0.0%,100.0%): 14
```

After:
```
(  1) 372939136 (53.7%, 53.7%): 1
(  2) 196240140 (28.3%, 82.0%): 3
(  3) 108014969 (15.6%, 97.5%): 2
(  4)  17192375 ( 2.5%,100.0%): 4
(  5)       435 ( 0.0%,100.0%): 5
(  6)        83 ( 0.0%,100.0%): 18
(  7)        79 ( 0.0%,100.0%): 10
(  8)        50 ( 0.0%,100.0%): 9
(  9)         6 ( 0.0%,100.0%): 19
```

The remaining 9 or 10 and 18 or 19 are `u64` and `u128` respectively that have the high bits set. As far as I can tell these are coming primarily from `SwitchTargets`.
2023-04-18 22:27:15 +00:00
Nilstrieb
b5d3d970fa Add rustc_fluent_macro to decouple fluent from rustc_macros
Fluent, with all the icu4x it brings in, takes quite some time to
compile. `fluent_messages!` is only needed in further downstream rustc
crates, but is blocking more upstream crates like `rustc_index`. By
splitting it out, we allow `rustc_macros` to be compiled earlier, which
speeds up `x check compiler` by about 5 seconds (and even more after the
needless dependency on `serde_json` is removed from
`rustc_data_structures`).
2023-04-18 18:56:22 +00:00
Ben Kimock
0445fbdd83 Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00
Josh Soref
e09d0d2a29 Spelling - compiler
* account
* achieved
* advising
* always
* ambiguous
* analysis
* annotations
* appropriate
* build
* candidates
* cascading
* category
* character
* clarification
* compound
* conceptually
* constituent
* consts
* convenience
* corresponds
* debruijn
* debug
* debugable
* debuggable
* deterministic
* discriminant
* display
* documentation
* doesn't
* ellipsis
* erroneous
* evaluability
* evaluate
* evaluation
* explicitly
* fallible
* fulfill
* getting
* has
* highlighting
* illustrative
* imported
* incompatible
* infringing
* initialized
* into
* intrinsic
* introduced
* javascript
* liveness
* metadata
* monomorphization
* nonexistent
* nontrivial
* obligation
* obligations
* offset
* opaque
* opportunities
* opt-in
* outlive
* overlapping
* paragraph
* parentheses
* poisson
* precisely
* predecessors
* predicates
* preexisting
* propagated
* really
* reentrant
* referent
* responsibility
* rustonomicon
* shortcircuit
* simplifiable
* simplifications
* specify
* stabilized
* structurally
* suggestibility
* translatable
* transmuting
* two
* unclosed
* uninhabited
* visibility
* volatile
* workaround

Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-04-17 16:09:18 -04:00
Matthias Krüger
6161fb8c65
Rollup merge of #110072 - joshtriplett:stabilize-is-terminal, r=Mark-Simulacrum
Stabilize IsTerminal

FCP completed in https://github.com/rust-lang/rust/issues/98070 .

closes: https://github.com/rust-lang/rust/issues/98070
2023-04-13 11:21:00 +02:00
bors
d37e2f74af Auto merge of #109786 - estebank:tweak-add-line-sugg, r=compiler-errors
Tweak output for 'add line' suggestion

Closes #108174
2023-04-13 07:02:53 +00:00
Esteban Küber
9fadcc143a Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
Esteban Küber
5b40aa5eb4 Tweak output for 'add line' suggestion 2023-04-12 22:50:10 +00:00
Matthias Krüger
57393be6fb
Rollup merge of #110135 - compiler-errors:revert-108031, r=davidtwco
Revert "Don't recover lifetimes/labels containing emojis as character literals"

Reverts PR #108031 per https://github.com/rust-lang/rust/pull/109754#issuecomment-1490452045

Fixes (doesnt close until beta backported) #109746

This reverts commit e3f9db5fc3.
This reverts commit 98b82aedba.
This reverts commit 380fa26413.
2023-04-12 22:04:35 +02:00