about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src
AgeCommit message (Collapse)AuthorLines
2023-12-11Move lints to their own moduleNadrieril-5/+4
2023-12-11Gather rustc-specific functions around `MatchCheckCtxt`Nadrieril-11/+12
2023-12-11Extract exhaustiveness into its own crateNadrieril-3710/+6
2023-12-10Auto merge of #118692 - surechen:remove_unused_imports, r=petrochenkovbors-4/+2
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. r? `@petrochenkov`
2023-12-10Auto merge of #118788 - compiler-errors:const-pretty, r=fee1-deadbors-2/+2
Don't print host effect param in pretty `path_generic_args` Make `own_args_no_defaults` pass back the `GenericParamDef`, so that we can pass both the args *and* param definitions into `path_generic_args`. That allows us to use the `GenericParamDef` to filter out effect params. This allows us to filter out the host param regardless of whether it's `sym::host` or `true`/`false`. This also renames a couple of `const_effect_param` -> `host_effect_param`, and restores `~const` pretty printing to `TraitPredPrintModifiersAndPath`. cc #118785 r? `@fee1-dead` cc `@oli-obk`
2023-12-10remove redundant importssurechen-4/+2
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-09Auto merge of #118308 - Nadrieril:sound-exhaustive-patterns-take-3, ↵bors-310/+665
r=compiler-errors Don't warn an empty pattern unreachable if we're not sure the data is valid Exhaustiveness checking used to be naive about the possibility of a place containing invalid data. This could cause it to emit an "unreachable pattern" lint on an arm that was in fact reachable, as in https://github.com/rust-lang/rust/issues/117119. This PR fixes that. We now track whether a place that is matched on may hold invalid data. This also forced me to be extra precise about how exhaustiveness manages empty types. Note that this now errs in the opposite direction: the following arm is truly unreachable (because the binding causes a read of the value) but not linted as such. I'd rather not recommend writing a `match ... {}` that has the implicit side-effect of loading the value. [Never patterns](https://github.com/rust-lang/rust/issues/118155) will solve this cleanly. ```rust match union.value { _x => unreachable!(), } ``` I recommend reviewing commit by commit. I went all-in on the test suite because this went through a lot of iterations and I kept everything. The bit I'm least confident in is `is_known_valid_scrutinee` in `check_match.rs`. Fixes https://github.com/rust-lang/rust/issues/117119.
2023-12-09s/const_effect/host_effectMichael Goulet-2/+2
2023-12-09Auto merge of #116170 - matthewjasper:remove-thir-destruction-scopes, r=cjgillotbors-154/+70
Don't include destruction scopes in THIR They are not used by anyone, and add memory/performance overhead.
2023-12-09Some types cannot show up as the type of a patternNadrieril-4/+3
2023-12-09Don't warn an empty pattern unreachable if we're not sure the data is validNadrieril-39/+90
2023-12-09Track place validityNadrieril-30/+216
2023-12-09Correctly handle empty constructorsNadrieril-158/+212
- `ConstructorSet` knows about both empty and nonempty constructors; - If an empty constructor is present in the column, we output it in `split().present`.
2023-12-09Be precise about usefulness vs reachabilityNadrieril-94/+159
2023-12-08coverage: Use `SpanMarker` to mark the full condition of `if !`Zalathar-0/+5
When MIR is built for an if-not expression, the `!` part of the condition doesn't correspond to any MIR statement, so coverage instrumentation normally can't see it. We can fix that by deliberately injecting a dummy statement whose sole purpose is to associate that span with its enclosing block.
2023-12-08coverage: Use `SpanMarker` to mark `continue` expressions.Zalathar-16/+8
This replaces the previous workaround, which was to inject a dummy `Assign` statement.
2023-12-08coverage: Add `CoverageKind::SpanMarker` for including extra spans in MIRZalathar-0/+13
There are cases where coverage instrumentation wants to show a span for some syntax element, but there is no MIR node that naturally carries that span, so the instrumentor can't see it. MIR building can now use this new kind of coverage statement to deliberately include those spans in MIR, attached to a dummy statement that has no other effect.
2023-12-05Rollup merge of #118598 - Nadrieril:remove_precise_pointer_size_matching, ↵Matthias Krüger-19/+6
r=davidtwco Remove the `precise_pointer_size_matching` feature gate `usize` and `isize` are special for pattern matching because their range might depend on the platform. To make code portable across platforms, the following is never considered exhaustive: ```rust let x: usize = ...; match x { 0..=18446744073709551615 => {} } ``` Because of how rust handles constants, this also unfortunately counts `0..=usize::MAX` as non-exhaustive. The [`precise_pointer_size_matching`](https://github.com/rust-lang/rust/issues/56354) feature gate was introduced both for this convenience and for the possibility that the lang team could decide to allow the above. Since then, [half-open range patterns](https://github.com/rust-lang/rust/issues/67264) have been implemented, and since #116692 they correctly support `usize`/`isize`: ```rust match 0usize { // exhaustive! 0..5 => {} 5.. => {} } ``` I believe this subsumes all the use cases of the feature gate. Moreover no attempt has been made to stabilize it in the 5 years of its existence. I therefore propose we retire this feature gate. Closes https://github.com/rust-lang/rust/issues/56354
2023-12-04Don't include destruction scopes in THIRMatthew Jasper-154/+70
They are not used by anyone, and add memory/performance overhead.
2023-12-04Remove the `precise_pointer_size_matching` feature gateNadrieril-19/+6
2023-12-04Auto merge of #118490 - Nadrieril:arena-alloc-matrix, r=nnethercotebors-15/+8
Exhaustiveness: allocate memory better Exhaustiveness is a recursive algorithm that allocates a bunch of slices at every step. Let's see if I can improve performance by improving allocations. Already just using `Vec::with_capacity` is showing impressive improvements on my local measurements. r? `@ghost`
2023-12-02Anticipate allocation sizesNadrieril-15/+8
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-9/+9
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-11-30Auto merge of #118379 - compiler-errors:const-params-for-partialeq, r=fee1-deadbors-3/+16
Fix `PartialEq` args when `#[const_trait]` is enabled This is based off of your PR that enforces effects on all methods, so just see the last commits. r? fee1-dead
2023-11-29Rollup merge of #118333 - eduardosm:print-missing-target-features, r=est31Matthias Krüger-16/+89
Print list of missing target features when calling a function with target features outside an unsafe block Fixes https://github.com/rust-lang/rust/issues/108680 Supersedes https://github.com/rust-lang/rust/pull/109710. I used the same wording for the messages, but the implementation is different. r? `@est31`
2023-11-29Rollup merge of #118157 - Nadrieril:never_pat-feature-gate, r=compiler-errorsMatthias Krüger-1/+22
Add `never_patterns` feature gate This PR adds the feature gate and most basic parsing for the experimental `never_patterns` feature. See the tracking issue (https://github.com/rust-lang/rust/issues/118155) for details on the experiment. `@scottmcm` has agreed to be my lang-team liaison for this experiment.
2023-11-29Add `never_patterns` feature gateNadrieril-1/+22
2023-11-28Add with_opt_const_effect_param helper, simplifyMichael Goulet-18/+15
2023-11-28Fix PartialEq args when #[const_trait] is enabledMichael Goulet-3/+19
2023-11-28thir-unsafeck: print list of missing target features when calling a function ↵Eduardo Sánchez Muñoz-16/+89
with target features outside an unsafe block
2023-11-28Auto merge of #118405 - matthiaskrgr:rollup-3a2eevc, r=matthiaskrgrbors-2/+8
Rollup of 7 pull requests Successful merges: - #115331 (optimize str::iter::Chars::advance_by) - #118236 (Update mod comment) - #118299 (Update `OnceLock` documentation to give a concrete 'lazy static' example, and expand on the existing example.) - #118314 (Rename `{collections=>alloc}{tests,benches}`) - #118341 (Simplify indenting in THIR printing) - #118366 (Detect and reject malformed `repr(Rust)` hints) - #118397 (Fix comments for unsigned non-zero `checked_add`, `saturating_add`) r? `@ghost` `@rustbot` modify labels: rollup
2023-11-28Auto merge of #118282 - fee1-dead-contrib:enforce-more, r=compiler-errorsbors-4/+4
effects: Run `enforce_context_effects` for all method calls So that we also perform checks when overloaded `PartialEq`s are called. r? `@compiler-errors`
2023-11-26Simplify indenting in THIR printingMark Rousskov-2/+8
This cuts >100kb from a local librustc_driver.so build, and seems just obviously simpler.
2023-11-26Rollup merge of #118311 - bvanjoi:merge_coroutinue_into_closure, r=petrochenkovGuillaume Gomez-20/+20
merge `DefKind::Coroutine` into `Defkind::Closure` Related to #118188 We no longer need to be concerned about the precise type whether it's `DefKind::Closure` or `DefKind::Coroutine`. Furthermore, thanks for the great work done by `@petrochenkov` on investigating https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Why.20does.20it.20hang.20when.20querying.20.EF.BB.BF.60opt_def_kind.60.3F r? `@petrochenkov`
2023-11-26Rollup merge of #118302 - mu001999:dead_code/clean, r=cjgillotGuillaume Gomez-149/+3
Clean dead codes Clean dead codes detected by #118257
2023-11-26merge `DefKind::Coroutine` into `DefKind::Closure`bohan-20/+20
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-10/+10
cleanup
2023-11-26Auto merge of #118300 - compiler-errors:rollup-cm3i8fg, r=compiler-errorsbors-5/+2
Rollup of 7 pull requests Successful merges: - #117651 (coverage: Simplify building coverage expressions based on sums) - #117968 (Stabilize `ptr::addr_eq`) - #118158 (Reduce fluent boilerplate) - #118201 (Miscellaneous `ObligationCauseCode` cleanups) - #118288 (Use `is_{some,ok}_and` more in the compiler) - #118289 (`is_{some,ok}_and` for rustdoc) - #118290 (Don't ICE when encountering placeholders in implied bounds computation) r? `@ghost` `@rustbot` modify labels: rollup
2023-11-26Clean dead codesr0cky-149/+3
2023-11-26Auto merge of #117611 - Nadrieril:linear-pass-take-4, r=cjgillotbors-764/+1013
Rewrite exhaustiveness in one pass This is at least my 4th attempt at this in as many years x) Previous attempts were all too complicated or too slow. But we're finally here! The previous version of the exhaustiveness algorithm computed reachability for each arm then exhaustiveness of the whole match. Since each of these steps does roughly the same things, this rewrites the algorithm to do them all in one go. I also think this makes things much simpler. I also rewrote the documentation of the algorithm in depth. Hopefully it's up-to-date and easier to follow now. Plz comment if anything's unclear. r? `@oli-obk` I think you're one of the rare other people to understand the exhaustiveness algorithm? cc `@varkor` I know you're not active anymore, but if you feel like having a look you might enjoy this :D Fixes https://github.com/rust-lang/rust/issues/79307
2023-11-25Rollup merge of #118288 - compiler-errors:is_some_and, r=lqd,dtolnayMichael Goulet-1/+1
Use `is_{some,ok}_and` more in the compiler slightly more fluent-reading code
2023-11-25Rollup merge of #118158 - nnethercote:reduce-fluent-boilerplate, ↵Michael Goulet-4/+1
r=compiler-errors Reduce fluent boilerplate Best reviewed one commit at a time. r? `@davidtwco`
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-3/+1
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-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+0
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-25is_{some,ok}_andMichael Goulet-1/+1
2023-11-25Review commentMichael Goulet-20/+8
2023-11-25make sure we still eagerly emit errorsMichael Goulet-2/+4
2023-11-25Remove mir::Const::from_anon_constMichael Goulet-4/+22
2023-11-25effects: Run `enforce_context_effects` for all method callsDeadbeef-4/+4
2023-11-22Replace `no_ord_impl` with `orderable`.Nicholas Nethercote-0/+1
Similar to the previous commit, this replaces `newtype_index`'s opt-out `no_ord_impl` attribute with the opt-in `orderable` attribute.