summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
AgeCommit message (Collapse)AuthorLines
2025-01-01Fix ICE when opaque captures a duplicated/invalid lifetimeMichael Goulet-2/+2
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-21/+10
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-16Rollup merge of #134284 - estebank:issue-74863, r=lcnrMatthias Krüger-1/+8
Keep track of patterns that could have introduced a binding, but didn't When we recover from a pattern parse error, or a pattern uses `..`, we keep track of that and affect resolution error for missing bindings that could have been provided by that pattern. We differentiate between `..` and parse recovery. We silence resolution errors likely caused by the pattern parse error. ``` error[E0425]: cannot find value `title` in this scope --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:18:30 | LL | if let Website { url, .. } = website { | ------------------- this pattern doesn't include `title`, which is available in `Website` LL | println!("[{}]({})", title, url); | ^^^^^ not found in this scope ``` Fix #74863.
2024-12-15Add hir::AttributeJonathan Dönszelmann-22/+28
2024-12-15Rename `value` field to `expr` to simplify later commits' diffsOli Scherer-3/+3
2024-12-14(Re-)Implement impl_trait_in_bindingsMichael Goulet-4/+25
2024-12-13Keep track of patterns that could have introduced a binding, but didn'tEsteban Küber-1/+8
When we recover from a pattern parse error, or a pattern uses `..`, we keep track of that and affect resolution error for missing bindings that could have been provided by that pattern. We differentiate between `..` and parse recovery. We silence resolution errors likely caused by the pattern parse error. ``` error[E0425]: cannot find value `title` in this scope --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:19:30 | LL | println!("[{}]({})", title, url); | ^^^^^ not found in this scope | note: `Website` has a field `title` which could have been included in this pattern, but it wasn't --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:17:12 | LL | / struct Website { LL | | url: String, LL | | title: Option<String> , | | ----- defined here LL | | } | |_- ... LL | if let Website { url, .. } = website { | ^^^^^^^^^^^^^^^^^^^ this pattern doesn't include `title`, which is available in `Website` ``` Fix #74863.
2024-12-13Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obkMatthias Krüger-0/+15
Add AST support for unsafe binders I'm splitting up #130514 into pieces. It's impossible for me to keep up with a huge PR like that. I'll land type system support for this next, probably w/o MIR lowering, which will come later. r? `@oli-obk` cc `@BoxyUwU` and `@lcnr` who also may want to look at this, though this PR doesn't do too much yet
2024-12-12Add unwrap_unsafe_binder and wrap_unsafe_binder macro operatorsMichael Goulet-0/+8
2024-12-12Lower AST and resolve lifetimes for unsafe binder typesMichael Goulet-0/+7
2024-12-10Keep track of parse errors in `mod`s and don't emit resolve errors for paths ↵Esteban Küber-1/+1
involving them When we expand a `mod foo;` and parse `foo.rs`, we now track whether that file had an unrecovered parse error that reached the end of the file. If so, we keep that information around. When resolving a path like `foo::bar`, we do not emit any errors for "`bar` not found in `foo`", as we know that the parse error might have caused `bar` to not be parsed and accounted for. When this happens in an existing project, every path referencing `foo` would be an irrelevant compile error. Instead, we now skip emitting anything until `foo.rs` is fixed. Tellingly enough, we didn't have any test for errors caused by `mod` expansion. Fix #97734.
2024-12-09Detect `struct S(ty = val);`Esteban Küber-8/+33
Emit a specific error for unsupported default field value syntax in tuple structs.
2024-12-09Introduce `default_field_values` featureEsteban Küber-19/+9
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-08Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-deadMatthias Krüger-0/+2
Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](https://github.com/rust-lang/rust/issues/129967)). This PR is extracted from https://github.com/rust-lang/rust/pull/129996 with minor modifications. cc `@max-niederman`
2024-12-03Rollup merge of #133779 - BoxyUwU:array_const_arg_infer_hir_id, ↵Matthias Krüger-1/+2
r=compiler-errors Use correct `hir_id` for array const arg infers Fixes #133771 `self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by #133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node. This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :< cc #133589 `@voidc` r? `@compiler-errors` `@lcnr`
2024-12-03Use correct `hir_id` for array const arg infersBoxy-1/+2
2024-12-02Rollup merge of #133746 - oli-obk:push-xwyrylxmrtvq, r=jieyouxuGuillaume Gomez-5/+3
Change `AttrArgs::Eq` to a struct variant Cleanups for simplifying https://github.com/rust-lang/rust/pull/131808 Basically changes `AttrArgs::Eq` to a struct variant and then avoids several matches on `AttrArgsEq` in favor of methods on it. This will make future refactorings simpler, as they can either keep methods or switch to field accesses without having to restructure code
2024-12-02Deduplicate some matches that always panic in one armOli Scherer-4/+2
2024-12-02Change `AttrArgs::Eq` into a struct variantOli Scherer-3/+3
2024-12-01Rollup merge of #133589 - voidc:remove-array-len, r=boxyuwuJacob Pratt-22/+12
Remove `hir::ArrayLen` This refactoring removes `hir::ArrayLen`, replacing it with `hir::ConstArg`. To represent inferred array lengths (previously `hir::ArrayLen::Infer`), a new variant `ConstArgKind::Infer` is added. r? `@BoxyUwU`
2024-11-30Remove hir::ArrayLen, introduce ConstArgKind::InferDominik Stolz-22/+12
Remove Node::ArrayLenInfer
2024-11-28Auto merge of #133468 - lcnr:uwu4, r=BoxyUwUbors-128/+74
always create `DefId`s for anon consts but don't use them anywhere, we intentionally don't encode them in the crate metadata. best reviewed by disabling whitespace. This pretty much reimplements #133285 while adding the tests of #133455. Fixes #133064 r? `@BoxyUwU` `@compiler-errors`
2024-11-28ast_lowering: rm separate `def_id_parent`lcnr-96/+62
no longer necessary as we now always create a ` DefId` for anon-consts
2024-11-28always create `DefId`s when lowering anon-constslcnr-32/+12
2024-11-28Rollup merge of #133422 - taiki-e:riscv-e-clobber-abi, r=AmanieuGuillaume Gomez-1/+6
Fix clobber_abi in RV32E and RV64E inline assembly Currently clobber_abi in RV32E and RV64E inline assembly is implemented using InlineAsmClobberAbi::RiscV, but broken since x16-x31 cannot be used in RV32E and RV64E. ``` error: cannot use register `x16`: register can't be used with the `e` target feature --> <source>:42:14 | 42 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ error: cannot use register `x17`: register can't be used with the `e` target feature --> <source>:42:14 | 42 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ error: cannot use register `x28`: register can't be used with the `e` target feature --> <source>:42:14 | 42 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ error: cannot use register `x29`: register can't be used with the `e` target feature --> <source>:42:14 | 42 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ error: cannot use register `x30`: register can't be used with the `e` target feature --> <source>:42:14 | 42 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ error: cannot use register `x31`: register can't be used with the `e` target feature --> <source>:42:14 | 42 | asm!("", clobber_abi("C"), options(nostack, nomem, preserves_flags)); | ^^^^^^^^^^^^^^^^ ``` r? `@Amanieu` `@rustbot` label O-riscv +A-inline-assembly
2024-11-26Rollup merge of #133443 - fmease:rm-dead-eff-code-ii, r=compiler-errorsGuillaume Gomez-15/+3
Remove dead code stemming from the old effects desugaring (II) Follow-up to #132374. r? project-const-traits
2024-11-26Auto merge of #132894 - frank-king:feature/where-refactor, r=cjgillotbors-34/+25
Refactor `where` predicates, and reserve for attributes support Refactor `WherePredicate` to `WherePredicateKind`, and reserve for attributes support in `where` predicates. This is a part of #115590 and is split from #132388. r? petrochenkov
2024-11-25Remove dead code stemming from the old effects desugaring (II)León Orell Valerian Liehr-15/+3
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-34/+25
2024-11-25Rollup merge of #131664 - taiki-e:s390x-asm-vreg-inout, r=AmanieuMatthias Krüger-6/+34
Support input/output in vector registers of s390x inline assembly (under asm_experimental_reg feature) This extends currently clobber-only vector registers (`vreg`) support to allow passing `#[repr(simd)]` types, floats (f32/f64/f128), and integers (i32/i64/i128) as input/output. This is unstable and gated under new `#![feature(asm_experimental_reg)]` (tracking issue: https://github.com/rust-lang/rust/issues/133416). If the feature is not enabled, only clober is supported as before. | Architecture | Register class | Target feature | Allowed types | | ------------ | -------------- | -------------- | -------------- | | s390x | `vreg` | `vector` | `i32`, `f32`, `i64`, `f64`, `i128`, `f128`, `i8x16`, `i16x8`, `i32x4`, `i64x2`, `f32x4`, `f64x2` | This matches the list of types that are supported by the vector registers in LLVM: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/SystemZ/SystemZRegisterInfo.td#L301-L313 In addition to `core::simd` types and floats listed above, custom `#[repr(simd)]` types of the same size and type are also allowed. All allowed types other than i32/f32/i64/f64/i128, and relevant target features are currently unstable. Currently there is no SIMD type for s390x in `core::arch`, but this is tracked in https://github.com/rust-lang/rust/issues/130869. cc https://github.com/rust-lang/rust/issues/130869 about vector facility support in s390x cc https://github.com/rust-lang/rust/issues/125398 & https://github.com/rust-lang/rust/issues/116909 about f128 support in asm `@rustbot` label +O-SystemZ +A-inline-assembly
2024-11-24add guard pattern AST nodeMax Niederman-0/+2
2024-11-25Fix clobber_abi in RV32E and RV64E inline assemblyTaiki Endo-1/+6
2024-11-24Make asm_goto_with_outputs a separate feature gateGary Guo-9/+35
2024-11-24Make s390x non-clobber-only vector register support unstableTaiki Endo-6/+34
2024-11-21Implement the unsafe-fields RFC.Luca Versari-0/+1
Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
2024-11-19Introduce `min_generic_const_args` and directly represent pathsNoah Lev-48/+60
Co-authored-by: Boxy UwU <rust@boxyuwu.dev> Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-11-16Auto merge of #130443 - veluca93:legacy-const-generics-fix, r=BoxyUwUbors-3/+90
Fix ICE when passing DefId-creating args to legacy_const_generics. r? BoxyUwU Fixes #123077 Fixes #129150
2024-11-16Fix ICE when passing DefId-creating args to legacy_const_generics.Luca Versari-3/+90
2024-11-15Fix span edition for 2024 RPIT coming from an external macroEric Huss-1/+1
This fixes a problem where code generated by an external macro with an RPIT would end up using the call-site edition instead of the macro's edition for the RPIT. When used from a 2024 crate, this caused the code to change behavior to the 2024 capturing rules, which we don't want. This was caused by the impl-trait lowering code would replace the span with one marked with `DesugaringKind::OpaqueTy` desugaring. However, it was also overriding the edition of the span with the edition of the local crate. Instead it should be using the edition of the span itself. Fixes https://github.com/rust-lang/rust/issues/132917
2024-11-10Stabilize Arm64EC inline assemblyTaiki Endo-0/+1
2024-11-08Stabilize s390x inline assemblyTaiki Endo-0/+1
2024-10-31Encode cross-crate opaque type originMichael Goulet-3/+3
2024-10-30Review comments.Camille GILLOT-151/+0
2024-10-30Remap impl-trait lifetimes on HIR instead of AST lowering.Camille GILLOT-246/+9
2024-10-29Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillotJubilee-12/+13
compiler: apply clippy::clone_on_ref_ptr for CI Apply lint https://rust-lang.github.io/rust-clippy/master/index.html#/clone_on_ref_ptr for compiler, also see https://github.com/rust-lang/rust/pull/131225#discussion_r1790109443. Some Arc's can be misplaced with Lrc's, sorry. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/enable.20more.20clippy.20lints.20for.20compiler.20.28and.5Cor.20std.29
2024-10-28fix clippy::clone_on_ref_ptr for compilerklensy-12/+13
2024-10-28more consistent debug_assertionsAdwin White-15/+32
2024-10-28Add duplicate lowering checkAdwin White-38/+38
2024-10-28Lower AST node id only onceAdwin White-108/+161
2024-10-27Move an impl-Trait check from AST validation to AST loweringLeón Orell Valerian Liehr-3/+16