about summary refs log tree commit diff
path: root/compiler/rustc_ast/src
AgeCommit message (Collapse)AuthorLines
2024-05-17Auto merge of #123865 - eholk:expr_2021, r=fmeasebors-0/+4
Update `expr` matcher for Edition 2024 and add `expr_2021` nonterminal This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag. This change also updates `expr` so that on Edition 2024 it will also match `const { ... }` blocks, while `expr_2021` preserves the current behavior of `expr`, matching expressions without `const` blocks. Joint work with `@vincenzopalazzo.` Issue #123742
2024-05-17Rename Unsafe to SafetySantiago Pastorino-31/+35
2024-05-15delegation: Implement list delegationVadim Petrochenkov-4/+75
```rust reuse prefix::{a, b, c} ```
2024-05-14improve maybe_consume_incorrect_semicolonardi-0/+1
2024-05-14Remove `NtIdent` and `NtLifetime`.Nicholas Nethercote-60/+52
The extra span is now recorded in the new `TokenKind::NtIdent` and `TokenKind::NtLifetime`. These both consist of a single token, and so there's no operator precedence problems with inserting them directly into the token stream. The other way to do this would be to wrap the ident/lifetime in invisible delimiters, but there's a lot of code that assumes an interpolated ident/lifetime fits in a single token, and changing all that code to work with invisible delimiters would have been a pain. (Maybe it could be done in a follow-up.) This change might not seem like much of a win, but it's a first step toward the much bigger and long-desired removal of `Nonterminal` and `TokenKind::Interpolated`. That change is big and complex enough that it's worth doing this piece separately. (Indeed, this commit is based on part of a late commit in #114647, a prior attempt at that big and complex change.)
2024-05-13Apply code review suggestionsEric Holk-1/+1
- use feature_err to report unstable expr_2021 - Update downlevel expr_2021 diagnostics Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2024-05-13expr_2021 should be allowed on edition 2021 and laterEric Holk-1/+1
2024-05-13Add expr_2021 nonterminal and feature flagEric Holk-0/+4
This commit adds a new nonterminal `expr_2021` in macro patterns, and `expr_fragment_specifier_2024` feature flag. For now, `expr` and `expr_2021` are treated the same, but in future PRs we will update `expr` to match to new grammar. Co-authored-by: Vincezo Palazzo <vincenzopalazzodev@gmail.com>
2024-05-12Disallow cast with trailing braced macro in let-elseDavid Tolnay-4/+91
2024-05-13Remove a `Span` from `TokenKind::Interpolated`.Nicholas Nethercote-20/+23
This span records the declaration of the metavariable in the LHS of the macro. It's used in a couple of error messages. Unfortunately, it gets in the way of the long-term goal of removing `TokenKind::Interpolated`. So this commit removes it, which degrades a couple of (obscure) error messages but makes things simpler and enables the next commit.
2024-05-11Add classify::expr_is_completeDavid Tolnay-39/+57
2024-05-11Macro call with braces does not require semicolon to be statementDavid Tolnay-13/+17
This commit by itself is supposed to have no effect on behavior. All of the call sites are updated to preserve their previous behavior. The behavior changes are in the commits that follow.
2024-05-11Mark expr_requires_semi_to_be_stmt call sitesDavid Tolnay-1/+2
For each of these, we need to decide whether they need to be using `expr_requires_semi_to_be_stmt`, or `expr_requires_comma_to_be_match_arm`, which are supposed to be 2 different behaviors. Previously they were conflated into one, causing either too much or too little parenthesization.
2024-05-11Expand on expr_requires_semi_to_be_stmt documentationDavid Tolnay-10/+41
2024-05-09Add `ErrorGuaranteed` to `Recovered::Yes` and use it more.Nicholas Nethercote-6/+9
The starting point for this was identical comments on two different fields, in `ast::VariantData::Struct` and `hir::VariantData::Struct`: ``` // FIXME: investigate making this a `Option<ErrorGuaranteed>` recovered: bool ``` I tried that, and then found that I needed to add an `ErrorGuaranteed` to `Recovered::Yes`. Then I ended up using `Recovered` instead of `Option<ErrorGuaranteed>` for these two places and elsewhere, which required moving `ErrorGuaranteed` from `rustc_parse` to `rustc_ast`. This makes things more consistent, because `Recovered` is used in more places, and there are fewer uses of `bool` and `Option<ErrorGuaranteed>`. And safer, because it's difficult/impossible to set `recovered` to `Recovered::Yes` without having emitted an error.
2024-05-08Rollup merge of #124587 - reitermarkus:use-generic-nonzero, r=dtolnayMatthias Krüger-1/+1
Generic `NonZero` post-stabilization changes. Tracking issue: https://github.com/rust-lang/rust/issues/120257 r? ``@dtolnay``
2024-05-08Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=NilstriebMatthias Krüger-4/+4
Remove braces when fixing a nested use tree into a single item [Back in 2019](https://github.com/rust-lang/rust/pull/56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`. This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then. A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`. This PR is best reviewed commit-by-commit.
2024-05-08Use generic `NonZero`.Markus Reiter-1/+1
2024-05-08Auto merge of #124779 - workingjubilee:debug-formatting-my-beloved, ↵bors-1/+1
r=compiler-errors Improve `rustc_parse::Parser`'s debuggability The main event is the final commit where I add `Parser::debug_lookahead`. Everything else was basically cleaning up things that bugged me (debugging, as it were) until I felt comfortable enough to actually work on it. The motivation is that it's annoying as hell to try to figure out how the debug infra works in rustc without having basic queries like `debug!(?parser);` come up "empty". However, Parser has a lot of fields that are mostly irrelevant for most debugging, like the entire ParseSess. I think `Parser::debug_lookahead` with a capped lookahead might be fine as a general-purpose Debug impl, but this adapter version was suggested to allow more choice, and admittedly, it's a refined version of what I was already handrolling just to get some insight going.
2024-05-07compiler: derive Debug in parserJubilee Young-1/+1
It's annoying to debug the parser if you have to stop every five seconds to add a Debug impl.
2024-05-06Return coherent description for boolean instead of panickingUrgau-1/+1
2024-05-04Various improvements to entrypoint codeNilstrieb-1/+25
This moves some code around and adds some documentation comments to make it easier to understand what's going on with the entrypoint logic, which is a bit complicated. The only change in behavior is consolidating the error messages for unix_sigpipe to make the code slightly simpler.
2024-05-03AST pretty: Use `builtin_syntax` for type ascriptionLeón Orell Valerian Liehr-4/+10
2024-05-01Step bootstrap cfgsMark Rousskov-1/+0
2024-04-30Rollup merge of #124511 - nnethercote:rm-extern-crates, r=fee1-deadMatthias Krüger-9/+7
Remove many `#[macro_use] extern crate foo` items This requires the addition of more `use` items, which often make the code more verbose. But they also make the code easier to read, because `#[macro_use]` obscures where macros are defined. r? `@fee1-dead`
2024-04-30Remove `extern crate tracing` from numerous crates.Nicholas Nethercote-3/+1
2024-04-29Add StaticForeignItem and use it on ForeignItemKindSantiago Pastorino-9/+38
2024-04-29Remove `extern crate rustc_macros` from numerous crates.Nicholas Nethercote-6/+6
2024-04-25ast: Visit item components in "natural" orderVadim Petrochenkov-4/+4
2024-04-25ast: Generalize item kind visitingVadim Petrochenkov-311/+341
And avoid duplicating logic for visiting `Item`s with different kinds (regular, associated, foreign).
2024-04-25Rollup merge of #124324 - nnethercote:minor-ast-cleanups, r=estebankMatthias Krüger-78/+71
Minor AST cleanups r? ``@estebank``
2024-04-25Add comments about attribute tokens.Nicholas Nethercote-0/+2
This clarifies something that has puzzled me for some time.
2024-04-24Remove unnecessary `pub`s in `mut_visit.rs`.Nicholas Nethercote-65/+60
This makes it clearer what is actually used outside of this crate.
2024-04-24Rename `NestedMetaItem::name_value_literal`.Nicholas Nethercote-2/+3
It's a highly misleading name, because it's completely different to `MetaItem::name_value_literal`. Specifically, it doesn't match `MetaItemKind::NameValue` (e.g. `#[foo = 3]`), it matches `MetaItemKind::List` (e.g. `#[foo(3)]`).
2024-04-24Remove `MetaItemKind::value_str`.Nicholas Nethercote-8/+4
`MetaItem::value_str` is good enough. And this makes `MetaItem::value_str` more like `MetaItem::meta_item_list` and `name_value_literal`.
2024-04-24Make `LazyAttrTokenStream::encode` panic.Nicholas Nethercote-3/+2
It's unreachable, because AST JSON printing support was removed some time ago.
2024-04-23delegation: Support renamingVadim Petrochenkov-4/+13
2024-04-18Auto merge of #124008 - nnethercote:simpler-static_assert_size, r=Nilstriebbors-3/+3
Simplify `static_assert_size`s. We want to run them on all 64-bit platforms. r? `@ghost`
2024-04-18Simplify `static_assert_size`s.Nicholas Nethercote-3/+3
We want to run them on all 64-bit platforms.
2024-04-17Improve `BindingMode` doc commentJules Bertholet-2/+4
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-10/+10
2024-04-17Store `ByRef` instead of `BindingAnnotation` in `PatInfo`Jules Bertholet-7/+9
2024-04-16Fix empty-set symbol in commentsDavid Tolnay-1/+1
2024-04-16Rollup merge of #123512 - Jules-Bertholet:ref-pat-eat-one-layer-2024, ↵Guillaume Gomez-0/+8
r=Nadrieril Match ergonomics 2024: Implement eat-one-layer r? `@Nadrieril` cc #123076 `@rustbot` label A-edition-2024 A-patterns
2024-04-16Auto merge of #123468 - compiler-errors:precise-capturing, r=oli-obkbors-4/+55
Implement syntax for `impl Trait` to specify its captures explicitly (`feature(precise_capturing)`) Implements `impl use<'a, 'b, T, U> Sized` syntax that allows users to explicitly list the captured parameters for an opaque, rather than inferring it from the opaque's bounds (or capturing *all* lifetimes under 2024-edition capture rules). This allows us to exclude some implicit captures, so this syntax may be used as a migration strategy for changes due to #117587. We represent this list of captured params as `PreciseCapturingArg` in AST and HIR, resolving them between `rustc_resolve` and `resolve_bound_vars`. Later on, we validate that the opaques only capture the parameters in this list. We artificially limit the feature to *require* mentioning all type and const parameters, since we don't currently have support for non-lifetime bivariant generics. This can be relaxed in the future. We also may need to limit this to require naming *all* lifetime parameters for RPITIT, since GATs have no variance. I have to investigate this. This can also be relaxed in the future. r? `@oli-obk` Tracking issue: - https://github.com/rust-lang/rust/issues/123432
2024-04-15Address review commentsJules Bertholet-2/+2
2024-04-15Ensure inherited reference is never set to `&mut` behind an `&`Jules Bertholet-0/+8
2024-04-16Rollup merge of #123462 - fmease:rn-mod-sep-to-path-sep, r=nnethercoteLeón Orell Valerian Liehr-12/+14
Cleanup: Rename `ModSep` to `PathSep` `::` is usually referred to as the *path separator* (citation needed). The existing name `ModSep` for *module separator* is a bit misleading since it in fact separates the segments of arbitrary path segments, not only ones resolving to modules. Let me just give a shout-out to associated items (`T::Assoc`, `<Ty as Trait>::function`) and enum variants (`Option::None`). Motivation: Reduce friction for new contributors, prevent potential confusion. cc `@petrochenkov` r? nnethercote or compiler
2024-04-15Use a path instead of an ident (and stop manually resolving)Michael Goulet-6/+6
2024-04-15Validation and other thingsMichael Goulet-4/+4