about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
AgeCommit message (Collapse)AuthorLines
2024-02-06Auto merge of #120361 - compiler-errors:async-closures, r=oli-obkbors-36/+25
Rework support for async closures; allow them to return futures that borrow from the closure's captures This PR implements a new lowering for async closures via `TyKind::CoroutineClosure` which handles the curious relationship between the closure and the coroutine that it returns. I wrote up a bunch in [this hackmd](https://hackmd.io/`@compiler-errors/S1HvqQxca)` which will be copied to the dev guide after this PR lands, and hopefully left sufficient comments in the source code explaining why this change is as large as it is. This also necessitates that they begin implementing the `AsyncFn`-family of traits, rather than the `Fn`-family of traits -- if you need `Fn` implementations, you should probably use the non-sugar `|| async {}` syntax instead. Notably this PR does not yet implement `async Fn()` syntax sugar for bounds, but I expect to add those soon (**edit:** #120392). For now, users must use `AsyncFn()` traits directly, which necessitates adding the `async_fn_traits` feature gate as well. I will add this as a follow-up very soon. r? oli-obk This is based on top of #120322, but that PR is minimal.
2024-02-06More comments, final tweaksMichael Goulet-0/+3
2024-02-06Teach typeck/borrowck/solvers how to deal with async closuresMichael Goulet-0/+8
2024-02-06Make async closures directly lower to ClosureKind::CoroutineClosureMichael Goulet-32/+9
2024-02-06Make sure that async closures (and fns) only capture their parent callable's ↵Michael Goulet-4/+5
parameters by move, and nothing else
2024-02-06Invert diagnostic lints.Nicholas Nethercote-2/+0
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-02-06Auto merge of #120392 - compiler-errors:async-bound-modifier, r=davidtwco,fmeasebors-21/+128
Introduce support for `async` bound modifier on `Fn*` traits Adds `async` to the list of `TraitBoundModifiers`, which instructs AST lowering to map the trait to an async flavor of the trait. For now, this is only supported for `Fn*` to `AsyncFn*`, and I expect that this manual mapping via lang items will be replaced with a better system in the future. The motivation for adding these bounds is to separate the users of async closures from the exact trait desugaring of their callable bounds. Instead of users needing to be concerned with the `AsyncFn` trait, they should be able to write `async Fn()` and it will desugar to whatever underlying trait we decide is best for the lowering of async closures. Note: rustfmt support can be done in the rustfmt repo after a subtree sync.
2024-02-03hir: Remove the generic type parameter from `MaybeOwned`Vadim Petrochenkov-7/+4
It's only ever used with a reference to `OwnerInfo` as an argument.
2024-02-03hir: Stop keeping prefixes for most of `use` list stemsVadim Petrochenkov-9/+23
And make sure all other imports have non-empty resolution lists.
2024-01-31Error on incorrect item kind in async boundMichael Goulet-9/+35
2024-01-31Add async bound modifier to enable async Fn boundsMichael Goulet-20/+101
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