Commit Graph

31545 Commits

Author SHA1 Message Date
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
c733a0216d Remove a fourth DiagnosticBuilder::emit_without_consuming call.
The old code was very hard to understand, involving an
`emit_without_consuming` call *and* a `delay_as_bug_without_consuming`
call.

With slight changes both calls can be avoided. Not creating the error
until later is crucial, as is the early return in the `if recovered`
block.

It took me some time to come up with this reworking -- it went through
intermediate states much further from the original code than this final
version -- and it's isn't obvious at a glance that it is equivalent. But
I think it is, and the unchanged test behaviour is good supporting
evidence.

The commit also changes `check_trailing_angle_brackets` to return
`Option<ErrorGuaranteed>`. This provides a stricter proof that it
emitted an error message than asserting `dcx.has_errors().is_some()`,
which would succeed if any error had previously been emitted anywhere.
2024-01-08 16:04:50 +11:00
Nicholas Nethercote
1b6c8e7533 Remove a third DiagnosticBuilder::emit_without_consuming call.
It's not clear why this was here, because the created error is returned
as a normal error anyway.

Nor is it clear why removing the call works. The change doesn't affect
any tests; `tests/ui/parser/issues/issue-102182-impl-trait-recover.rs`
looks like the only test that could have been affected.
2024-01-08 16:03:41 +11:00
Nicholas Nethercote
3ce34f42e1 Remove a second DiagnosticBuilder::emit_without_consuming call.
Instead of taking `seq` as a mutable reference,
`maybe_recover_struct_lit_bad_delims` now consumes `seq` on the recovery
path, and returns `seq` unchanged on the non-recovery path. The commit
also combines an `if` and a `match` to merge two identical paths.

Also change `recover_seq_parse_error` so it receives a `PErr` instead of
a `PResult`, because all the call sites now handle the `Ok`/`Err`
distinction themselves.
2024-01-08 16:01:22 +11:00
Nicholas Nethercote
1881055000 Remove a DiagnosticBuilder::emit_without_consuming call.
In this parsing recovery function, we only need to emit the previously
obtained error message and mark `expr` as erroneous in the case where we
actually recover.
2024-01-08 16:01:22 +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
bd4e623485 Use chaining for DiagnosticBuilder construction and emit.
To avoid the use of a mutable local variable, and because it reads more
nicely.
2024-01-08 15:45:29 +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
bors
75c68cfd2b Auto merge of #119675 - cjgillot:set-no-discriminant, r=tmiasko
Skip threading over no-op SetDiscriminant.

Fixes https://github.com/rust-lang/rust/issues/119674
2024-01-07 15:34:05 +00:00
bors
d8b44d2802 Auto merge of #119667 - Nadrieril:remove-wildcard-row, r=compiler-errors
Exhaustiveness: remove `Matrix.wildcard_row`

To compute exhaustiveness, we check whether an extra row with a wildcard added at the end of the match expression would be reachable. We used to store an actual such row of patterns in the `Matrix`, but it's a bit redundant since we know it only contains wildcards. It was kept because we used it to get the type of each column (and relevancy). With this PR, we keep track of the types (and relevancy) directly.

This is part of me splitting up https://github.com/rust-lang/rust/pull/119581 for ease of review.

r? `@compiler-errors`
2024-01-07 13:36:54 +00:00
Michael Goulet
854d1131ff
Rollup merge of #119666 - compiler-errors:construct-coroutine-info-immediately, r=cjgillot
Populate `yield` and `resume` types in MIR body while body is being initialized

