about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/thir
AgeCommit message (Collapse)AuthorLines
2024-12-09Introduce `default_field_values` featureEsteban Küber-1/+2
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-17Unify expanded constants and named constants in `PatKind`Esteban Küber-2/+2
2024-11-17Fold `PatKind::NamedConstant` into `PatKind::Constant`Esteban Küber-1/+1
2024-11-17Point at `const` definition when used instead of a binding in a `let` statementEsteban Küber-1/+1
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-10-06various fixes for `naked_asm!` implementationFolkert de Vries-1/+7
- 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-1/+3
2024-09-24use more accurate spans for user type ascriptionsLukas Markeffsky-1/+2
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-1/+1
2024-04-20Track mutability of deref patternsNadrieril-1/+1
2024-03-27Implement `mut ref`/`mut ref mut`Jules Bertholet-9/+1
2024-03-20Add barest-bones deref patternsNadrieril-0/+1
Co-authored-by: Deadbeef <ent3rm4n@gmail.com>
2024-02-24Add asm label support to THIRGary Guo-0/+1
2024-01-05Remove `thir::Guard`Matthew Jasper-8/+3
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2023-12-26`thir::Visitor` only needs to visit `&'thir` dataNadrieril-12/+27
2023-11-29Add `never_patterns` feature gateNadrieril-1/+1
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-2/+2
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-06Visit patterns in THIR let expressionsMatthew Jasper-1/+2
This fixes some THIR unsafety checking errors not being emitted for let expressions in these situations.
2023-10-16Address review commentsMatthew Jasper-1/+1
Clean up code and add comments. Use InlineConstant to wrap range patterns.
2023-10-16Fix inline const pattern unsafety checking in THIRMatthew Jasper-3/+4
THIR unsafety checking was getting a cycle of function unsafety checking -> building THIR for the function -> evaluating pattern inline constants in the function -> building MIR for the inline constant -> checking unsafety of functions (so that THIR can be stolen) This is fixed by not stealing THIR when generating MIR but instead when unsafety checking. This leaves an issue with pattern inline constants not being unsafety checked because they are evaluated away when generating THIR. To fix that we now represent inline constants in THIR patterns and visit them in THIR unsafety checking.
2023-10-14Propagate pattern errors via a new `PatKind::Error` variantNadrieril-1/+1
Instead of via `Const::new_error`
2023-09-21rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::ConstRalf Jung-3/+3
2023-08-14Move scrutinee `HirId` into `MatchSource::TryDesugar`Esteban Küber-1/+1
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-5/+5
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-0/+1
2023-04-21offset_ofDrMeepster-0/+1
2023-04-03Add Span to StmtKind::Let.Camille GILLOT-0/+1
2023-02-26Move THIR printing to rustc_mir_build.Camille GILLOT-881/+0
2023-01-27address reviewb-naber-7/+7
2023-01-26output tree representation for thir-treeb-naber-0/+881
2022-09-02Use boxed slices in `PatKind`.Nicholas Nethercote-3/+3
To shrink it a little more.
2022-09-02Clean up THIR patterns.Nicholas Nethercote-2/+2
`thir::Pat::kind` is a `Box<PatKind>`, which doesn't follow the usual pattern in AST/HIR/THIR which is that the "kind" enum for a node is stored inline within the parent struct. This commit makes the `PatKind` directly inline within the `Pat`. This requires using `Box<Pat>` in all the types that hold a `Pat. Ideally, `Pat` would be stored in `Thir` like `Expr` and `Stmt` and referred to with a `PatId` rather than `Box<Pat>`. But this is hard to do because lots of `Pat`s get created after the destruction of the `Cx` that does normal THIR building. But this does get us a step closer to `PatId`, because all the `Box<Pat>` occurrences would be replaced with `PatId` if `PatId` ever happened. At 128 bytes, `Pat` is large. Subsequent commits will shrink it.
2022-08-24Rename `thir::Adt` as `thir::AdtExpr`.Nicholas Nethercote-3/+3
This matches the naming scheme used elsewhere, e.g. in the AST, and avoids name clashes with the `ExprKind::Closure` variant.
2022-08-24Box `thir::ExprKind::InlineAsm`.Nicholas Nethercote-2/+2
This shrinks `thir::Expr`.
2022-08-24Box `thir::ExprKind::Closure`.Nicholas Nethercote-2/+9
This shrinks `thir::Expr`.
2022-08-24Store blocks in `Thir`.Nicholas Nethercote-2/+2
Like expressions, statements, and match arms. This shrinks `thir::Stmt` and is a precursor to further shrinking `thir::Expr`.
2022-07-14Rollup merge of #99000 - JulianKnodt:allow_resolve_no_substs, r=lcnrDylan DPC-61/+0
Move abstract const to middle Moves AbstractConst (and all associated methods) to rustc middle for use in `rustc_infer`. This allows for const resolution in infer to use abstract consts to walk consts and check if they are resolvable. This attempts to resolve the issue where `Foo<{ concrete const }, generic T>` is incorrectly marked as conflicting, and is independent from the other issue where nested abstract consts must be resolved. r? `@lcnr`
2022-07-12Move abstract const to rustc_middle::tykadmin-61/+0
2022-07-11lower let-else in MIR insteadDing Xiang Fei-0/+4
2022-07-09don't allow ZST in ScalarIntRalf Jung-0/+1
There are several indications that we should not ZST as a ScalarInt: - We had two ways to have ZST valtrees, either an empty `Branch` or a `Leaf` with a ZST in it. `ValTree::zst()` used the former, but the latter could possibly arise as well. - Likewise, the interpreter had `Immediate::Uninit` and `Immediate::Scalar(Scalar::ZST)`. - LLVM codegen already had to special-case ZST ScalarInt. So instead add new ZST variants to those types that did not have other variants which could be used for this purpose.
2022-07-05impl TypeVisitable in type traversal macrosAlan Egerton-1/+1
2022-05-23Fix precise field capture of univariant enumsTomasz Miąsko-1/+1
When constructing a MIR from a THIR field expression, introduce an additional downcast projection before accessing a field of an enum. When rebasing a place builder on top of a captured place, account for the fact that a single HIR enum field projection corresponds to two MIR projection elements: a downcast element and a field element.
2022-04-14Reimplement lowering of sym operands for asm! so that it also works with ↵Amanieu d'Antras-2/+2
global_asm!
2022-04-06get rid of visit_constant in thir visitorb-naber-2/+8
2022-04-02rebase and use ty::Const in patterns againb-naber-1/+0
2022-04-02do use ty::Const in patterns and abstract constsb-naber-6/+1
2022-04-02change thir to use mir::ConstantKind instead of ty::Constb-naber-1/+10
2022-03-23use NonHirLiteral instead of ScalarLiteral, move pattern related code to ↵b-naber-1/+1
pat_is_poly in IsThirPolymorphic
2022-03-23use ParamConst in ExprKind::ConstParamb-naber-1/+1
2022-03-23remove thir::Visitor::visit_constb-naber-11/+4