about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src/expr.rs
AgeCommit message (Collapse)AuthorLines
2024-02-15Rollup merge of #121120 - nnethercote:LitKind-Err-guar, r=fmeaseGuillaume Gomez-2/+7
Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`. Similar to recent work doing the same for `ExprKind::Err` (#120586) and `TyKind::Err` (#121109). r? `@oli-obk`
2024-02-15Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.Nicholas Nethercote-2/+7
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
2024-02-15Reinstate some delayed bugs.Nicholas Nethercote-1/+3
These were changed to `has_errors` assertions in #121071 because that seemed reasonable, but evidently not. Fixes #121103. Fixes #121108.
2024-02-14Use fewer delayed bugs.Nicholas Nethercote-3/+1
For some cases where it's clear that an error has already occurred, e.g.: - there's a comment stating exactly that, or - things like HIR lowering, where we are lowering an error kind The commit also tweaks some comments around delayed bug sites.
2024-02-07No need to take ImplTraitContext by refMichael Goulet-9/+9
2024-02-06Auto merge of #120361 - compiler-errors:async-closures, r=oli-obkbors-20/+18
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-20/+7
2024-01-31Add async bound modifier to enable async Fn boundsMichael Goulet-0/+2
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-19Pack the u128 in LitKind::IntJosh Stone-2/+8
2024-01-16Async closures will move params into the future alwaysMichael Goulet-24/+15
2024-01-13Add check for ui_testing via promoting parameters from `ParseSess` to `Session`George-lewis-2/+2
2024-01-05Remove `hir::Guard`Matthew Jasper-14/+1
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
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-198/+68
Instead of having separate `make_async/etc_expr` functions, this merges them them into one, reducing code duplication a bit.
2023-12-26Rollup merge of #119240 - compiler-errors:lang-item-more, r=petrochenkovMichael Goulet-6/+4
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-26Auto merge of #119258 - compiler-errors:closure-kind, r=eholkbors-27/+38
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-6/+4
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-23/+22
from movability
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-17/+16
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
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/+95
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-19Desugar for await loopsEric Holk-28/+92
2023-12-19Plumb awaitness of for loopsEric Holk-4/+5
2023-12-18Ensure `yield` expressions desugar correctly in async generatorsMichael Goulet-20/+32
2023-12-15NFC don't convert types to identical typesMatthias Krüger-3/+1
2023-12-13Rollup merge of #118759 - compiler-errors:bare-unit-structs, r=petrochenkovMatthias Krüger-0/+2
Support bare unit structs in destructuring assignments We should be allowed to use destructuring assignments on *bare* unit structs, not just unit structs that are located within other pattern constructors. Fixes #118753 r? petrochenkov since you reviewed #95380, reassign if you're busy or don't want to review this.
2023-12-12Correctly gate the parsing of match arms without bodyNadrieril-2/+5
2023-12-10remove redundant importssurechen-1/+0
detects redundant imports that can be eliminated. for #117772 : In order to facilitate review and modification, split the checking code and removing redundant imports code into two PR.
2023-12-09Lower some forgotten coroutine spansMichael Goulet-2/+2
2023-12-08Support bare unit structs in destructuring assignmentsMichael Goulet-0/+2
2023-12-08Auto merge of #118420 - compiler-errors:async-gen, r=eholkbors-22/+139
Introduce support for `async gen` blocks I'm delighted to demonstrate that `async gen` block are not very difficult to support. They're simply coroutines that yield `Poll<Option<T>>` and return `()`. **This PR is WIP and in draft mode for now** -- I'm mostly putting it up to show folks that it's possible. This PR needs a lang-team experiment associated with it or possible an RFC, since I don't think it falls under the jurisdiction of the `gen` RFC that was recently authored by oli (https://github.com/rust-lang/rfcs/pull/3513, https://github.com/rust-lang/rust/issues/117078). ### Technical note on the pre-generator-transform yield type: The reason that the underlying coroutines yield `Poll<Option<T>>` and not `Poll<T>` (which would make more sense, IMO, for the pre-transformed coroutine), is because the `TransformVisitor` that is used to turn coroutines into built-in state machine functions would have to destructure and reconstruct the latter into the former, which requires at least inserting a new basic block (for a `switchInt` terminator, to match on the `Poll` discriminant). This does mean that the desugaring (at the `rustc_ast_lowering` level) of `async gen` blocks is a bit more involved. However, since we already need to intercept both `.await` and `yield` operators, I don't consider it much of a technical burden. r? `@ghost`
2023-12-08Support async gen fnMichael Goulet-7/+9
2023-12-08coro_kind -> coroutine_kindMichael Goulet-2/+2
2023-12-08Implement `async gen` blocksMichael Goulet-13/+128
2023-12-08Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errorsbors-10/+40
never_patterns: Parse match arms with no body Never patterns are meant to signal unreachable cases, and thus don't take bodies: ```rust let ptr: *const Option<!> = ...; match *ptr { None => { foo(); } Some(!), } ``` This PR makes rustc accept the above, and enforces that an arm has a body xor is a never pattern. This affects parsing of match arms even with the feature off, so this is delicate. (Plus this is my first non-trivial change to the parser). ~~The last commit is optional; it introduces a bit of churn to allow the new suggestions to be machine-applicable. There may be a better solution? I'm not sure.~~ EDIT: I removed that commit r? `@compiler-errors`
2023-12-04Option<CoroutineKind>Eric Holk-17/+8
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-31/+40
2023-12-03rustc: Harmonize `DefKind` and `DefPathData`Vadim Petrochenkov-3/+2
`DefPathData::(ClosureExpr,ImplTrait)` are renamed to match `DefKind::(Closure,OpaqueTy)`. `DefPathData::ImplTraitAssocTy` is replaced with `DefPathData::TypeNS(kw::Empty)` because both correspond to `DefKind::AssocTy`. It's possible that introducing `(DefKind,DefPathData)::AssocOpaqueTy` could be a better solution, but that would be a much more invasive change. Const generic parameters introduced for effects are moved from `DefPathData::TypeNS` to `DefPathData::ValueNS`, because constants are values. `DefPathData` is no longer passed to `create_def` functions to avoid redundancy.
2023-12-03Disallow arm bodies on never patternsNadrieril-8/+13
2023-12-03Disallow guards on never patternsNadrieril-2/+5
2023-12-03Disallow an arm without a body (except for never patterns)Nadrieril-3/+10
Parsing now accepts a match arm without a body, so we must make sure to only accept that if the pattern is a never pattern.
2023-12-03Parse a pattern with no armNadrieril-7/+22
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-2/+2
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.