about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2024-08-21Simplify some redundant field namesMichael Goulet-7/+2
2024-08-21Use bool in favor of Option<()> for diagnosticsMichael Goulet-10/+10
2024-08-20Move the "matches no value" note to be a span labelNadrieril-9/+6
2024-08-20fix: simple typo in compiler directoryc8ef-1/+1
2024-08-19Cap the number of patterns pointed to by the lintNadrieril-3/+18
2024-08-19Add a note with a link to explain empty typesNadrieril-0/+4
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-14/+14
2024-08-17Remove a useless ref/id/ref round-trip from `pattern_from_hir`Zalathar-6/+2
This re-lookup of `&hir::Pat` by its ID appears to be an artifact of earlier complexity that has since been removed from the compiler.
2024-08-14Auto merge of #129060 - matthiaskrgr:rollup-s72gpif, r=matthiaskrgrbors-6/+29
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-13Remove a no-longer-true `assert`Nadrieril-4/+6
2024-08-13`#[deprecated_safe_2024]`: Also use the `// TODO:` hint in the compiler errorTobias Bucher-4/+11
This doesn't work for translated compiler error messages.
2024-08-13Allow to customize `// TODO:` comment for deprecated safe autofixTobias Bucher-6/+22
Relevant for the deprecation of `CommandExt::before_exit` in #125970.
2024-08-13Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlinbors-2/+4
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-11Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errorsMatthias Krüger-2/+4
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-10Stabilize `min_exhaustive_patterns`Nadrieril-12/+7
2024-08-07Use more slice patterns inside the compilerLeón Orell Valerian Liehr-2/+4
2024-08-07Disallow enabling features without their implied featuresCaleb Zulawski-9/+1
2024-08-07Hide implicit target features from diagnostics when possibleCaleb Zulawski-5/+21
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-2/+4
2024-08-05custom MIR: add support for tail callsRalf Jung-0/+22
2024-08-01MIR required_consts, mentioned_items: ensure we do not forget to fill these ↵Ralf Jung-2/+2
lists
2024-07-31Rollup merge of #127159 - Nadrieril:hide-candidate, r=matthewjasperMatthias Krüger-245/+293
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-29Rollup merge of #128304 - Zalathar:thir-pat-display, r=NadrierilMatthias Krüger-5/+5
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-29Entirely hide `Candidate`s from outside `lower_match_tree`Nadrieril-38/+64
2024-07-29Visiting bindings is straightforward nowNadrieril-67/+14
2024-07-29Abstract out the candidate manipulation not in the main algorithmNadrieril-127/+192
2024-07-29Set up false edges in `lower_match_tree`Nadrieril-38/+42
2024-07-29Small simplificationNadrieril-14/+20
2024-07-29Encapsulate the printing of `WitnessPat`Zalathar-4/+4
This hides the fact that we print `WitnessPat` by converting it to `thir::Pat` and then printing that.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-112/+127
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Don't store `thir::Pat` in error structsZalathar-1/+1
In several cases this avoids the need to clone the underlying pattern, and then print the clone later.
2024-07-26Auto merge of #128034 - Nadrieril:explain-unreachable, r=compiler-errorsbors-28/+79
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-26Rollup merge of #128085 - Zalathar:notes, r=NadrierilMatthias Krüger-60/+198
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-25Turn an unreachable code path into an ICEOli Scherer-11/+5
2024-07-25Remove an obsolete commentZalathar-6/+0
The test mentioned by this comment was deleted long ago by <https://github.com/rust-lang/rust/pull/80290>.
2024-07-25Various notes on match loweringZalathar-54/+198
2024-07-24Improve "covered_by_many" errorNadrieril-18/+13
2024-07-24Explain why a given pattern is considered unreachableNadrieril-22/+74
2024-07-24Move rustc-specific entrypoint to the `rustc` moduleNadrieril-6/+10
2024-07-23Rollup merge of #125834 - ↵Matthias Krüger-2/+22
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-22compiler: treat `&raw (const|mut) UNSAFE_STATIC` implied deref as safeJubilee Young-2/+22
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-22Rollup merge of #125990 - tbu-:pr_unsafe_env_lint_name, r=ehussTrevor Gross-2/+2
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-21Rollup merge of #128033 - Nadrieril:explain-empty-wildcards, r=compiler-errorsJubilee-16/+20
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-21Explain why we require `_` for empty patternsNadrieril-0/+4
2024-07-21Tweak `collect_non_exhaustive_tys`Nadrieril-16/+16
2024-07-20Rollup merge of #127917 - Zalathar:after-or, r=NadrierilMatthias Krüger-91/+129
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-20Rollup merge of #127556 - Zalathar:autoref, r=NadrierilMatthias Krüger-81/+84
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-20Inline `finalize_or_candidate`Zalathar-17/+7
2024-07-20Improve `test_remaining_match_pairs_after_or`Zalathar-0/+13
2024-07-20Split out `test_remaining_match_pairs_after_or`Zalathar-43/+58
Only the last candidate can possibly have more match pairs, so this can be separate from the main or-candidate postprocessing loop.