about summary refs log tree commit diff
path: root/compiler/rustc_expand
AgeCommit message (Collapse)AuthorLines
2024-06-25Extra panic cases.Nicholas Nethercote-0/+6
Just some extra sanity checking, making explicit some values not possible in code working with token trees -- we shouldn't be seeing explicit delimiter tokens, because they should be represented as `TokenTree::Delimited`.
2024-06-24Rollup merge of #126177 - carbotaniuman:unsafe_attr_errors, r=jieyouxuMatthias Krüger-1/+1
Add hard error and migration lint for unsafe attrs More implementation work for https://github.com/rust-lang/rust/issues/123757 This adds the migration lint for unsafe attributes, as well as making it a hard error in Rust 2024.
2024-06-23Add hard error and migration lint for unsafe attrscarbotaniuman-1/+1
2024-06-23Rollup merge of #126851 - nnethercote:NtExprKind-NtPatKind, r=compiler-errorsMatthias Krüger-41/+39
Rework pattern and expression nonterminal kinds. Some tweaks to `NonterminalKind` that will assist with #124141. Details in the individual commits. r? compiler-errors cc ```@eholk```
2024-06-23Rework pattern and expression nonterminal kinds.Nicholas Nethercote-12/+12
Merge `PatParam`/`PatWithOr`, and `Expr`/`Expr2021`, for a few reasons. - It's conceptually nice, because the two pattern kinds and the two expression kinds are very similar. - With expressions in particular, there are several places where both expression kinds get the same treatment. - It removes one unreachable match arm. - Most importantly, for #124141 I will need to introduce a new type `MetaVarKind` that is very similar to `NonterminalKind`, but records a couple of extra fields for expression metavars. It's nicer to have a single `MetaVarKind::Expr` expression variant to hold those extra fields instead of duplicating them across two variants `MetaVarKind::{Expr,Expr2021}`. And then it makes sense for patterns to be treated the same way, and for `NonterminalKind` to also be treated the same way. I also clarified the comments, because I have long found them a little hard to understand.
2024-06-23Tweak some ugly formatting.Nicholas Nethercote-1/+4
2024-06-23Import `NonterminalKind` in `compiler/rustc_expand/src/mbe/quoted.rs`.Nicholas Nethercote-30/+25
So we can omit the `token::` qualifier, which gives more space to some cramped code.
2024-06-22delegation: Do not crash on qpaths without a traitVadim Petrochenkov-2/+20
2024-06-21Rollup merge of #126700 - compiler-errors:fragment, r=fmeaseMatthias Krüger-2/+5
Make edition dependent `:expr` macro fragment act like the edition-dependent `:pat` fragment does Parse the `:expr` fragment as `:expr_2021` in editions <=2021, and as `:expr` in edition 2024. This is similar to how we parse `:pat` as `:pat_param` in edition <=2018 and `:pat_with_or` in >=2021, and means we can get rid of a span dependency from `nonterminal_may_begin_with`. Specifically, this fixes a theoretical regression since the `expr_2021` macro fragment previously would allow `const {}` if the *caller* is edition 2024. This is inconsistent with the way that the `pat` macro fragment was upgraded, and also leads to surprising behavior when a macro *caller* crate upgrades to edtion 2024, since they may have parsing changes that they never asked for (with no way of opting out of it). This PR also allows using `expr_2021` in all editions. Why was this was disallowed in the first place? It's purely additive, and also it's still feature gated? r? ```@fmease``` ```@eholk``` cc ```@vincenzopalazzo``` cc #123865 Tracking: - https://github.com/rust-lang/rust/issues/123742
2024-06-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-0/+1
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-19Allow naming expr_2021 in all editionsMichael Goulet-2/+5
2024-06-19Rollup merge of #124135 - petrochenkov:deleglob, r=fmease许杰友 Jieyou Xu (Joe)-43/+175
delegation: Implement glob delegation Support delegating to all trait methods in one go. Overriding globs with explicit definitions is also supported. The implementation is generally based on the design from https://github.com/rust-lang/rfcs/pull/3530#issuecomment-2020869823, but unlike with list delegation in https://github.com/rust-lang/rust/pull/123413 we cannot expand glob delegation eagerly. We have to enqueue it into the queue of unexpanded macros (most other macros are processed this way too), and then a glob delegation waits in that queue until its trait path is resolved, and enough code expands to generate the identifier list produced from the glob. Glob delegation is only allowed in impls, and can only point to traits. Supporting it in other places gives very little practical benefit, but significantly raises the implementation complexity. Part of https://github.com/rust-lang/rust/issues/118212.
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-11/+6
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-11/+16
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18Prefer `dcx` methods over fields or fields' methodsOli Scherer-23/+24
2024-06-15Rollup merge of #125829 - petrochenkov:upctxt2, r=michaelwoeristerMatthias Krüger-1/+1
rustc_span: Add conveniences for working with span formats This is the refactoring part of https://github.com/rust-lang/rust/pull/125017.
2024-06-14delegation: Implement glob delegationVadim Petrochenkov-43/+175
2024-06-13Add a new concat metavar exprCaio-27/+145
2024-06-13rustc_span: By-value interface for ctxt updateVadim Petrochenkov-1/+1
2024-06-11Rollup merge of #125913 - fmease:early-lints-spruce-up-some-diags, r=Nadrieril许杰友 Jieyou Xu (Joe)-1/+1
Spruce up the diagnostics of some early lints Implement the various "*(note to myself) in a follow-up PR we should turn parts of this message into a subdiagnostic (help msg or even struct sugg)*" drive-by comments I left in #124417 during my review. For context, before #124417, only a few early lints touched/decorated/customized their diagnostic because the former API made it a bit awkward. Likely because of that, things that should've been subdiagnostics were just crammed into the primary message. This PR rectifies this.
2024-06-10rustc_span: Optimize syntax context updates in spansVadim Petrochenkov-5/+5
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-06-03Spruce up the diagnostics of some early lintsLeón Orell Valerian Liehr-1/+1
2024-05-28Convert `proc_macro_back_compat` lint to an unconditional error.Nicholas Nethercote-54/+50
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/+11
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 `//`. ```