about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src/build/expr/into.rs
AgeCommit message (Collapse)AuthorLines
2024-12-17Rename `rustc_mir_build::build` to `builder`Zalathar-650/+0
2024-12-14Make sure to use normalized ty for unevaluated const for default struct valueMichael Goulet-5/+11
2024-12-09review comments: rewordingsEsteban Küber-1/+1
2024-12-09Introduce `default_field_values` featureEsteban Küber-20/+44
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-11/+7
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-1/+5
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-6/+13
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-56/+43
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+6
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-08Stop using `unpack!` for `BlockAnd<()>`Zalathar-3/+3
2024-07-08Remove the non-assigning form of `unpack!`Zalathar-10/+14
This kind of unpacking can be expressed as an ordinary method on `BlockAnd<()>`.
2024-06-30Replace a magic boolean with enum `DeclareLetBindings`Zalathar-2/+3
The new enum `DeclareLetBindings` has three variants: - `Yes`: Declare `let` bindings as normal, for `if` conditions. - `No`: Don't declare bindings, for match guards and let-else. - `LetNotPermitted`: Assert that `let` expressions should not occur.
2024-06-21Save 2 pointers in `TerminatorKind` (96 → 80 bytes)Scott McMurray-2/+2
These things don't need to be `Vec`s; boxed slices are enough. The frequent one here is call arguments, but MIR building knows the number of arguments from the THIR, so the collect is always getting the allocation right in the first place, and thus this shouldn't ever add the shrink-in-place overhead.
2024-06-19coverage: Make MCDC take in account last RHS of condition-coverageDorian Péron-0/+3
Condition coverage extends branch coverage to treat the specific case of last operands of boolean decisions not involved in control flow. This is ultimately made for MCDC to be exhaustive on all boolean expressions. This patch adds a call to `visit_branch_coverage_operation` to track the top-level operand of the said decisions, and changes `visit_coverage_standalone_condition` so MCDC branch registration is called when enabled on these _last RHS_ cases.
2024-05-30coverage: Instrument the RHS value of lazy logical operatorsZalathar-2/+6
When a lazy logical operator (`&&` or `||`) occurs outside of an `if` condition, it normally doesn't have any associated control-flow branch, so we don't have an existing way to track whether it was true or false. This patch adds special code to handle this case, by inserting extra MIR blocks in a diamond shape after evaluating the RHS. This gives us a place to insert the appropriate marker statements, which can then be given their own counters.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_mir_build`.Nicholas Nethercote-0/+1
2024-05-13Remove `extern crate rustc_middle` from `rustc_mir_build`.Nicholas Nethercote-0/+1
2024-04-03Remove MIR unsafe checkMatthew Jasper-1/+1
This also remove safety information from MIR.
2024-03-08Rollup merge of #119365 - nbdd0121:asm-goto, r=AmanieuMatthias Krüger-7/+25
Add asm goto support to `asm!` Tracking issue: #119364 This PR implements asm-goto support, using the syntax described in "future possibilities" section of [RFC2873](https://rust-lang.github.io/rfcs/2873-inline-asm.html#asm-goto). Currently I have only implemented the `label` part, not the `fallthrough` part (i.e. fallthrough is implicit). This doesn't reduce the expressive though, since you can use label-break to get arbitrary control flow or simply set a value and rely on jump threading optimisation to get the desired control flow. I can add that later if deemed necessary. r? ``@Amanieu`` cc ``@ojeda``
2024-03-07Don't pass a break scope to `Builder::break_for_else`Zalathar-2/+0
This method would previously take a target scope, and then verify that it was equal to the scope on top of the if-then scope stack. In practice, this means that callers have to go out of their way to pass around redundant scope information that's already on the if-then stack. So it's easier to just retrieve the correct scope directly from the if-then stack, and simplify the other code that was passing it around.
2024-03-06Additional comments for lowering `if`Zalathar-0/+8
2024-03-06Clarify lowering the `else` arm into the else blockZalathar-6/+6
2024-03-06Clarify how lowering `if` produces then/else blocksZalathar-30/+31
This makes it easier to see that the call to `in_scope` returns both the then block and the else block. The rather confusing `unpack!` step is confined to its own separate line. (This patch reindents several lines, so using "ignore whitespace" is recommended in order to focus on the actual changes.)
2024-03-04Extract an arguments struct for `Builder::then_else_break`Zalathar-3/+5
Most of this method's arguments are usually or always forwarded as-is to recursive invocations. Wrapping them in a dedicated struct allows us to document each struct field, and lets us use struct-update syntax to indicate which arguments are being modified when making a recursive call.
2024-03-02The ordinary lowering of `thir::ExprKind::Let` is unreachableZalathar-32/+6
After desugaring, `let` expressions should only appear inside `if` expressions or `match` guards, possibly nested within a let-chain. In both cases they are specifically handled by the lowerings of those expressions, so this case is currently unreachable.
2024-02-24Implement asm goto in MIR and MIR loweringGary Guo-9/+24
2024-02-24Change InlineAsm to allow multiple targets insteadGary Guo-3/+3
2024-02-24Add asm label support to THIRGary Guo-0/+3
2024-01-15compiler: Lower fn call arg spans down to MIRMartin Nordholts-1/+5
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-05Remove `hir::Guard`Matthew Jasper-1/+3
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2023-12-18Pass THIR ExprIds in MIR buildingMatthew Jasper-50/+47
2023-10-20s/generator/coroutine/Oli Scherer-1/+1
2023-09-21rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::ConstRalf Jung-8/+16
2023-08-30use if only on lhs of binary logical exprsDing Xiang Fei-16/+18
2023-08-30lower bare boolean expression with if-constructDing Xiang Fei-39/+29
2023-08-14Move scrutinee `HirId` into `MatchSource::TryDesugar`Esteban Küber-1/+1
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-2/+2
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-1/+1
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-06-27`thir`: Add `Become` expression kindMaybe Waffle-1/+4
2023-06-18Better error for non const `PartialEq` call generated by `match`Deadbeef-1/+5
2023-04-21offset_ofDrMeepster-1/+2
2023-04-17Spelling - compilerJosh Soref-2/+2
* 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-06Add `UnwindAction::Terminate`Gary Guo-1/+5
2023-04-06Refactor unwind from Option to a new enumGary Guo-3/+6
2023-04-01Use `FieldIdx` in various things related to aggregatesScott McMurray-7/+4
Shrank `AggregateKind` by 8 bytes on x64, since the active field of a union is tracked as an `Option<FieldIdx>` instead of `Option<usize>`.
2023-03-28Move `mir::Field` → `abi::FieldIdx`Scott McMurray-1/+2
The first PR for https://github.com/rust-lang/compiler-team/issues/606 This is just the move-and-rename, because it's plenty big-and-bitrotty already. Future PRs will start using `FieldIdx` more broadly, and concomitantly removing `FieldIdx::new`s.
2023-03-14Wrap the whole LocalInfo in ClearCrossCrate.Camille GILLOT-3/+2
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-1/+1
2022-12-19Revert "Auto merge of #103880 - b-naber:field-ty-mir, r=lcnr"Rémy Rakic-5/+3
This reverts commit 03770f0e2b60c02db8fcf52fed5fb36aac70cedc, reversing changes made to 01ef4b21dc5251b58bd9c6fd6face2ae95d56da1.