summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
AgeCommit message (Collapse)AuthorLines
2024-01-29Rollup merge of #120428 - petrochenkov:somehir2, r=compiler-errorsDylan DPC-2/+4
hir: Two preparatory changes for #120206 cc https://github.com/rust-lang/rust/pull/120206 r? ```@compiler-errors```
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-10/+10
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-28hir: Use `InferArg` in `ArrayLen::Infer`Vadim Petrochenkov-1/+4
2024-01-28hir: Remove unnecessary `HirId` from `hir::Let`Vadim Petrochenkov-1/+0
It has 1-to-1 correspondence to its expression id. Also remove mostly useless `visit_let_expr`.
2024-01-25Remove unused featuresclubby789-2/+0
2024-01-19Pack the u128 in LitKind::IntJosh Stone-2/+8
2024-01-19Auto merge of #120006 - cjgillot:no-hir-owner, r=wesleywiserbors-3/+3
Get rid of the hir_owner query. This query was meant as a firewall between `hir_owner_nodes` which is supposed to change often, and the queries that only depend on the item signature. That firewall was inefficient, leaking the contents of the HIR body through `HirId`s. `hir_owner` incurs a significant cost, as we need to hash HIR twice in multiple modes. This PR proposes to remove it, and simplify the hashing scheme. For the future, `def_kind`, `def_span`... are much more efficient for incremental decoupling, and should be preferred.
2024-01-18Rollup merge of #119978 - compiler-errors:async-closure-captures, r=oli-obkMatthias Krüger-202/+215
Move async closure parameters into the resultant closure's future eagerly Move async closure parameters into the closure's resultant future eagerly. Before, we used to desugar `async |p1, p2, ..| { body }` as `|p1, p2, ..| { || async { body } }`. Now, we desugar the above like `|p1, p2, ..| { async move { let p1 = p1; let p2 = p2; ... body } }`. This mirrors the same desugaring that `async fn` does with its parameter types, and the compiler literally uses the same code via a shared helper function. This removes the necessity for E0708, since now expressions like `async |x: i32| { x }` will not give you confusing borrow errors. This does *not* fix the case where async closures have self-borrows. This will come with a general implementation of async closures, which is still in the works. r? oli-obk
2024-01-17Add `PatKind::Err`Lieselotte-0/+1
2024-01-16Simplify BodyId hashing.Camille GILLOT-3/+3
2024-01-16Async closures will move params into the future alwaysMichael Goulet-43/+33
2024-01-16Introduce helper that deals with moving async args into the coroutineMichael Goulet-170/+193
2024-01-13Add check for ui_testing via promoting parameters from `ParseSess` to `Session`George-lewis-13/+8
2024-01-12Delegation implementation: step 1Bryanskiy-4/+386
2024-01-09Add error code for missing base expression in struct update syntaxclubby789-2/+2
2024-01-08Rollup merge of #119705 - fmease:tilde-const-assoc-fns-trait-impls, ↵Matthias Krüger-13/+16
r=compiler-errors Support `~const` in associated functions in trait impls Fixes #119700.
2024-01-07Split note, fix const/static impl trait errorMichael Goulet-5/+10
2024-01-07effects: support ~const in assoc fns in trait implsLeón Orell Valerian Liehr-13/+16
2024-01-07Inline some helpers no longer needed due to RPITIT being stableMichael Goulet-47/+29
2024-01-07Make ImplTraitPosition display more descriptiveMichael Goulet-9/+9
2024-01-05Remove `hir::Guard`Matthew Jasper-14/+1
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2024-01-04Rollup merge of #119540 - fmease:no-effect-args-inside-dyn-trait, ↵Matthias Krüger-13/+15
r=compiler-errors Don't synthesize host effect args inside trait object types While we were indeed emitting an error for `~const` & `const` trait bounds in trait object types, we were still synthesizing host effect args for them. Since we don't record the original trait bound modifiers for dyn-Trait in `hir::TyKind::TraitObject` (unlike we do for let's say impl-Trait, `hir::TyKind::OpaqueTy`), AstConv just assumes `ty::BoundConstness::NotConst` in `conv_object_ty_poly_trait_ref` which given `<host> dyn ~const NonConstTrait` resulted in us not realizing that `~const` was used on a non-const trait which lead to a failed assertion in the end. Instead of updating `hir::TyKind::TraitObject` to track this kind of information, just strip the user-provided constness (similar to #119505). Fixes #119524.
2024-01-03Rollup merge of #119505 - fmease:no-host-param-for-trait-fns, r=fee1-deadLeón Orell Valerian Liehr-4/+6
Don't synthesize host effect params for trait associated functions marked const Fixes #113378. r? fee1-dead or compiler
2024-01-03Rollup merge of #119494 - fmease:deny-hr-param-defaults, r=compiler-errorsLeón Orell Valerian Liehr-32/+42
Deny defaults for higher-ranked generic parameters Fixes #119489 (incl. https://github.com/rust-lang/rust/issues/119489#issuecomment-1873399208). Partially reverts #119042. cc ```@bvanjoi``` r? ```@compiler-errors``` or compiler
2024-01-03Don't synthesize host effect args inside trait object typesLeón Orell Valerian Liehr-13/+15
2024-01-02Don't synthesize host effect params for trait assoc fns marked constLeón Orell Valerian Liehr-4/+6
2024-01-01Deny defaults for higher-ranked generic parametersLeón Orell Valerian Liehr-32/+42
2023-12-30Auto merge of #119284 - Nadrieril:fix-bodiless-arm-parse, r=cjgillotbors-3/+1
Don't drop a hir node after lowering Fixes https://github.com/rust-lang/rust/issues/119271. It seems that all hir nodes that get allocated an id must be placed within the hir on pain of ICEs. In https://github.com/rust-lang/rust/pull/118527 I dropped guards on never patterns since they're not useful, which caused the ICE.
2023-12-28Merge Coroutine lowering functionsArpad Borsos-224/+81
Instead of having separate `make_async/etc_expr` functions, this merges them them into one, reducing code duplication a bit.
2023-12-27Auto merge of #119099 - fmease:always-const-trait-bounds, r=fee1-deadbors-40/+57
Introduce `const Trait` (always-const trait bounds) Feature `const_trait_impl` currently lacks a way to express “always const” trait bounds. This makes it impossible to define generic items like fns or structs which contain types that depend on const method calls (\*). While the final design and esp. the syntax of effects / keyword generics isn't set in stone, some version of “always const” trait bounds will very likely form a part of it. Further, their implementation is trivial thanks to the `effects` backbone. Not sure if this needs t-lang sign-off though. (\*): ```rs #![feature(const_trait_impl, effects, generic_const_exprs)] fn compute<T: const Trait>() -> Type<{ T::generate() }> { /*…*/ } struct Store<T: const Trait> where Type<{ T::generate() }>:, { field: Type<{ T::generate() }>, } ``` Lastly, “always const” trait bounds are a perfect fit for `generic_const_items`. ```rs #![feature(const_trait_impl, effects, generic_const_items)] const DEFAULT<T: const Default>: T = T::default(); ``` Previously, we (oli, fee1-dead and I) wanted to reinterpret `~const Trait` as `const Trait` in generic const items which would've been quite surprising and not very generalizable. Supersedes #117530. --- cc `@oli-obk` As discussed r? fee1-dead (or compiler)
2023-12-27Introduce `const Trait` (always-const trait bounds)León Orell Valerian Liehr-40/+57
2023-12-26Auto merge of #119324 - compiler-errors:rollup-c6eqcg9, r=compiler-errorsbors-7/+9
Rollup of 5 pull requests Successful merges: - #119235 (Add missing feature gate for sanitizer CFI cfgs) - #119240 (Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s) - #119297 (Pass DeadItem and lint as consistent group in dead-code.) - #119307 (Clean up some lifetimes in `rustc_pattern_analysis`) - #119323 (add test for coercing never to infinite type) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-26Rollup merge of #119240 - compiler-errors:lang-item-more, r=petrochenkovMichael Goulet-7/+9
Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s The rest of 'em affect diagnostics, so leave them alone... for now. cc #115178
2023-12-26Don't drop a hir node after loweringNadrieril-3/+1
2023-12-26fallback `default` to `None` during ast-loweing for lifetime binderbohan-2/+30
2023-12-26Auto merge of #119258 - compiler-errors:closure-kind, r=eholkbors-32/+39
Make closures carry their own ClosureKind Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant. This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine". r? eholk
2023-12-26Make some non-diagnostic-affecting QPath::LangItem into regular qpathsMichael Goulet-7/+9
2023-12-25Only regular coroutines have movabilityMichael Goulet-8/+20
2023-12-25Make closures carry their own ClosureKind, rather than deducing what it is ↵Michael Goulet-28/+23
from movability
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-60/+66
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Rollup merge of #119231 - aDotInTheVoid:PatKind-struct-bool-docs, ↵Matthias Krüger-1/+1
r=compiler-errors Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases. See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed. r? ``@compiler-errors``
2023-12-23bool->enum for ast::PatKind::Struct presence of `..`Alona Enraght-Moony-1/+1
See https://github.com/rust-lang/rust/blob/cee794ee98d49b45a55ba225680d98e0c4672736/compiler/rustc_parse/src/parser/pat.rs#L890-L897 for the only place this is constructed.
2023-12-22Rollup merge of #119222 - eholk:into-async-iterator, r=compiler-errors,dtolnayMichael Goulet-1/+19
Add `IntoAsyncIterator` This introduces the `IntoAsyncIterator` trait and uses it in the desugaring of the unstable `for await` loop syntax. This is mostly added for symmetry with `Iterator` and `IntoIterator`. r? `@compiler-errors` cc `@rust-lang/libs-api,` `@rust-lang/wg-async`
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-12/+23
2023-12-22Use `IntoAsyncIterator` in `for await` loop desugaringEric Holk-1/+19
2023-12-22Auto merge of #118847 - eholk:for-await, r=compiler-errorsbors-30/+97
Add support for `for await` loops This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library. Given a loop like: ```rust for await i in iter { ... } ``` this is desugared to something like: ```rust let mut iter = iter.into_async_iter(); while let Some(i) = loop { match core::pin::Pin::new(&mut iter).poll_next(cx) { Poll::Ready(i) => break i, Poll::Pending => yield, } } { ... } ``` This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this. I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue. r? `@compiler-errors`
2023-12-22Auto merge of #119163 - fmease:refactor-ast-trait-bound-modifiers, ↵bors-27/+34
r=compiler-errors Refactor AST trait bound modifiers Instead of having two types to represent trait bound modifiers in the parser / the AST (`parser::ty::BoundModifiers` & `ast::TraitBoundModifier`), only to map one to the other later, just use `parser::ty::BoundModifiers` (moved & renamed to `ast::TraitBoundModifiers`). The struct type is more extensible and easier to deal with (see [here](https://github.com/rust-lang/rust/pull/119099/files#r1430749981) and [here](https://github.com/rust-lang/rust/pull/119099/files#r1430752116) for context) since it more closely models what it represents: A compound of two kinds of modifiers, constness and polarity. Modeling this as an enum (the now removed `ast::TraitBoundModifier`) meant one had to add a new variant per *combination* of modifier kind, which simply isn't scalable and which lead to a lot of explicit non-DRY matches. NB: `hir::TraitBoundModifier` being an enum is fine since HIR doesn't need to worry representing invalid modifier kind combinations as those get rejected during AST validation thereby immensely cutting down the number of possibilities.
2023-12-20Rollup merge of #119145 - aDotInTheVoid:variantdata-struct-struct, ↵Matthias Krüger-4/+5
r=compiler-errors Give `VariantData::Struct` named fields, to clairfy `recovered`. Implements https://github.com/rust-lang/rust/pull/119121#discussion_r1431467066. Supersedes #119121 This way, it's clear what the bool fields means, instead of having to find where it's generated. Changes both ast and hir. r? `@compiler-errors`
2023-12-20Refactor AST trait bound modifiersLeón Orell Valerian Liehr-27/+34
2023-12-20resolve: Eagerly feed closure visibilitiesVadim Petrochenkov-5/+1
Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`