about summary refs log tree commit diff
path: root/compiler/rustc_ast_lowering/src
AgeCommit message (Collapse)AuthorLines
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`
2023-12-20Give `VariantData::Struct` named fields, to clairfy `recovered`.Alona Enraght-Moony-4/+5
2023-12-19Desugar for await loopsEric Holk-28/+94
2023-12-19Plumb awaitness of for loopsEric Holk-4/+5
2023-12-19Auto merge of #119093 - michaelwoerister:mcp533-18, r=petrochenkovbors-15/+14
Replace some instances of FxHashMap/FxHashSet with stable alternatives (mostly in rustc_hir and rustc_ast_lowering) Part of https://github.com/rust-lang/compiler-team/issues/533. We should be getting close to being able to remove the HashStable impl of HashMap.
2023-12-19Auto merge of #119061 - compiler-errors:async-gen-abi, r=wesleywiserbors-20/+32
Desugar `yield` in `async gen` correctly, ensure `gen` always returns unit 1. Ensure `async gen` blocks desugar `yield $expr` to `task_context = yield async_gen_ready($expr)`. Previously we were not assigning the `task_context` correctly, meaning that `yield` expressions in async generators returned type `ResumeTy` instead of `()`, and that we were not storing the `task_context` (which is probably unsound if we were reading the old task-context which has an invalidated borrow or something...) 2. Ensure that all `(async?) gen` blocks and `(async?) gen` fns return unit. Previously we were only checking this for `gen fn`, meaning that `gen {}` and `async gen {}` and `async gen fn` were allowed to return values that weren't unit. This is why #119058 was an ICE rather than an E0308. Fixes #119058.
2023-12-18Replace some instances of FxHashMap/FxHashSet with stable alternatives ↵Michael Woerister-15/+14
(mostly in rustc_hir and rustc_ast_lowering) Part of https://github.com/rust-lang/compiler-team/issues/533
2023-12-18Auto merge of #119069 - matthiaskrgr:rollup-xxk4m30, r=matthiaskrgrbors-1/+4
Rollup of 5 pull requests Successful merges: - #118852 (coverage: Skip instrumenting a function if no spans were extracted from MIR) - #118905 ([AIX] Fix XCOFF metadata) - #118967 (Add better ICE messages for some undescriptive panics) - #119051 (Replace `FileAllocationInfo` with `FileEndOfFileInfo`) - #119059 (Deny `~const` trait bounds in inherent impl headers) r? `@ghost` `@rustbot` modify labels: rollup
2023-12-18Rollup merge of #118967 - RossSmyth:panic-messages, r=TaKO8KiMatthias Krüger-1/+4
Add better ICE messages for some undescriptive panics Add some better messages at some panics re: #118955 I took a look at some others but either was not able to figure out what they did, or it was unclear what they should say instead. For example in the query system whether each time a poisoned value is matched upon if they should all just call `FatalError.raise()`
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-1/+1
2023-12-18Ensure `yield` expressions desugar correctly in async generatorsMichael Goulet-20/+32
2023-12-18resolve: Replace visibility table in resolver outputs with query feedingVadim Petrochenkov-4/+6
Also feed missing visibilities for import stems and trait impl items, which were previously evaluated lazily.
2023-12-15Rollup merge of #119004 - matthiaskrgr:conv, r=compiler-errorsJubilee-3/+1
NFC don't convert types to identical types
2023-12-15NFC don't convert types to identical typesMatthias Krüger-3/+1
2023-12-15Rollup merge of #118396 - compiler-errors:ast-lang-items, r=cjgillotJubilee-6/+38
Collect lang items from AST, get rid of `GenericBound::LangItemTrait` r? `@cjgillot` cc #115178 Looking forward, the work to remove `QPath::LangItem` will also be significantly more difficult, but I plan on doing it as well. Specifically, we have to change: 1. A lot of `rustc_ast_lowering` for things like expr `..` 2. A lot of astconv, since we actually instantiate lang and non-lang paths quite differently. 3. A ton of diagnostics and clippy lints that are special-cased via `QPath::LangItem` Meanwhile, it was pretty easy to remove `GenericBound::LangItemTrait`, so I just did that here.
2023-12-15banish hir::GenericBound::LangItemTraitMichael Goulet-6/+37
2023-12-15Collect lang items from ASTMichael Goulet-0/+1
2023-12-15Annotate some more bugsMichael Goulet-4/+9
2023-12-15Add better ICE messages for some undescriptive panicsRoss Smyth-1/+4
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-10Auto merge of #116952 - compiler-errors:lifetime_capture_rules_2024, r=TaKO8Kibors-2/+5
Implement 2024-edition lifetime capture rules RFC Implements rust-lang/rfcs#3498.
2023-12-10remove redundant importssurechen-4/+2
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-09Rollup merge of #118766 - compiler-errors:lower-spans, r=spastorinoGuillaume Gomez-5/+6
Lower some forgotten spans I wrote a HIR visitor that visited all of the spans in the HIR, and made it ICE when we have a unlowered span. That led me to discover these unlowered spans.
2023-12-09Lower some forgotten coroutine spansMichael Goulet-2/+2
2023-12-09Lower spans for opaque duplicated lifetimes, const infer varsMichael Goulet-3/+3
2023-12-09Lower constness span in host paramMichael Goulet-0/+1
2023-12-08More nitsMichael Goulet-1/+2
2023-12-08Introduce closure_id method on CoroutineKindMichael Goulet-4/+1
2023-12-08Support bare unit structs in destructuring assignmentsMichael Goulet-0/+2
2023-12-08Auto merge of #118420 - compiler-errors:async-gen, r=eholkbors-52/+192
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-08Add testsMichael Goulet-9/+16
2023-12-08Make some matches exhaustive to avoid bugs, fix toolsMichael Goulet-0/+1
2023-12-08Support async gen fnMichael Goulet-16/+26
2023-12-08coro_kind -> coroutine_kindMichael Goulet-17/+24
2023-12-08Implement `async gen` blocksMichael Goulet-13/+128
2023-12-08Auto merge of #118527 - Nadrieril:never_patterns_parse, r=compiler-errorsbors-10/+66
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-06Auto merge of #118605 - fee1-dead-contrib:rm-rustc_host, r=compiler-errorsbors-49/+18
Remove `#[rustc_host]`, use internal desugaring Also removed a way for users to explicitly specify the host param since that isn't particularly useful. This should eliminate any pain with encoding attributes across crates and etc. r? `@compiler-errors`
2023-12-05Enable new capture rules by default on edition 2024Michael Goulet-0/+1
2023-12-05Add lifetime_capture_rules_2024Michael Goulet-2/+4
2023-12-05Remove `#[rustc_host]`, use internal desugaringDeadbeef-49/+18
2023-12-04Address code review feedbackEric Holk-10/+10
2023-12-04Fix some broken testsEric Holk-1/+1
2023-12-04Option<CoroutineKind>Eric Holk-43/+23
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-124/+93
2023-12-04Lower return types for gen fn to impl IteratorEric Holk-72/+158