I found it weird that we went back and populated these types *after* the body was constructed. Let's just do it all at once.
2024-01-06 21:51:46 -05:00
Camille GILLOT
41eb9a49af Skip threading over no-op SetDiscriminant. 2024-01-07 00:28:20 +00:00
Martin Nordholts
6d8fb57d1a rustc_mir_transform: Enforce rustc::potential_query_instability lint
Stop allowing `rustc::potential_query_instability` on all of
rustc_mir_transform and instead allow it on a case-by-case basis if it
is safe to do so. In this particular crate, all instances were safe to
allow.
2024-01-06 19:09:04 +01:00
Michael Goulet
5e2b66fc9d Don't populate yield and resume types after the fact 2024-01-06 18:03:01 +00:00
Nadrieril
50b197c6ee Reuse ctor_sub_tys when we have one around 2024-01-06 18:03:13 +01:00
Nadrieril
d40f1b1172 Remove Matrix.wildcard_row
It was only used to track types and relevancy, so may as well store that
directly.
2024-01-06 17:56:54 +01:00
bors
b6a8c762ee Auto merge of #119662 - matthiaskrgr:rollup-ehofh5n, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #118194 (rustdoc: search for tuples and unit by type with `()`)
 - #118781 (merge core_panic feature into panic_internals)
 - #119486 (pass allow-{dirty,staged} to clippy)
 - #119591 (rustc_mir_transform: Make DestinationPropagation stable for queries)
 - #119595 (Fixed ambiguity in hint.rs)
 - #119624 (rustc_span: More consistent span combination operations)
 - #119653 (compiler: update Fuchsia sanitizer support.)
 - #119655 (Remove ignore-stage1 that was added when changing error count msg)
 - #119661 (Strip lld-wrapper binaries)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-06 15:50:44 +00:00
Matthias Krüger
54df1b3f8b
Rollup merge of #119653 - devnexen:update_fuchsia_compiler_rt_support, r=petrochenkov
compiler: update Fuchsia sanitizer support.
2024-01-06 16:07:49 +01:00
Matthias Krüger
1d6ab69ab1
Rollup merge of #119624 - petrochenkov:dialoc4, r=compiler-errors
rustc_span: More consistent span combination operations

Also add more tests for using `tt` in addition to `ident`, and some other minor tweaks, see individual commits.

This is a part of https://github.com/rust-lang/rust/pull/119412 that doesn't yet add side tables for metavariable spans.
2024-01-06 16:07:48 +01:00
Matthias Krüger
909f2b63a3
Rollup merge of #119591 - Enselic:DestinationPropagation-stable, r=cjgillot
rustc_mir_transform: Make DestinationPropagation stable for queries

By using `FxIndexMap` instead of `FxHashMap`, so that the order of visiting of locals is deterministic.

We also need to bless
`copy_propagation_arg.foo.DestinationPropagation.panic*.diff`. Do not review the diff of the diff. Instead look at the diff files before and after this commit. Both before and after this commit, 3 statements are replaced with nop. It's just that due to change in ordering, different statements are replaced. But the net result is the same. In other words, compare this diff (before fix):
* 090d5eac72/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

With this diff (after fix):
* f603babd63/tests/mir-opt/dest-prop/copy_propagation_arg.foo.DestinationPropagation.panic-unwind.diff

and you can see that both before and after the fix, we replace 3 statements with `nop`s.

I find it _slightly_ surprising that the test this PR affects did not previously fail spuriously due to the indeterminism of `FxHashMap`, but I guess in can be explained with the predictability of small `FxHashMap`s with `usize` (`Local`) keys, or something along those lines.

