about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/ast_traits.rs
AgeCommit message (Collapse)AuthorLines
2025-08-09remove `P`Deadbeef-6/+5
2025-06-19completely deduplicate `Visitor` and `MutVisitor`Deadbeef-0/+7
2025-05-29remove `visit_clobber` and move `DummyAstNode` to `rustc_expand`Deadbeef-0/+6
`visit_clobber` is not really useful except for one niche purpose involving generic code. We should just use the replace logic where we can.
2025-05-10Remove `AstDeref`.Nicholas Nethercote-47/+28
It's a "utility trait to reduce boilerplate" implemented for `P` and `AstNodeWrapper`, but removing it gives a net reduction of twenty lines of code. It's also simpler to just implement `HasNodeId`/`HasAttrs`/`HasTokens` directly on types instead of via `AstDeref`. (I decided to make this change when doing some related refactoring and the error messages involving `AstDeref` and `HasAttrs` were hard to understand; removing it helped a lot.)
2025-04-02Remove `NtBlock`, `Nonterminal`, and `TokenKind::Interpolated`.Nicholas Nethercote-14/+0
`NtBlock` is the last remaining variant of `Nonterminal`, so once it is gone then `Nonterminal` can be removed as well.
2025-04-02Remove `NtExpr` and `NtLiteral`.Nicholas Nethercote-2/+0
Notes about tests: - tests/ui/rfcs/rfc-2294-if-let-guard/feature-gate.rs: some messages are now duplicated due to repeated parsing. - tests/ui/rfcs/rfc-2497-if-let-chains/disallowed-positions.rs: ditto. - `tests/ui/proc-macro/macro-rules-derive-cfg.rs`: the diff looks large but the only difference is the insertion of a single invisible-delimited group around a metavar. - `tests/ui/attributes/nonterminal-expansion.rs`: a slight span degradation, somehow related to the recent massive attr parsing rewrite (#135726). I couldn't work out exactly what is going wrong, but I don't think it's worth holding things up for a single slightly suboptimal error message.
2025-03-07Remove `NtItem` and `NtStmt`.Nicholas Nethercote-4/+0
This involves replacing `nt_pretty_printing_compatibility_hack` with `stream_pretty_printing_compatibility_hack`. The handling of statements in `transcribe` is slightly different to other nonterminal kinds, due to the lack of `from_ast` implementation for empty statements. Notable test changes: - `tests/ui/proc-macro/expand-to-derive.rs`: the diff looks large but the only difference is the insertion of a single invisible-delimited group around a metavar.
2025-03-01Implment `#[cfg]` and `#[cfg_attr]` in `where` clausesFrank King-2/+13
2025-02-28Remove `NtPath`.Nicholas Nethercote-2/+0
2025-02-28Remove `NtMeta`.Nicholas Nethercote-2/+0
Note: there was an existing code path involving `Interpolated` in `MetaItem::from_tokens` that was dead. This commit transfers that to the new form, but puts an `unreachable!` call inside it.
2025-02-28Remove `NtPat`.Nicholas Nethercote-2/+0
The one notable test change is `tests/ui/macros/trace_faulty_macros.rs`. This commit removes the complicated `Interpolated` handling in `expected_expression_found` that results in a longer error message. But I think the new, shorter message is actually an improvement. The original complaint was in #71039, when the error message started with "error: expected expression, found `1 + 1`". That was confusing because `1 + 1` is an expression. Other than that, the reporter said "the whole error message is not too bad if you ignore the first line". Subsequently, extra complexity and wording was added to the error message. But I don't think the extra wording actually helps all that much. In particular, it still says of the `1+1` that "this is expected to be expression". This repeats the problem from the original complaint! This commit removes the extra complexity, reverting to a simpler error message. This is primarily because the traversal is a pain without `Interpolated` tokens. Nonetheless, I think the error message is *improved*. It now starts with "expected expression, found `pat` metavariable", which is much clearer and the real problem. It also doesn't say anything specific about `1+1`, which is good, because the `1+1` isn't really relevant to the error -- it's the `$e:pat` that's important.
2025-02-21Remove `NtTy`.Nicholas Nethercote-2/+0
Notes about tests: - tests/ui/parser/macro/trait-object-macro-matcher.rs: the syntax error is duplicated, because it occurs now when parsing the decl macro input, and also when parsing the expanded decl macro. But this won't show up for normal users due to error de-duplication. - tests/ui/associated-consts/issue-93835.rs: similar, plus there are some additional errors about this very broken code. - The changes to metavariable descriptions in #132629 are now visible in error message for several tests.
2025-02-21Remove `NtVis`.Nicholas Nethercote-2/+0
We now use invisible delimiters for expanded `vis` fragments, instead of `Token::Interpolated`.
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-7/+8
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-07Remove `HasSpan` trait.Nicholas Nethercote-33/+0
The only place it is meaningfully used is in a panic message in `TokenStream::from_ast`. But `node.span()` doesn't need to be printed because `node` is also printed and it must contain the span.
2024-05-14Remove `NtIdent` and `NtLifetime`.Nicholas Nethercote-2/+0
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-03-14Rename `ast::StmtKind::Local` into `ast::StmtKind::Let`Guillaume Gomez-4/+4
2023-01-05Fix `uninlined_format_args` for some compiler cratesnils-2/+2
Convert all the crates that have had their diagnostic migration completed (except save_analysis because that will be deleted soon and apfloat because of the licensing problem).
2022-09-09Rename `{Create,Lazy}TokenStream` as `{To,Lazy}AttrTokenStream`.Nicholas Nethercote-19/+19
`To` is better than `Create` for indicating that this is a non-consuming conversion, rather than creating something out of nothing. And the addition of `Attr` is because the current names makes them sound like they relate to `TokenStream`, but really they relate to `AttrTokenStream`.
2022-08-29Inline `attrs`.Nicholas Nethercote-0/+1
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-37/+10
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
2022-08-16Shrink `ast::Attribute`.Nicholas Nethercote-2/+2
2022-05-22rustc_parse: Move AST -> TokenStream conversion logic to `rustc_ast`Vadim Petrochenkov-1/+7
2022-05-11ast: Introduce some traits to get AST node properties genericallyVadim Petrochenkov-0/+436
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion