Commit Graph

1953 Commits

Author SHA1 Message Date
Nadrieril
36eced444e Cap the number of patterns pointed to by the lint 2024-08-19 21:57:40 +02:00
Nadrieril
efb28bdd90 Add a note with a link to explain empty types 2024-08-19 21:57:37 +02:00
Nadrieril
25964b541e Reword the "unreachable pattern" explanations 2024-08-19 21:39:57 +02:00
bors
fbce03b195 Auto merge of #129060 - matthiaskrgr:rollup-s72gpif, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #122884 (Optimize integer `pow` by removing the exit branch)
 - #127857 (Allow to customize `// TODO:` comment for deprecated safe autofix)
 - #129034 (Add `#[must_use]` attribute to `Coroutine` trait)
 - #129049 (compiletest: Don't panic on unknown JSON-like output lines)
 - #129050 (Emit a warning instead of an error if `--generate-link-to-definition` is used with other output formats than HTML)
 - #129056 (Fix one usage of target triple in bootstrap)
 - #129058 (Add mw back to review rotation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-14 06:43:26 +00:00
Nadrieril
249a588cad Remove a no-longer-true assert 2024-08-13 23:00:42 +02:00
Tobias Bucher
811d7dd113 #[deprecated_safe_2024]: Also use the // TODO: hint in the compiler error
This doesn't work for translated compiler error messages.
2024-08-13 11:32:47 +02:00
Tobias Bucher
399ef23d2b Allow to customize // TODO: comment for deprecated safe autofix
Relevant for the deprecation of `CommandExt::before_exit` in #125970.
2024-08-13 11:32:24 +02:00
bors
591ecb88df Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlin
miri: make vtable addresses not globally unique

Miri currently gives vtables a unique global address. That's not actually matching reality though. So this PR enables Miri to generate different addresses for the same type-trait pair.

To avoid generating an unbounded number of `AllocId` (and consuming unbounded amounts of memory), we use the "salt" technique that we also already use for giving constants non-unique addresses: the cache is keyed on a "salt" value n top of the actually relevant key, and Miri picks a random salt (currently in the range `0..16`) each time it needs to choose an `AllocId` for one of these globals -- that means we'll get up to 16 different addresses for each vtable. The salt scheme is integrated into the global allocation deduplication logic in `tcx`, and also used for functions and string literals. (So this also fixes the problem that casting the same function to a fn ptr over and over will consume unbounded memory.)

r? `@saethlin`
Fixes https://github.com/rust-lang/miri/issues/3737
2024-08-13 04:32:34 +00:00
Matthias Krüger
32e0fe129d
Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors
Use more slice patterns inside the compiler

Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'.

r? ghost
2024-08-11 07:51:51 +02:00
Nadrieril
cd40769c02 Stabilize min_exhaustive_patterns 2024-08-10 12:07:17 +02:00
León Orell Valerian Liehr
c4c518d2d4
Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
Caleb Zulawski
8818c95528 Disallow enabling features without their implied features 2024-08-07 00:45:00 -04:00
Caleb Zulawski
83276f5680 Hide implicit target features from diagnostics when possible 2024-08-07 00:43:52 -04:00
Ralf Jung
5cab8ae4a4 miri: make vtable addresses not globally unique 2024-08-06 19:09:31 +02:00
Ralf Jung
212417b87f custom MIR: add support for tail calls 2024-08-05 18:23:14 +02:00
Ralf Jung
6d312d7bd1 MIR required_consts, mentioned_items: ensure we do not forget to fill these lists 2024-08-01 15:49:25 +02:00
Matthias Krüger
19f6ff0655
Rollup merge of #127159 - Nadrieril:hide-candidate, r=matthewjasper
match lowering: Hide `Candidate` from outside the lowering algorithm

The internals of `Candidate` are tricky and a source of confusion. This PR makes it so we don't expose `Candidate`s outside the lowering algorithm. Now:
- false edges are handled in `lower_match_tree`;
- `lower_match_tree` takes a list of patterns as input;
- `lower_match_tree` returns a flat datastructure that contains only the necessary information.

r? ```@matthewjasper```
2024-07-31 23:20:10 +02:00
Matthias Krüger
d73decdaad
Rollup merge of #128304 - Zalathar:thir-pat-display, r=Nadrieril
Isolate the diagnostic code that expects `thir::Pat` to be printable

Currently, `thir::Pat` implements `fmt::Display` (and `IntoDiagArg`) directly, for use by a few diagnostics.

That makes it tricky to experiment with alternate representations for THIR patterns, because the patterns currently need to be printable on their own. That immediately rules out possibilities like storing subpatterns as a `PatId` index into a central list (instead of the current directly-owned `Box<Pat>`).

This PR therefore takes an incremental step away from that obstacle, by removing `thir::Pat` from diagnostic structs in `rustc_pattern_analysis`, and hiding the pattern-printing process behind a single public `Pat::to_string` method. Doing so makes it easier to identify and update the code that wants to print patterns, and gives a place to pass in additional context in the future if necessary.

