about summary refs log tree commit diff
path: root/compiler/rustc_ast_passes
AgeCommit message (Collapse)AuthorLines
2023-12-22Auto merge of #118847 - eholk:for-await, r=compiler-errorsbors-0/+1
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-21/+23
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-21Rollup merge of #119154 - surechen:fix_119067, r=fmeaseMatthias Krüger-8/+9
Simple modification of `non_lifetime_binders`'s diagnostic information to adapt to type binders fixes #119067 Replace diagnostic information "lifetime bounds cannot be used in this context" to "bounds cannot be used in this context". ```rust #![allow(incomplete_features)] #![feature(non_lifetime_binders)] trait Trait {} trait Trait2 where for <T: Trait> ():{} //~^ ERROR bounds cannot be used in this context ```
2023-12-21Simple modification of diagnostic informationsurechen-8/+9
fixes #119067
2023-12-20Refactor AST trait bound modifiersLeón Orell Valerian Liehr-21/+23
2023-12-20Give `VariantData::Struct` named fields, to clairfy `recovered`.Alona Enraght-Moony-2/+2
2023-12-19Plumb awaitness of for loopsEric Holk-0/+1
2023-12-18Auto merge of #117818 - fmease:properly-reject-defaultness-on-free-consts, ↵bors-5/+7
r=cjgillot Properly reject `default` on free const items Fixes #117791. Technically speaking, this is a breaking change but I doubt it will lead to any real-world regressions (maybe in some macro-trickery crates?). Doing a crater run probably isn't worth it.
2023-12-18Auto merge of #119069 - matthiaskrgr:rollup-xxk4m30, r=matthiaskrgrbors-3/+17
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-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-2/+2
2023-12-18Rename `ShowSpanVisitor::span_diagnostic` as `ShowSpanVisitor::dcx`.Nicholas Nethercote-6/+6
2023-12-18Rename `AstValidator::err_handler` as `AstValidator::dcx`.Nicholas Nethercote-41/+38
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-3/+3
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-4/+4
2023-12-18Deny ~const trait bounds in inherent impl headersLeón Orell Valerian Liehr-3/+17
2023-12-12Correctly gate the parsing of match arms without bodyNadrieril-1/+41
2023-12-10remove redundant importssurechen-2/+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-08Rename some more coro_kind -> coroutine_kindMichael Goulet-2/+2
2023-12-08Make some matches exhaustive to avoid bugs, fix toolsMichael Goulet-5/+6
2023-12-08coro_kind -> coroutine_kindMichael Goulet-1/+1
2023-12-04Address code review feedbackEric Holk-1/+1
2023-12-04Option<CoroutineKind>Eric Holk-2/+7
2023-12-04Merge Async and Gen into CoroutineKindEric Holk-1/+1
2023-12-02Auto merge of #118470 - nnethercote:cleanup-error-handlers, r=compiler-errorsbors-2/+2
Cleanup error handlers Mostly by making function naming more consistent. More to do after this, but this is enough for one PR. r? compiler-errors
2023-12-02Use `Session::diagnostic` in more places.Nicholas Nethercote-2/+2
2023-12-02Rename `HandlerInner::delay_span_bug` as `HandlerInner::span_delayed_bug`.Nicholas Nethercote-1/+1
Because the corresponding `Level` is `DelayedBug` and `span_delayed_bug` follows the pattern used everywhere else: `span_err`, `span_warning`, etc.
2023-12-01Auto merge of #117472 - jmillikin:stable-c-str-literals, r=Nilstriebbors-1/+0
Stabilize C string literals RFC: https://rust-lang.github.io/rfcs/3348-c-str-literal.html Tracking issue: https://github.com/rust-lang/rust/issues/105723 Documentation PR (reference manual): https://github.com/rust-lang/reference/pull/1423 # Stabilization report Stabilizes C string and raw C string literals (`c"..."` and `cr#"..."#`), which are expressions of type [`&CStr`](https://doc.rust-lang.org/stable/core/ffi/struct.CStr.html). Both new literals require Rust edition 2021 or later. ```rust const HELLO: &core::ffi::CStr = c"Hello, world!"; ``` C strings may contain any byte other than `NUL` (`b'\x00'`), and their in-memory representation is guaranteed to end with `NUL`. ## Implementation Originally implemented by PR https://github.com/rust-lang/rust/pull/108801, which was reverted due to unintentional changes to lexer behavior in Rust editions < 2021. The current implementation landed in PR https://github.com/rust-lang/rust/pull/113476, which restricts C string literals to Rust edition >= 2021. ## Resolutions to open questions from the RFC * Adding C character literals (`c'.'`) of type `c_char` is not part of this feature. * Support for `c"..."` literals does not prevent `c'.'` literals from being added in the future. * C string literals should not be blocked on making `&CStr` a thin pointer. * It's possible to declare constant expressions of type `&'static CStr` in stable Rust (as of v1.59), so C string literals are not adding additional coupling on the internal representation of `CStr`. * The unstable `concat_bytes!` macro should not accept `c"..."` literals. * C strings have two equally valid `&[u8]` representations (with or without terminal `NUL`), so allowing them to be used in `concat_bytes!` would be ambiguous. * Adding a type to represent C strings containing valid UTF-8 is not part of this feature. * Support for a hypothetical `&Utf8CStr` may be explored in the future, should such a type be added to Rust.
2023-11-29Add `never_patterns` feature gateNadrieril-0/+1
2023-11-26Use `rustc_fluent_macro::fluent_messages!` directly.Nicholas Nethercote-3/+1
Currently we always do this: ``` use rustc_fluent_macro::fluent_messages; ... fluent_messages! { "./example.ftl" } ``` But there is no need, we can just do this everywhere: ``` rustc_fluent_macro::fluent_messages! { "./example.ftl" } ``` which is shorter.
2023-11-26Avoid need for `{D,Subd}iagnosticMessage` imports.Nicholas Nethercote-1/+0
The `fluent_messages!` macro produces uses of `crate::{D,Subd}iagnosticMessage`, which means that every crate using the macro must have this import: ``` use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; ``` This commit changes the macro to instead use `rustc_errors::{D,Subd}iagnosticMessage`, which avoids the need for the imports.
2023-11-24Add `Span` to `TraitBoundModifier`Deadbeef-3/+2
2023-11-22Auto merge of #117928 - nnethercote:rustc_ast_pretty, r=fee1-deadbors-1/+1
`rustc_ast_pretty` cleanups Some improvements I found while looking at this code. r? `@fee1-dead`
2023-11-22Update itertools to 0.11.Nicholas Nethercote-1/+1
Because the API for `with_position` improved in 0.11 and I want to use it.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-6/+6
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-15Re-format code with new rustfmtMark Rousskov-10/+8
2023-11-15Bump cfg(bootstrap)sMark Rousskov-3/+3
2023-11-12Auto merge of #117817 - fmease:deny-more-tilde-const, r=fee1-deadbors-48/+48
Deny more `~const` trait bounds thereby fixing a family of ICEs (delayed bugs) for `feature(const_trait_impl, effects)` code. As discussed r? `@fee1-dead`
2023-11-12Deny more `~const` trait boundsLeón Orell Valerian Liehr-48/+48
2023-11-11Reject defaultness on free constsLeón Orell Valerian Liehr-5/+7
2023-11-01Stabilize C string literalsJohn Millikin-1/+0
2023-10-31Test the multispan case in `tests.ui/bounds-lifetime.rs`.Nicholas Nethercote-1/+1
2023-10-31Fix a `FIXME`, by adding a `gate_multi` macro.Nicholas Nethercote-18/+24
Note that this adds the `span.allows_unstable` checking that this case previously lacked.
2023-10-31Rearrange the `gate_feature_*` macros.Nicholas Nethercote-60/+58
2023-10-31Use `if let` to reduce some excessive indentation.Nicholas Nethercote-53/+45
2023-10-31Use a slice pattern to neaten a condition.Nicholas Nethercote-8/+3
2023-10-31Cover two more cases in the `gate_doc` macro.Nicholas Nethercote-18/+14
2023-10-31Streamline `gate_feature_*` macros.Nicholas Nethercote-31/+14
The debug probably isn't useful, and assigning all the `$foo` metavariables to `foo` variables is verbose and weird. Also, `$x:expr` usually doesn't have a space after the `:`.
2023-10-30Rollup merge of #117370 - nicholasbishop:bishop-better-c-variadic-errors, ↵Guillaume Gomez-8/+46
r=oli-obk C-variadic error improvements A couple improvements for c-variadic errors: 1. Fix the bad-c-variadic error being emitted multiple times. If a function incorrectly contains multiple `...` args, and is also not foreign or `unsafe extern "C"`, only emit the latter error once rather than once per `...`. 2. Explicitly reject `const` C-variadic functions. Trying to use C-variadics in a const function would previously fail with an error like "destructor of `VaListImpl<'_>` cannot be evaluated at compile-time". Add an explicit check for const C-variadics to provide a clearer error: "functions cannot be both `const` and C-variadic". This also addresses one of the concerns in https://github.com/rust-lang/rust/issues/44930: "Ensure that even when this gets stabilized for regular functions, it is still rejected on const fn."
2023-10-30Explicitly reject const C-variadic functionsNicholas Bishop-2/+32
Trying to use C-variadics in a const function would previously fail with an error like "destructor of `VaListImpl<'_>` cannot be evaluated at compile-time". Add an explicit check for const C-variadics to provide a clearer error: "functions cannot be both `const` and C-variadic".
2023-10-30Fix bad-c-variadic error being emitted multiple timesNicholas Bishop-6/+14
If a function incorrectly contains multiple `...` args, and is also not foreign or `unsafe extern "C"`, only emit the latter error once.