This should fix [this](https://github.com/rust-lang/rust/pull/119252#discussion_r1436101791) comment, but I wanted to make a separate PR for this fix for a simpler development and review process.

Part of https://github.com/rust-lang/rust/issues/84447 which is E-help-wanted.

r? `@cjgillot` who is reviewer for the highly related PR https://github.com/rust-lang/rust/pull/119252.
2024-01-06 16:07:47 +01:00
bors
9212108a9b Auto merge of #119531 - petrochenkov:cmpctxt, r=cjgillot
rustc_span: Optimize syntax context comparisons

Including comparisons with root context.

- `eq_ctxt` doesn't require retrieving full `SpanData`, or taking the span interner lock twice.
- Checking `SyntaxContext` for "rootness" is cheaper than extracting a full outer `ExpnData` for it and checking *it* for rootness.

The internal lint for `eq_ctxt` is also tweaked to detect `a.ctxt() != b.ctxt()` in addition to `a.ctxt() == b.ctxt()`.
2024-01-06 13:51:01 +00:00
bors
efb3f11087 Auto merge of #119499 - cjgillot:dtm-opt, r=nnethercote
Two small bitset optimisations
2024-01-06 11:54:15 +00:00
David Carlier
d70f0e36f0 compiler: update Fuchsia sanitizer support. 2024-01-06 10:06:15 +00:00
bors
e21f4cd98f Auto merge of #119478 - bjorn3:no_serialize_specialization, r=wesleywiser
Avoid specialization in the metadata serialization code

With the exception of a perf-only specialization for byte slices and byte vectors.

This uses the same trick of introducing a new trait and having the Encodable and Decodable derives add a bound to it as used for TyEncoder/TyDecoder. The new code is clearer about which encoder/decoder uses which impl and it reduces the dependency of rustc on specialization, making it easier to remove support for specialization entirely or turn it into a construct that is only allowed for perf optimizations if we decide to do this.
2024-01-06 09:56:00 +00:00
bors
aa7e9f21e9 Auto merge of #119648 - compiler-errors:rollup-42inxd8, r=compiler-errors
Rollup of 9 pull requests

Successful merges:

 - #119208 (coverage: Hoist some complex code out of the main span refinement loop)
 - #119216 (Use diagnostic namespace in stdlib)
 - #119414 (bootstrap: Move -Clto= setting from Rustc::run to rustc_cargo)
 - #119420 (Handle ForeignItem as TAIT scope.)
 - #119468 (rustdoc-search: tighter encoding for f index)
 - #119628 (remove duplicate test)
 - #119638 (fix cyle error when suggesting to use associated function instead of constructor)
 - #119640 (library: Fix warnings in rtstartup)
 - #119642 (library: Fix a symlink test failing on Windows)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-06 06:00:27 +00:00
Michael Goulet
61c776ae0a
Rollup merge of #119638 - lukas-code:suggest-constructor-cycle-error, r=cjgillot
fix cyle error when suggesting to use associated function instead of constructor

Fixes https://github.com/rust-lang/rust/issues/119625.

The first commit fixes the infinite recursion and makes the cycle error actually show up. We do this by making the `Display` for `ty::Instance` impl  respect `with_no_queries` so that it can be used in query descriptions.

The second commit fixes the cycle error `resolver_for_lowering` -> `normalize` -> `resolve_instance` (for evaluating const) -> `lang_items` (for `drop_in_place`) -> `resolver_for_lowering` (for collecting lang items). We do this by simply skipping the suggestion when encountering an unnormalized type.
2024-01-05 23:41:43 -05:00
Michael Goulet
9585ebc269
Rollup merge of #119420 - cjgillot:issue-119295, r=compiler-errors
Handle ForeignItem as TAIT scope.

Fixes #119295
2024-01-05 23:41:42 -05:00
Michael Goulet
d90c702566
Rollup merge of #119216 - weiznich:use_diagnostic_namespace_in_stdlib, r=compiler-errors
Use diagnostic namespace in stdlib

This required a minor fix to have the diagnostics shown in third party crates when the `diagnostic_namespace` feature is not enabled. See 5d63f5d8d1 for details. I've opted for having a single PR for both changes as it's really not that much code. If it is required it should be easy to split up the change into several PR's.

r? `@compiler-errors`
2024-01-05 23:41:41 -05:00
Michael Goulet
bacddd3e5d
Rollup merge of #119208 - Zalathar:hoist, r=WaffleLapkin,Swatinem
coverage: Hoist some complex code out of the main span refinement loop

The span refinement loop in `spans.rs` takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports.

It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways.

This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are *almost* identical, with all known differences being unimportant.

This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.
2024-01-05 23:41:41 -05:00
bors
d62f05b842 Auto merge of #119459 - cjgillot:inline-mir-utils, r=compiler-errors
Inline a few utility functions around MIR

Most of them are small enough to benefit from inlining.
2024-01-06 04:01:09 +00:00
bors
5bcd86d89b Auto merge of #119329 - Nadrieril:reveal-opaques-early, r=compiler-errors
Exhaustiveness: Statically enforce revealing of opaques

In https://github.com/rust-lang/rust/pull/116821 it was decided that exhaustiveness should operate on the hidden type of an opaque type when relevant. This PR makes sure we consistently reveal opaques within exhaustiveness. This makes it possible to remove `reveal_opaque_ty` from the `TypeCx` trait which was an unfortunate implementation detail.

r? `@compiler-errors`
2024-01-06 02:00:24 +00:00
Vadim Petrochenkov
90d11d6448 rustc_span: Optimize syntax context comparisons
Including comparisons with root context
2024-01-06 01:25:20 +03:00
Camille GILLOT
6dfdeab65a Do not run check on foreign items. 2024-01-05 21:49:37 +00:00
Camille GILLOT
7366bdaea2 Handle ForeignItem as TAIT scope. 2024-01-05 21:49:37 +00:00
bors
595bc6f003 Auto merge of #119634 - matthiaskrgr:rollup-v2xt7et, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #119151 (Hide foreign `#[doc(hidden)]` paths in import suggestions)
 - #119350 (Imply outlives-bounds on lazy type aliases)
 - #119354 (Make `negative_bounds` internal & fix some of its issues)
 - #119506 (Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`)
 - #119554 (Fix scoping for let chains in match guards)
 - #119563 (Check yield terminator's resume type in borrowck)
 - #119589 (cstore: Remove unnecessary locking from `CrateMetadata`)
 - #119622 (never patterns: Document behavior of never patterns with macros-by-example)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-01-05 21:42:26 +00:00
Lukas Markeffsky
339fa311ad fix cycle error for "use constructor" suggestion 2024-01-05 21:56:32 +01:00
Lukas Markeffsky
274674819c fix OOM when ty::Instance is used in query description 2024-01-05 21:55:29 +01:00
Martin Nordholts
95eb5bcb67 rustc_mir_transform: Make DestinationPropagation stable for queries
By using FxIndexMap instead of FxHashMap, so that the order of visiting
of locals is deterministic.

We also need to bless
copy_propagation_arg.foo.DestinationPropagation.panic*.diff. Do not
review the diff of the diff. Instead look at the diff file before and
after this commit. Both before and after this commit, 3 statements are
replaced with nop. It's just that due to change in ordering, different
statements are replaced. But the net result is the same.
2024-01-05 20:55:32 +01:00
Matthias Krüger
60a2b43708
Rollup merge of #119589 - petrochenkov:cdatalock, r=Mark-Simulacrum
cstore: Remove unnecessary locking from `CrateMetadata`

Locks and atomics in `CrateMetadata` fields were necessary before https://github.com/rust-lang/rust/pull/107765 when `CStore` was cloneable, but now they are not necessary and can be removed after restructuring the code a bit to please borrow checker.

All remaining locked fields in `CrateMetadata` are lazily populated caches.
2024-01-05 20:39:53 +01:00
Matthias Krüger
ad7aabd965
Rollup merge of #119563 - compiler-errors:coroutine-resume, r=oli-obk
Check yield terminator's resume type in borrowck

In borrowck, we didn't check that the lifetimes of the `TerminatorKind::Yield`'s `resume_place` were actually compatible with the coroutine's signature. That means that the lifetimes were totally going unchecked. Whoops!

This PR implements this checking.

Fixes #119564

r? types
2024-01-05 20:39:53 +01:00
Matthias Krüger
958417fba1
Rollup merge of #119554 - matthewjasper:remove-guard-distinction, r=compiler-errors
Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes #118593
2024-01-05 20:39:52 +01:00
Matthias Krüger
8309063e0a
Rollup merge of #119506 - compiler-errors:visibilities-for-object-safety-error, r=Nilstrieb
Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`

Inside of `report_object_error`, using the `effective_visibilities` query causes cycles since it calls `type_of`, which itself may call `typeck`, which may end up reporting its own object-safety errors.

Fixes #119346
Fixes #119502
2024-01-05 20:39:52 +01:00
Matthias Krüger
ea6129084e
Rollup merge of #119354 - fmease:negative_bounds-fixes, r=compiler-errors
Make `negative_bounds` internal & fix some of its issues

r? compiler-errors
2024-01-05 20:39:51 +01:00
Matthias Krüger
fc591dbc94
Rollup merge of #119350 - fmease:lazy-ty-aliases-implied-bounds, r=compiler-errors
Imply outlives-bounds on lazy type aliases

Fixes #118479.

r? types
2024-01-05 20:39:51 +01:00