---

I'm currently not sure whether switching over to `PatId` is actually desirable or not, but I think this change makes sense on its own merits, by reducing the coupling between `thir::Pat` and the pattern-analysis error types.
2024-07-29 11:42:34 +02:00
Nadrieril
08bcc01394 Entirely hide Candidates from outside lower_match_tree 2024-07-29 10:03:32 +02:00
Nadrieril
c7471664b3 Visiting bindings is straightforward now 2024-07-29 10:03:32 +02:00
Nadrieril
cbdacec188 Abstract out the candidate manipulation not in the main algorithm 2024-07-29 09:50:07 +02:00
Nadrieril
e2fd9aa33e Set up false edges in lower_match_tree 2024-07-29 09:50:07 +02:00
Nadrieril
9e05fb67a3 Small simplification 2024-07-29 09:50:07 +02:00
Zalathar
db05b0fd34 Encapsulate the printing of WitnessPat
This hides the fact that we print `WitnessPat` by converting it to `thir::Pat`
and then printing that.
2024-07-29 14:56:50 +10:00
Nicholas Nethercote
84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Zalathar
e1fc4a997d Don't store thir::Pat in error structs
In several cases this avoids the need to clone the underlying pattern, and then
print the clone later.
2024-07-28 21:58:44 +10:00
bors
355efacf0d Auto merge of #128034 - Nadrieril:explain-unreachable, r=compiler-errors
exhaustiveness: Explain why a given pattern is considered unreachable

This PR tells the user why a given pattern is considered unreachable. I reused the intersection information we were already computing; even though it's incomplete I convinced myself that it is sufficient to always get a set of patterns that cover the unreachable one.

I'm not a fan of the diagnostic messages I came up with, I'm open to suggestions.

Fixes https://github.com/rust-lang/rust/issues/127870. This is also the other one of the two diagnostic improvements I wanted to do before https://github.com/rust-lang/rust/pull/122792.

Note: the first commit is an unrelated drive-by tweak.

r? `@compiler-errors`
2024-07-26 10:51:04 +00:00
Matthias Krüger
f345c5e845
Rollup merge of #128085 - Zalathar:notes, r=Nadrieril
Various notes on match lowering

This is an assortment of comments for things that I found unclear or confusing when I was learning how match lowering works.

This PR only adds/modifies comments, so there are no functional changes.

I have tried to avoid touching code that would conflict with #127159.

r? `@Nadrieril`
2024-07-26 00:57:22 +02:00
Oli Scherer
0706cc6397 Turn an unreachable code path into an ICE 2024-07-25 15:33:34 +00:00
Zalathar
31f31aa471 Remove an obsolete comment
The test mentioned by this comment was deleted long ago by
<https://github.com/rust-lang/rust/pull/80290>.
2024-07-25 16:41:51 +10:00
Zalathar
118a70f38c Various notes on match lowering 2024-07-25 16:22:55 +10:00
Nadrieril
940769a79b Improve "covered_by_many" error 2024-07-24 08:46:52 +02:00
Nadrieril
64ac2b8082 Explain why a given pattern is considered unreachable 2024-07-24 08:02:55 +02:00
Nadrieril
bab8ede761 Move rustc-specific entrypoint to the rustc module 2024-07-24 08:02:55 +02:00
Matthias Krüger
1b4b0e9a4d
Rollup merge of #125834 - workingjubilee:weaken-thir-unsafeck-for-addr-of-static-mut, r=compiler-errors
treat `&raw (const|mut) UNSAFE_STATIC` implied deref as safe

Fixes rust-lang/rust#125833

As reported in that and related issues, `static mut STATIC_MUT: T` is very often used in embedded code, and is in many ways equivalent to `static STATIC_CELL: SyncUnsafeCell<T>`. The Rust expression of `&raw mut STATIC_MUT` and `SyncUnsafeCell::get(&STATIC_CELL)` are approximately equal, and both evaluate to `*mut T`. The library function is safe because it has *declared itself* to be safe. However, the raw ref operator is unsafe because all uses of `static mut` are considered unsafe, even though the static's value is not used by this expression (unlike, for example, `&STATIC_MUT`).

We can fix this unnatural difference by simply adding the proper exclusion for the safety check inside the THIR unsafeck, so that we do not declare it unsafe if it is not.

While the primary concern here is `static mut`, this change is made for all instances of an "unsafe static", which includes a static declared inside `extern "abi" {}`. Hypothetically, we could go as far as generalizing this to all instances of `&raw (const|mut) *ptr`, but today we do not, as we have not actually considered the range of possible expressions that use a similar encoding. We do not even extend this to thread-local equivalents, because they have less clear semantics.
2024-07-23 13:06:54 +02:00
Jubilee Young
3fdd8d5ef3 compiler: treat &raw (const|mut) UNSAFE_STATIC implied deref as safe
The implied deref to statics introduced by HIR->THIR lowering is only
used to create place expressions, it lacks unsafe semantics.
It is also confusing, as there is no visible `*ident` in the source.
For both classes of "unsafe static" (extern static and static mut)
allow this operation.

