about summary refs log tree commit diff
path: root/src/tools/rustfmt/src/parse/macros
AgeCommit message (Collapse)AuthorLines
2025-08-09remove `P`Deadbeef-9/+8
2025-06-06Rollup merge of #141603 - nnethercote:reduce-P, r=fee1-deadGuillaume Gomez-1/+1
Reduce `ast::ptr::P` to a typedef of `Box` As per the MCP at https://github.com/rust-lang/compiler-team/issues/878. r? `@fee1-dead`
2025-05-27move asm parsing code into `rustc_parse`Folkert de Vries-1/+1
2025-05-27Reduce `P<T>` to a typedef of `Box<T>`.Nicholas Nethercote-1/+1
Keep the `P` constructor function for now, to minimize immediate churn. All the `into_inner` calls are removed, which is nice.
2025-05-18rename to get rid of the 'raw' conceptFolkert de Vries-6/+3
2025-05-18attempt to have rustfmt use the new logicFolkert de Vries-3/+6
apparently it doesn't really use the asm parsing at present, so this may work?
2025-04-21Remove `token::{Open,Close}Delim`.Nicholas Nethercote-4/+2
By replacing them with `{Open,Close}{Param,Brace,Bracket,Invisible}`. PR #137902 made `ast::TokenKind` more like `lexer::TokenKind` by replacing the compound `BinOp{,Eq}(BinOpToken)` variants with fieldless variants `Plus`, `Minus`, `Star`, etc. This commit does a similar thing with delimiters. It also makes `ast::TokenKind` more similar to `parser::TokenType`. This requires a few new methods: - `TokenKind::is_{,open_,close_}delim()` replace various kinds of pattern matches. - `Delimiter::as_{open,close}_token_kind` are used to convert `Delimiter` values to `TokenKind`. Despite these additions, it's a net reduction in lines of code. This is because e.g. `token::OpenParen` is so much shorter than `token::OpenDelim(Delimiter::Parenthesis)` that many multi-line forms reduce to single line forms. And many places where the number of lines doesn't change are still easier to read, just because the names are shorter, e.g.: ``` - } else if self.token != token::CloseDelim(Delimiter::Brace) { + } else if self.token != token::CloseBrace { ```
2025-03-24Remove `is_any_keyword` methods.Nicholas Nethercote-1/+1
They're dodgy, covering all the keywords, including weak ones, and edition-specific ones without considering the edition. They have a single use in rustfmt. This commit changes that use to `is_reserved_ident`, which is a much more widely used alternative and is good enough, judging by the lack of effect on the test suite.
2024-12-19Speed up `Parser::expected_token_types`.Nicholas Nethercote-13/+15
The parser pushes a `TokenType` to `Parser::expected_token_types` on every call to the various `check`/`eat` methods, and clears it on every call to `bump`. Some of those `TokenType` values are full tokens that require cloning and dropping. This is a *lot* of work for something that is only used in error messages and it accounts for a significant fraction of parsing execution time. This commit overhauls `TokenType` so that `Parser::expected_token_types` can be implemented as a bitset. This requires changing `TokenType` to a C-style parameterless enum, and adding `TokenTypeSet` which uses a `u128` for the bits. (The new `TokenType` has 105 variants.) The new types `ExpTokenPair` and `ExpKeywordPair` are now arguments to the `check`/`eat` methods. This is for maximum speed. The elements in the pairs are always statically known; e.g. a `token::BinOp(token::Star)` is always paired with a `TokenType::Star`. So we now compute `TokenType`s in advance and pass them in to `check`/`eat` rather than the current approach of constructing them on insertion into `expected_token_types`. Values of these pair types can be produced by the new `exp!` macro, which is used at every `check`/`eat` call site. The macro is for convenience, allowing any pair to be generated from a single identifier. The ident/keyword filtering in `expected_one_of_not_found` is no longer necessary. It was there to account for some sloppiness in `TokenKind`/`TokenType` comparisons. The existing `TokenType` is moved to a new file `token_type.rs`, and all its new infrastructure is added to that file. There is more boilerplate code than I would like, but I can't see how to make it shorter.
2024-12-18Only have one source of truth for keywords.Nicholas Nethercote-75/+12
`rustc_symbol` is the source of truth for keywords. rustdoc has its own implicit definition of keywords, via the `is_doc_keyword`. It (presumably) intends to include all keywords, but it omits `yeet`. rustfmt has its own explicit list of Rust keywords. It also (presumably) intends to include all keywords, but it omits `await`, `builtin`, `gen`, `macro_rules`, `raw`, `reuse`, `safe`, and `yeet`. Also, it does linear searches through this list, which is inefficient. This commit fixes all of the above problems by introducing a new predicate `is_any_keyword` in rustc and using it in rustdoc and rustfmt. It documents that it's not the right predicate in most cases.
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-1/+1
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-10-06disallow `asm!` in `#[naked]` functionsFolkert de Vries-2/+2
also disallow the `noreturn` option, and infer `naked_asm!` as `!`
2024-10-06implement `naked_asm` macroFolkert-2/+2
2024-09-19Merge commit 'b23b69900eab1260be510b2bd8922f4b6de6cf1e' into sync-from-rustfmtYacin Tmimi-4/+4
2024-08-14Use `impl PartialEq<TokenKind> for Token` more.Nicholas Nethercote-5/+3
This lets us compare a `Token` with a `TokenKind`. It's used a lot, but can be used even more, avoiding the need for some `.kind` uses.
2024-07-30Suppress must_use on eat calls in rustfmtMichael Goulet-5/+7
2024-06-23Rollup merge of #126851 - nnethercote:NtExprKind-NtPatKind, r=compiler-errorsMatthias Krüger-3/+3
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-3/+3
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-22fix bad merge conflict resolutionCaleb Cartwright-1/+4
2024-06-22Merge commit 'e4944185ae09c99f59b460e358909f329010ea9c' into ↵Caleb Cartwright-4/+0
sync-from-rustfmt-24-06
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-7/+7
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-05Remove `stream_to_parser`.Nicholas Nethercote-2/+2
It's a zero-value wrapper of `Parser::new`.
2024-03-05Rename all `ParseSess` variables/fields/lifetimes as `psess`.Nicholas Nethercote-14/+14
Existing names for values of this type are `sess`, `parse_sess`, `parse_session`, and `ps`. `sess` is particularly annoying because that's also used for `Session` values, which are often co-located, and it can be difficult to know which type a value named `sess` refers to. (That annoyance is the main motivation for this change.) `psess` is nice and short, which is good for a name used this much. The commit also renames some `parse_sess_created` values as `psess_created`.
2024-03-04Tweak `parse_asm_args`.Nicholas Nethercote-1/+1
It doesn't need a `Parser` and a `ParseSess`, because the former contains the latter.
2024-01-22Actually, just use nonterminal_may_begin_withMichael Goulet-8/+7
2024-01-22Do not eagerly recover malformed AST in rustfmtMichael Goulet-1/+1
2024-01-22Check that a token can begin a nonterminal kind before parsing it as a macro ↵Michael Goulet-17/+24
arg in rustfmt
2023-12-18Rename `ParseSess::span_diagnostic` as `ParseSess::dcx`.Nicholas Nethercote-7/+7
2023-08-03Fix rustfmt depMu001999-1/+1
2023-06-19Merge commit '3f7c366fc0464e01ddcaefbd70647cb3da4202be' into rustfmt-syncCaleb Cartwright-1/+9
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-2/+2
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.
2022-05-11Remove some unnecessary invisible delimiter checks.Nicholas Nethercote-3/+1
These seem to have no useful effect... they don't seem useful from a code inspection point of view, and they affect anything in the test suite.
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-8/+8
2022-03-16rustc_error: make ErrorReported impossible to constructmark-2/+2
There are a few places were we have to construct it, though, and a few places that are more invasive to change. To do this, we create a constructor with a long obvious name.
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-3/+3
2021-12-29Merge commit '4a053f206fd6799a25823c307f7d7f9d897be118' into ↵Caleb Cartwright-0/+381
sync-rustfmt-subtree