summary refs log tree commit diff
path: root/compiler/rustc_expand/src
AgeCommit message (Collapse)AuthorLines
2024-06-06Fix formattingcarbotaniuman-2/+16
2024-06-06Fix buildcarbotaniuman-4/+4
2024-06-06Disallow unsafe in derivecarbotaniuman-1/+2
2024-06-06Parse unsafe attributescarbotaniuman-4/+10
2024-06-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-1/+4
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-05Make top-level `rustc_parse` functions fallible.Nicholas Nethercote-6/+8
Currently we have an awkward mix of fallible and infallible functions: ``` new_parser_from_source_str maybe_new_parser_from_source_str new_parser_from_file (maybe_new_parser_from_file) // missing (new_parser_from_source_file) // missing maybe_new_parser_from_source_file source_str_to_stream maybe_source_file_to_stream ``` We could add the two missing functions, but instead this commit removes of all the infallible ones and renames the fallible ones leaving us with these which are all fallible: ``` new_parser_from_source_str new_parser_from_file new_parser_from_source_file source_str_to_stream source_file_to_stream ``` This requires making `unwrap_or_emit_fatal` public so callers of formerly infallible functions can still work. This does make some of the call sites slightly more verbose, but I think it's worth it for the simpler API. Also, there are two `catch_unwind` calls and one `catch_fatal_errors` call in this diff that become removable thanks this change. (I will do that in a follow-up PR.)
2024-06-05Reorder `source_str_to_stream` arguments.Nicholas Nethercote-1/+1
It's the only one of these functions where `psess` isn't the first argument.
2024-06-05Remove `stream_to_parser`.Nicholas Nethercote-11/+7
It's a zero-value wrapper of `Parser::new`.
2024-06-05Don't use the word "parse" for lexing operations.Nicholas Nethercote-2/+2
Lexing converts source text into a token stream. Parsing converts a token stream into AST fragments. This commit renames several lexing operations that have "parse" in the name. I think these names have been subtly confusing me for years. This is just a `s/parse/lex/` on function names, with one exception: `parse_stream_from_source_str` becomes `source_str_to_stream`, to make it consistent with the existing `source_file_to_stream`. The commit also moves that function's location in the file to be just above `source_file_to_stream`. The commit also cleans up a few comments along the way.
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-1/+4
2024-05-28Convert `proc_macro_back_compat` lint to an unconditional error.Nicholas Nethercote-54/+47
We still check for the `rental`/`allsorts-rental` crates. But now if they are detected we just emit a fatal error, instead of emitting a warning and providing alternative behaviour. The original "hack" implementing alternative behaviour was added in #73345. The lint was added in #83127. The tracking issue is #83125. The direct motivation for the change is that providing the alternative behaviour is interfering with #125174 and follow-on work.
2024-05-28Use let chains in `pretty_printing_compatibility_hack`.Nicholas Nethercote-41/+32
To reduce indentation and improve readability.
2024-05-28Remove a stray comment that shouldn't be here.Nicholas Nethercote-1/+0
2024-05-27Rollup merge of #125530 - SparrowLii:expand2, r=petrochenkovGuillaume Gomez-32/+31
cleanup dependence of `ExtCtxt` in transcribe when macro expansion part of #125356 We can remove `transcribe`’s dependence on `ExtCtxt` to facilitate subsequent work (such as moving macro expansion into the incremental compilation system) r? ```@petrochenkov``` Thanks for the reviewing!
2024-05-25cleanup dependence of `ExtCtxt` in transcribe when macro expansionSparrowLii-32/+31
2024-05-23Rollup merge of #125316 - nnethercote:tweak-Spacing, r=petrochenkovMatthias Krüger-16/+42
Tweak `Spacing` use Some clean-up precursors to #125174. r? ``@petrochenkov``
2024-05-23Add some comments.Nicholas Nethercote-0/+17
2024-05-23Clarify a comment.Nicholas Nethercote-4/+4
2024-05-23Clarify `parse` a little.Nicholas Nethercote-3/+8
- Name the colon span as `colon_span` to distinguish it from the other `span` local variable. - Just use basic pattern matching, which is easier to read than `map_or`.
2024-05-23Clarify the meaning of the span within `mbe::TokenTree::MetaVar`.Nicholas Nethercote-9/+13
2024-05-21Rename buffer_lint_with_diagnostic to buffer_lintXiretza-10/+10
2024-05-21Make early lints translatableXiretza-10/+8
2024-05-21Convert uses of BuiltinLintDiag::Normal to custom variantsXiretza-24/+17
This ensures all diagnostic messages are created at diagnostic emission time, making them translatable.
2024-05-21Generate lint diagnostic message from BuiltinLintDiagXiretza-5/+0
Translation of the lint message happens when the actual diagnostic is created, not when the lint is buffered. Generating the message from BuiltinLintDiag ensures that all required data to construct the message is preserved in the LintBuffer, eventually allowing the messages to be moved to fluent. Remove the `msg` field from BufferedEarlyLint, it is either generated from the data in the BuiltinLintDiag or stored inside BuiltinLintDiag::Normal.
2024-05-18Auto merge of #125180 - mu001999-contrib:improve/macro-diag, r=fee1-deadbors-13/+45
Improve error message: missing `;` in macro_rules Fixes #124968
2024-05-18Improve error message: missing `;` in macro_rulesr0cky-13/+45
2024-05-17Auto merge of #123865 - eholk:expr_2021, r=fmeasebors-22/+51
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-17Rollup merge of #123694 - Xiretza:expand-diagnostics, r=compiler-errorsMatthias Krüger-3/+6
expand: fix minor diagnostics bug The error mentions `///`, when it's actually `//!`: ``` error[E0658]: attributes on expressions are experimental --> test.rs:4:9 | 4 | //! wah | ^^^^^^^ | = note: see issue https://github.com/rust-lang/rust/issues/15701 <https://github.com/rust-lang/rust/issues/15701> for more information = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable = help: `///` is for documentation comments. For a plain comment, use `//`. ```
2024-05-16Auto merge of #124987 - ↵bors-8/+8
workingjubilee:macro-metavar-expr-with-a-shorter-len, r=c410-f3r,joshtriplett,joshtriplett Rename `${length()}` to `${len()}` Implements the rename suggested in https://github.com/rust-lang/rust/pull/122808#issuecomment-2047722187 > I brought this up in the doc PR but it belongs here – `length` should probably be renamed `len` before stabilization. The latter is de facto standard in the standard library, whereas the former is only used in a single unstable API. These metafunctions aren’t library items of course, but should presumably still be consistent with established names. r? `@c410-f3r`
2024-05-15delegation: Implement list delegationVadim Petrochenkov-2/+122
```rust reuse prefix::{a, b, c} ```
2024-05-14Remove `NtIdent` and `NtLifetime`.Nicholas Nethercote-12/+36
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-30/+46
- 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-13Add expr_2021 nonterminal and feature flagEric Holk-1/+14
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-13Remove a `Span` from `TokenKind::Interpolated`.Nicholas Nethercote-18/+7
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-10s/MetaVarExpr::Length/MetaVarExpr::Len/Jubilee Young-8/+8
2024-05-09Add `ErrorGuaranteed` to `Recovered::Yes` and use it more.Nicholas Nethercote-1/+4
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 #123344 - pietroalbini:pa-unused-imports, r=NilstriebMatthias Krüger-2/+2
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-06Move some tests from `rustc_expand` to `rustc_parse`.Nicholas Nethercote-1638/+0
There are some test cases involving `parse` and `tokenstream` and `mut_visit` that are located in `rustc_expand`. Because it used to be the case that constructing a `ParseSess` required the involvement of `rustc_expand`. However, since #64197 merged (a long time ago) `rust_expand` no longer needs to be involved. This commit moves the tests into `rustc_parse`. This is the optimal place for the `parse` tests. It's not ideal for the `tokenstream` and `mut_visit` tests -- they would be better in `rustc_ast` -- but they still rely on parsing, which is not available in `rustc_ast`. But `rustc_parse` is lower down in the crate graph and closer to `rustc_ast` than `rust_expand`, so it's still an improvement for them. The exact renaming is as follows: - rustc_expand/src/mut_visit/tests.rs -> rustc_parse/src/parser/mut_visit/tests.rs - rustc_expand/src/tokenstream/tests.rs -> rustc_parse/src/parser/tokenstream/tests.rs - rustc_expand/src/tests.rs + rustc_expand/src/parse/tests.rs -> compiler/rustc_parse/src/parser/tests.rs The latter two test files are combined because there's no need for them to be separate, and having a `rustc_parse::parser::parse` module would be weird. This also means some `pub(crate)`s can be removed.
2024-05-03Refactor `Frame`.Nicholas Nethercote-48/+50
It is currently an enum and the `tts` and `idx` fields are repeated across the two variants. This commit splits it into a struct `Frame` and an enum `FrameKind`, to factor out the duplication. The commit also renames `Frame::new` as `Frame::new_delimited` and adds `Frame::new_sequence`. I.e. both variants now have a constructor.
2024-05-03Type annotate `repeats`.Nicholas Nethercote-1/+1
Because the type is not obvious, and this clarifies things.
2024-05-03Introduce `Invocation::span_mut`.Nicholas Nethercote-5/+9
Alongside the existing `Invocation::span`.
2024-05-03Replace a hard-to-read line.Nicholas Nethercote-1/+2
Too clever by half, IMO.
2024-05-03Tweak `fully_expand_fragment` loop.Nicholas Nethercote-11/+9
Control flow never gets past the end of the `ExpandResult::Retry` match arm, due to the `span_bug` and the `continue`. Therefore, the code after the match can only be reached from the `ExpandResult::Ready` arm. This commit moves that code after the match into the `ExpandResult::Ready` arm, avoiding the need for the `continue` in the `ExpandResult::Retry` arm.
2024-05-03Remove unnecessary `pub`s.Nicholas Nethercote-11/+12
2024-05-03Fix some comment formatting.Nicholas Nethercote-12/+16
2024-05-03Inline and remove three `DummyResult` methods.Nicholas Nethercote-32/+22
They each have a single call site.
2024-05-03Remove unnecessary re-export of `MacroKind`.Nicholas Nethercote-3/+1
2024-05-03De-`pub` some `rustc_expand` modules.Nicholas Nethercote-7/+5
2024-05-03Remove unused `ExpCtxt` methods.Nicholas Nethercote-27/+0
2024-05-03Remove an unnecessary `#[macro_use]`.Nicholas Nethercote-1/+0