We lack a clear story around `thread_local! { static mut }`, which
is actually its own category of item that reuses the static syntax but
has its own rules. It's possible they should be similarly included, but
in the absence of a good reason one way or another, we do not bless it.
2024-07-22 14:54:36 -07:00
Trevor Gross
81135a015f
Rollup merge of #125990 - tbu-:pr_unsafe_env_lint_name, r=ehuss
Rename `deprecated_safe` lint to `deprecated_safe_2024`

Create a lint group `deprecated_safe` that includes `deprecated_safe_2024`.

Addresses https://github.com/rust-lang/rust/issues/124866#issuecomment-2142814375.

r? `@ehuss`
2024-07-22 11:40:19 -05:00
Jubilee
d484654a5e
Rollup merge of #128033 - Nadrieril:explain-empty-wildcards, r=compiler-errors
Explain why we require `_` for empty patterns

This adds a note to the "non-exhaustive patterns" diagnostic to explain why we sometimes require extra `_` patterns on empty types. This is one of the two diagnostic improvements I wanted to do before [stabilizing `min_exhaustive_patterns`](https://github.com/rust-lang/rust/pull/122792).

r? ``@compiler-errors``
2024-07-21 17:44:30 -07:00
Nadrieril
8a49d83db7 Explain why we require _ for empty patterns 2024-07-21 15:24:27 +02:00
Nadrieril
710add58e2 Tweak collect_non_exhaustive_tys 2024-07-21 15:24:27 +02:00
Matthias Krüger
d846e9252c
Rollup merge of #127917 - Zalathar:after-or, r=Nadrieril
match lowering: Split `finalize_or_candidate` into more coherent methods

I noticed that `finalize_or_candidate` was responsible for several different postprocessing tasks, making it difficult to understand.

This PR aims to clean up some of the confusion by:
- Extracting `remove_never_subcandidates` from `merge_trivial_subcandidates`
- Extracting `test_remaining_match_pairs_after_or` from `finalize_or_candidate`
- Taking what remains of `finalize_or_candidate`, and inlining it into its caller

---
Reviewing individual commits and ignoring whitespace is recommended.

Most of the large-looking changes are just moving existing code around, mostly unaltered.

r? ``@Nadrieril``
2024-07-20 13:24:54 +02:00
Matthias Krüger
dfee7ed13f
Rollup merge of #127556 - Zalathar:autoref, r=Nadrieril
Replace a long inline "autoref" comment with method docs

This comment has two problems:

- It is very long, making the flow of the enclosing method hard to follow.
- It starts by talking about an `autoref` flag that hasn't existed since #59114.
  - This makes it hard to trust that the information in the comment is accurate or relevant, even though much of it still seems to be true.

This PR therefore replaces the long inline comment with a revised doc comment on `bind_matched_candidate_for_guard`, and some shorter inline comments.

For readers who want more historical context, we also link to the PR that added the old comment, and the PR that removed the `autoref` flag.
2024-07-20 07:13:41 +02:00
Zalathar
239037ecde Inline finalize_or_candidate 2024-07-20 13:29:03 +10:00
Zalathar
886668cc2e Improve test_remaining_match_pairs_after_or 2024-07-20 13:29:03 +10:00
Zalathar
e60c5c1a77 Split out test_remaining_match_pairs_after_or
Only the last candidate can possibly have more match pairs, so this can be
separate from the main or-candidate postprocessing loop.
2024-07-20 12:45:12 +10:00
Zalathar
e091c356fa Improve merge_trivial_subcandidates 2024-07-20 12:45:11 +10:00
Zalathar
3b7e4bc77a Split out remove_never_subcandidates 2024-07-20 12:45:11 +10:00
Matthias Krüger
4d5ba0d2c7
Rollup merge of #127858 - Zalathar:pair-tree, r=Nadrieril
match lowering: Rename `MatchPair` to `MatchPairTree`

In #120904, `MatchPair` became able to store other match pairs as children, forming a tree. That has made the old name confusing, so this patch renames the type to `MatchPairTree`.

This PR also includes a patch renaming the `test` method to `pick_test_for_match_pair`, since it would conflict with the main change.

r? `@Nadrieril`
2024-07-18 23:05:22 +02:00
Ralf Jung
303a2db236 remove saw_const_match_error; check if pattern contains an Error instead 2024-07-18 11:58:16 +02:00
Ralf Jung
67c99d6338 avoid creating an Instance only to immediately disassemble it again 2024-07-18 11:58:16 +02:00