about summary refs log tree commit diff
path: root/compiler/rustc_mir_build/src/build
AgeCommit message (Collapse)AuthorLines
2024-12-17Rename `rustc_mir_build::build` to `builder`Zalathar-12234/+0
2024-12-16Rollup merge of #134371 - scottmcm:fix-134352, r=oli-obkMatthias Krüger-7/+25
Check for array lengths that aren't actually `usize` I wish typeck wouldn't give us `ty::Array`s that have this problem in the first place, but we can check for it. Fixes #134352 cc ``@matthiaskrgr``
2024-12-16Rollup merge of #134314 - compiler-errors:default-struct-value-const, r=estebankMatthias Krüger-5/+11
Make sure to use normalized ty for unevaluated const in default struct value This cleans up the way that we construct the `mir::Const::Unevaluated` for default struct values. We were previously using `from_unevaluated`, which doesn't normalize the type, and is really only used for inline assembly. Other codepaths (such as `ExprKind::NamedConst`) use the type from the body. Also, let's stop using `literal_operand`, which also is really not meant for calls other than for literal comparisons in pattern lowering. Also move all of the tests to a separate subdirectory so they don't need to have the same prefix on all the test files. Fixes #134298 r? estebank or reassign
2024-12-15Check for array lengths that aren't actually `usize`Scott McMurray-7/+25
2024-12-15Add hir::AttributeJonathan Dönszelmann-2/+1
2024-12-14Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, ↵bors-9/+83
r=davidtwco,RalfJung Bounds-check with PtrMetadata instead of Len in MIR Rather than emitting `Len(*_n)` in array index bounds checks, emit `PtrMetadata(copy _n)` instead -- with some asterisks for arrays and `&mut` that need it to be done slightly differently. We're getting pretty close to removing `Len` entirely, actually. I think just one more PR after this (for slice drop shims). r? mir
2024-12-14Make sure to use normalized ty for unevaluated const for default struct valueMichael Goulet-5/+11
2024-12-14Split UserTypeAnnotation to have a kindMichael Goulet-3/+2
2024-12-13Don't retag the `PtrMetadata(&raw const *_n)` in slice indexingScott McMurray-2/+11
2024-12-09review comments: rewordingsEsteban Küber-1/+1
2024-12-09Introduce `default_field_values` featureEsteban Küber-21/+45
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-12-05Rollup merge of #133607 - WaffleLapkin:tail-call-checks, r=compiler-errorsGuillaume Gomez-0/+4
implement checks for tail calls Quoting the [RFC draft](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md): > The argument to become is a function (or method) call, that exactly matches the function signature and calling convention of the callee. The intent is to ensure a matching ABI. Note that lifetimes may differ as long as they pass borrow checking, see [below](https://github.com/phi-go/rfcs/blob/guaranteed-tco/text/0000-explicit-tail-calls.md#return-type-coercion) for specifics on the return type. > Tail calling closures and tail calling from closures is not allowed. This is due to the high implementation effort, see below, this restriction can be lifted by a future RFC. > Invocations of operators were considered as valid targets but were rejected on grounds of being too error-prone. In any case, these can still be called as methods. > Tail calling [variadic functions](https://doc.rust-lang.org/beta/unstable-book/language-features/c-variadic.html) and tail calling from variadic functions is not allowed. As support for variadic function is stabilized on a per target level, support for tail-calls regarding variadic functions would need to follow a similar approach. To avoid this complexity and to minimize implementation effort for backends, this interaction is currently not allowed but support can be added with a future RFC. ----- The checks are implemented as a query, similarly to `check_unsafety`. The code is cherry-picked straight out of #112657 which was written more than a year ago, so I expect we might need to change some things ^^"
2024-12-03Bounds-check with PtrMetadata instead of Len in MIRScott McMurray-8/+73
2024-12-02remove `Ty::is_copy_modulo_regions`lcnr-1/+1
2024-11-29implement checks for tail callsMaybe Waffle-0/+4
this implements checks necessary to guarantee that we can actually perform a tail call. while extremely restrictive, this is what is documented in the RFC, and all these checks are needed for one reason or another.
2024-11-28fix a comment with uneven number of backticks in rustc_mir_buildMaybe Lapkin-1/+1
this is funny though! apparently tidy parsed `.gitignore`, but did not recognize unignore lines (`!...`), so tidy was ignoring `rustc_mir_build` this whole time (at least for some lints?).
2024-11-20Auto merge of #133261 - matthiaskrgr:rollup-ekui4we, r=matthiaskrgrbors-9/+21
Rollup of 6 pull requests Successful merges: - #129838 (uefi: process: Add args support) - #130800 (Mark `get_mut` and `set_position` in `std::io::Cursor` as const.) - #132708 (Point at `const` definition when used instead of a binding in a `let` statement) - #133226 (Make `PointerLike` opt-in instead of built-in) - #133244 (Account for `wasm32v1-none` when exporting TLS symbols) - #133257 (Add `UnordMap::clear` method) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-20Rollup merge of #132708 - estebank:const-as-binding, r=NadrierilMatthias Krüger-9/+21
Point at `const` definition when used instead of a binding in a `let` statement Modify `PatKind::InlineConstant` to be `ExpandedConstant` standing in not only for inline `const` blocks but also for `const` items. This allows us to track named `const`s used in patterns when the pattern is a single binding. When we detect that there is a refutable pattern involving a `const` that could have been a binding instead, we point at the `const` item, and suggest renaming. We do this for both `let` bindings and `match` expressions missing a catch-all arm if there's at least one single binding pattern referenced. After: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | const PAT: u32 = 0; | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable ... LL | let PAT = v1; | ^^^ pattern `1_u32..=u32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` help: introduce a variable instead | LL | let PAT_var = v1; | ~~~~~~~ ``` Before: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ``` CC #132582.
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-53/+145
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-19move `fn is_item_raw` to `TypingEnv`lcnr-4/+6
2024-11-18reviewlcnr-0/+2
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-27/+41
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-11-17Account for `ExpandedConstant` in `parse_match`Esteban Küber-6/+14
2024-11-17Unify expanded constants and named constants in `PatKind`Esteban Küber-5/+9
2024-11-17Fold `PatKind::NamedConstant` into `PatKind::Constant`Esteban Küber-7/+2
2024-11-17Point at `const` definition when used instead of a binding in a `let` statementEsteban Küber-2/+7
After: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | const PAT: u32 = 0; | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable ... LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ``` Before: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ```
2024-11-01Show actual MIR when MIR building forgot to terminate blockbjorn3-6/+17
This makes it significantly easier to debug bugs of this kind.
2024-10-30compiler: Switch to rustc_abi in hir_pretty, lint_defs, and mir_buildJubilee Young-9/+8
Completely abandon usage of rustc_target in these crates, as they need no special knowledge of rustc's target tuples.
2024-10-30Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errorsJubilee-2/+2
Rename `rustc_abi::Abi` to `BackendRepr` Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights. Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-2/+2
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-29TypingMode :thinking:lcnr-3/+7
2024-10-23Rollup merge of #132060 - joshtriplett:innermost-outermost, r=jieyouxuLeón Orell Valerian Liehr-4/+4
"innermost", "outermost", "leftmost", and "rightmost" don't need hyphens These are all standard dictionary words and don't require hyphenation. ----- Encountered an instance of this in error messages and it bugged me, so I figured I'd fix it across the entire codebase.
2024-10-23"innermost", "outermost", "leftmost", and "rightmost" don't need hyphensJosh Triplett-4/+4
These are all standard dictionary words and don't require hyphenation.
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-2/+2
2024-10-20Rip out old effects var handling code from traitsMichael Goulet-6/+1
2024-10-08coverage. Adapt to mcdc mapping formats introduced by llvm 19zhuyunxing-40/+54
2024-10-08coverage. MCDC ConditionId start from 0 to keep with llvm 19zhuyunxing-12/+17
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-24be even more precise about "cast" vs "coercion"Lukas Markeffsky-4/+12
2024-09-24use more accurate spans for user type ascriptionsLukas Markeffsky-6/+8
2024-09-23Rollup merge of #130715 - compiler-errors:mir-build-const-eval, r=BoxyUwUMatthias Krüger-2/+7
Replace calls to `ty::Const::{try_}eval` in mir build/pattern analysis We normalize consts in writeback: #130645. This means that consts are gonna be as normalized as they're ever gonna get in MIR building and pattern analysis. Therefore we can just use `try_to_target_usize` rather than calling `eval_target_usize`. Regarding the `.expect` calls, I'm not totally certain whether they're correct given rigid unevaluated consts. But this PR shouldn't make *more* ICEs occur; we may have to squash these ICEs when mGCE comes around, tho 😺
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-337/+245
2024-09-22Replace calls to Const::eval in mir buildMichael Goulet-2/+7
2024-09-14Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnrLeón Orell Valerian Liehr-7/+6
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`
2024-09-13Rename and reorder lots of lifetimes.Nicholas Nethercote-7/+6
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and 'me with vanilla 'a. These are cases where the original name isn't really any more informative than 'a. - Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime applies to multiple fields and so the original lifetime name isn't really accurate. - Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-13Auto merge of #107251 - dingxiangfei2009:let-chain-rescope, r=jieyouxubors-0/+10
Rescope temp lifetime in if-let into IfElse with migration lint Tracking issue #124085 This PR shortens the temporary lifetime to cover only the pattern matching and consequent branch of a `if let`. At the expression location, means that the lifetime is shortened from previously the deepest enclosing block or statement in Edition 2021. This warrants an Edition change. Coming with the Edition change, this patch also implements an edition lint to warn about the change and a safe rewrite suggestion to preserve the 2021 semantics in most cases. Related to #103108. Related crater runs: https://github.com/rust-lang/rust/pull/129466.
2024-09-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-3/+2
Simplify some nested `if` statements Applies some but not all instances of `clippy::collapsible_if`. Some ended up looking worse afterwards, though, so I left those out. Also applies instances of `clippy::collapsible_else_if` Review with whitespace disabled please.
2024-09-11Simplify some nested if statementsMichael Goulet-3/+2
2024-09-11rescope temp lifetime in let-chain into IfElseDing Xiang Fei-0/+10
apply rules by span edition
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-7/+5