about summary refs log tree commit diff
path: root/compiler/rustc_ast/src
AgeCommit message (Collapse)AuthorLines
2025-06-12add `extern "custom"` functionsFolkert de Vries-0/+32
2025-06-12early linting: avoid redundant calls to `check_id`Deadbeef-1/+2
2025-06-12avoid `&mut P<T>` in `visit_expr` etc methodsDeadbeef-7/+25
2025-06-12Add some useful `Path`/`PathSegment` equality operations.Nicholas Nethercote-2/+19
They will be used in a subsequent commit.
2025-06-09deduplicate the rest of AST walker functionsDeadbeef-1165/+666
2025-06-06Rollup merge of #142086 - fee1-dead-contrib:ast-visitor-dedup, r=oli-obkGuillaume Gomez-357/+272
duduplicate more AST visitor methods r? oli-obk
2025-06-06Rollup merge of #141603 - nnethercote:reduce-P, r=fee1-deadGuillaume Gomez-210/+11
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-06-06deduplicate more `walk_*` methods in AST visitDeadbeef-217/+146
2025-06-05use helper macro for flat_map vs visit_list, initial dedupsDeadbeef-153/+139
2025-06-04Rollup merge of #142007 - nnethercote:visitor-comments, r=chenyukangMatthias Krüger-0/+4
Improve some `Visitor` comments. For AST/HIR/THIR visitors, explain the use of deconstruction. r? ``@BoxyUwU``
2025-06-04Rollup merge of #141570 - chenyukang:yukang-fix-eq_unspanned, r=workingjubileeMatthias Krüger-13/+3
Fix incorrect eq_unspanned in TokenStream Fixes rust-lang/rust#141522 r? ``@workingjubilee`` should we remove this function? since it's used in several places, i'd prefer to keep it.
2025-06-04Improve some `Visitor` comments.Nicholas Nethercote-0/+4
For AST/HIR/THIR visitors, explain the use of deconstruction.
2025-06-03Rollup merge of #141945 - nnethercote:rm-Path-is_ident, r=compiler-errorsMatthias Krüger-13/+9
Remove `Path::is_ident`. It checks that a path has a single segment that matches the given symbol, and that there are zero generic arguments. It has a single use. We also have `impl PartialEq<Symbol> for Path` which does exactly the same thing *except* it doesn't check for zero generic arguments, which seems like an oversight. It has numerous uses. This commit removes `Path::is_ident`, adds a test for zero generic arguments to `PartialEq<Symbol> for Path`, and changes the single use of `is_ident` to instead use `==`. r? `@wesleywiser`
2025-06-03Auto merge of #141961 - matthiaskrgr:rollup-r09j2sp, r=matthiaskrgrbors-0/+33
Rollup of 8 pull requests Successful merges: - rust-lang/rust#141724 (fix(rust-lang/rust#141141): When expanding `PartialEq`, check equality of scalar types first.) - rust-lang/rust#141833 (`tests/ui`: A New Order [2/N]) - rust-lang/rust#141861 (Switch `x86_64-msvc-{1,2}` back to Windows Server 2025 images) - rust-lang/rust#141914 (redesign stage 0 std follow-ups) - rust-lang/rust#141918 (Deconstruct values in the THIR visitor) - rust-lang/rust#141923 (Update books) - rust-lang/rust#141931 (Deconstruct values in the THIR visitor) - rust-lang/rust#141956 (Remove two trait methods from cg_ssa) r? `@ghost` `@rustbot` modify labels: rollup
2025-06-03Rollup merge of #141724 - Sol-Ell:issue-141141-fix, r=nnethercoteMatthias Krüger-0/+33
fix(#141141): When expanding `PartialEq`, check equality of scalar types first. Fixes rust-lang/rust#141141. Now, `cs_eq` function of `partial_eq.rs` compares [scalar types](https://doc.rust-lang.org/rust-by-example/primitives.html#scalar-types) first. - Add `is_scalar` field to `FieldInfo`. - Add `is_scalar` method to `TyKind`. - Pass `FieldInfo` via `CsFold::Combine` and refactor code relying on it. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for FloatTy. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for IntTy. - Implement `TryFrom<&str>` and `TryFrom<Symbol>` for UintTy.
2025-06-03Remove `Path::is_ident`.Nicholas Nethercote-13/+9
It checks that a path has a single segment that matches the given symbol, and that there are zero generic arguments. It has a single use. We also have `impl PartialEq<Symbol> for Path` which does exactly the same thing *except* it doesn't check for zero generic arguments, which seems like an oversight. It has numerous uses. This commit removes `Path::is_ident`, adds a test for zero generic arguments to `PartialEq<Symbol> for Path`, and changes the single use of `is_ident` to instead use `==`.
2025-06-02Separately check equality of the scalar types and compound types in the ↵Ell-0/+33
order of declaration.
2025-06-01Add `visit_id` to ast `Visitor`Deadbeef-282/+224
This helps with efforts to deduplicate the `MutVisitor` and the `Visitor` code. All users of `Visitor`'s methods that have extra `NodeId` as parameters really just want to visit the id on its own. Also includes some methods deduplicated and cleaned up as a result of this change.
2025-05-30Rollup merge of #141430 - fee1-dead-contrib:push-nmzoprvtsvww, r=petrochenkovMatthias Krüger-104/+20
remove `visit_clobber` and move `DummyAstNode` to `rustc_expand` `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-29Rollup merge of #141636 - fee1-dead-contrib:push-ntqvvxwuvrvx, r=petrochenkovGuillaume Gomez-26/+26
avoid some usages of `&mut P<T>` in AST visitors It's a double indirection, and is also complicating our efforts at rust-lang/rust#127615. r? `@ghost`
2025-05-29avoid some usages of `&mut P<T>` in AST visitorsDeadbeef-26/+26
2025-05-29remove `visit_clobber` and move `DummyAstNode` to `rustc_expand`Deadbeef-104/+20
`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-29Rollup merge of #141675 - nnethercote:ItemKind-field-order, r=fee1-deadJacob Pratt-14/+12
Reorder `ast::ItemKind::{Struct,Enum,Union}` fields. So they match the order of the parts in the source code, e.g.: ``` struct Foo<T, U> { t: T, u: U } <-><----> <------------> / | \ ident generics variant_data ``` r? `@fee1-dead`
2025-05-28Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.Nicholas Nethercote-14/+12
So they match the order of the parts in the source code, e.g.: ``` struct Foo<T, U> { t: T, u: U } <-><----> <------------> / | \ ident generics variant_data ```
2025-05-27Rollup merge of #141632 - fee1-dead-contrib:push-txmttkxvwqxl, r=oli-obkMatthias Krüger-11/+3
remove `visit_mt` from `ast::mut_visit` doesn't look like anyone is using it.
2025-05-27Rollup merge of #141635 - fee1-dead-contrib:push-lmyymwotrspk, r=oli-obkMichael Goulet-284/+145
further dedup `WalkItemKind` for `mut_visit` and `visit` also some drive-by fixes. r? oli-obk
2025-05-27Remove out-of-date `noop_*` names.Nicholas Nethercote-22/+4
`mut_visit.rs` has a single function with a `noop_` prefix: `noop_filter_map_expr`. This commit renames as `walk_filter_map_expr` which is consistent with other functions in this file. The commit also removes out-of-date comments that refer to `noop_*` methods.
2025-05-27further dedup `WalkItemKind` for `mut_visit` and `visit`Deadbeef-284/+145
also some drive-by fixes.
2025-05-27remove `visit_mt` from `ast::mut_visit`Deadbeef-11/+3
doesn't look like anyone is using it.
2025-05-27Reduce `P<T>` to a typedef of `Box<T>`.Nicholas Nethercote-76/+6
Keep the `P` constructor function for now, to minimize immediate churn. All the `into_inner` calls are removed, which is nice.
2025-05-27Remove unused `P` stuff.Nicholas Nethercote-42/+2
2025-05-27Remove support for `P<[T]>`.Nicholas Nethercote-78/+1
It's no longer used.
2025-05-27Remove the one use of `P<[T]>`.Nicholas Nethercote-1/+1
A `Vec` is fine, the additional word (vector vs. boxed slice) doesn't matter here.
2025-05-27Remove `P::map`.Nicholas Nethercote-15/+3
It's barely used, and the places that use it are better if they don't.
2025-05-27Remove `'static` bounds on `P`.Nicholas Nethercote-4/+4
These date back to 2014. I don't think they're needed any more.
2025-05-26remove eq_unspanned from TokenStreamyukang-7/+3
2025-05-26Fix incorrect eq_unspanned in TokenStreamyukang-8/+2
2025-05-23further deduplicate ast visitor codeDeadbeef-429/+284
2025-05-19introduce common macro for `MutVisitor` and `Visitor` to dedup codeDeadbeef-49/+73
2025-05-18Rollup merge of #140746 - dianne:guard-pat-res, r=oli-obkLeón Orell Valerian Liehr-1/+1
name resolution for guard patterns This PR provides an initial implementation of name resolution for guard patterns [(RFC 3637)](https://github.com/rust-lang/rfcs/blob/master/text/3637-guard-patterns.md). This does not change the requirement that the bindings on either side of an or-pattern must be the same [(proposal here)](https://github.com/rust-lang/rfcs/blob/master/text/3637-guard-patterns.md#allowing-mismatching-bindings-when-possible); the code that handles that is separate from what this PR touches, so I'm saving it for a follow-up. On a technical level, this separates "collecting the bindings in a pattern" (which was already done for or-patterns) from "introducing those bindings into scope". I believe the approach used here can be extended straightforwardly in the future to work with `if let` guard patterns, but I haven't tried it myself since we don't allow those yet. Tracking issue for guard patterns: #129967 cc ``@Nadrieril``
2025-05-18name resolution for guard patternsdianne-1/+1
2025-05-12update cfg(bootstrap)Pietro Albini-1/+0
2025-05-10Remove `AstDeref`.Nicholas Nethercote-50/+30
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-05-03Implement asymmetrical precedence for closures and jumpsDavid Tolnay-5/+10
2025-05-02Add useful comments on `ExprKind::If` variants.Nicholas Nethercote-0/+3
Things that aren't obvious and took me a while to work out.
2025-04-30ast: Remove token visiting from AST visitorVadim Petrochenkov-123/+16
It's no longer necessary after the removal of nonterminal tokens in #124141.
2025-04-30Auto merge of #127516 - nnethercote:simplify-LazyAttrTokenStream, r=petrochenkovbors-18/+369
Simplify `LazyAttrTokenStream` `LazyAttrTokenStream` is an unpleasant type: `Lrc<Box<dyn ToAttrTokenStream>>`. Why does it look like that? - There are two `ToAttrTokenStream` impls, one for the lazy case, and one for the case where we already have an `AttrTokenStream`. - The lazy case (`LazyAttrTokenStreamImpl`) is implemented in `rustc_parse`, but `LazyAttrTokenStream` is defined in `rustc_ast`, which does not depend on `rustc_parse`. The use of the trait lets `rustc_ast` implicitly depend on `rustc_parse`. This explains the `dyn`. - `LazyAttrTokenStream` must have a `size_of` as small as possible, because it's used in many AST nodes. This explains the `Lrc<Box<_>>`, which keeps it to one word. (It's required `Lrc<dyn _>` would be a fat pointer.) This PR moves `LazyAttrTokenStreamImpl` (and a few other token stream things) from `rustc_parse` to `rustc_ast`. This lets us replace the `ToAttrTokenStream` trait with a two-variant enum and also remove the `Box`, changing `LazyAttrTokenStream` to `Lrc<LazyAttrTokenStreamInner>`. Plus it does a few cleanups. r? `@petrochenkov`
2025-04-30Use `ThinVec` to shrink `LazyAttrTokenStreamInner`.Nicholas Nethercote-3/+4
2025-04-30Simplify `LazyAttrTokenStream`.Nicholas Nethercote-96/+121
This commit does the following. - Changes it from `Lrc<Box<dyn ToAttrTokenStream>>` to `Lrc<LazyAttrTokenStreamInner>`. - Reworks `LazyAttrTokenStreamImpl` as `LazyAttrTokenStreamInner`, which is a two-variant enum. - Removes the `ToAttrTokenStream` trait and the two impls of it. The recursion limit must be increased in some crates otherwise rustdoc aborts.
2025-04-29Move various token stream things from `rustc_parse` to `rustc_ast`.Nicholas Nethercote-1/+326
Specifically: `TokenCursor`, `TokenTreeCursor`, `LazyAttrTokenStreamImpl`, `FlatToken`, `make_attr_token_stream`, `ParserRange`, `NodeRange`. `ParserReplacement`, and `NodeReplacement`. These are all related to token streams, rather than actual parsing. This will facilitate the simplifications in the next commit.