about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/ast.rs
AgeCommit message (Collapse)AuthorLines
2025-09-29Use `Iterator::eq` and (dogfood) `eq_by` in compiler and libraryYotam Ofek-2/+1
2025-09-09c-variadic: reject functions with unsupported extern ABIFolkert de Vries-0/+5
2025-09-09c-variadic: reject non-unsafe functionsFolkert de Vries-0/+23
2025-09-08Refactor how to get the span of a function headerFolkert de Vries-36/+31
2025-08-25add span to struct pattern rest (..)Valdemar Erk-3/+3
2025-08-19Prevent impossible combinations in `ast::ModKind`.Nicholas Nethercote-2/+2
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`. This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
2025-08-11Extract ast TraitImplHeaderCameron Steffen-8/+13
2025-08-09remove `P`Deadbeef-166/+165
2025-07-31Deduplicate `IntTy`/`UintTy`/`FloatTy`.Nicholas Nethercote-100/+1
There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed. The one annoying wrinkle is that the old version had differences in their `Debug` impls, e.g. one printed `u32` while the other printed `U32`. Some compiler error messages rely on the former (yuk), and some clippy output depends on the latter. So the commit also changes clippy to not rely on `Debug` and just implement what it needs itself.
2025-07-26Don't lint against named labels in `naked_asm!`Amanieu d'Antras-1/+1
Naked functions are allowed to define global labels, just like `global_asm!`.
2025-07-22Implement AST visitors using a derive macro.Camille GILLOT-136/+149
2025-07-17parse `const trait Trait`Deadbeef-0/+1
2025-07-17Improve path segment joining.Nicholas Nethercote-1/+54
There are many places that join path segments with `::` to produce a string. A lot of these use `join("::")`. Many in rustdoc use `join_with_double_colon`, and a few use `.joined("..")`. One in Clippy uses `itertools::join`. A couple of them look for `kw::PathRoot` in the first segment, which can be important. This commit introduces `rustc_ast::join_path_{syms,ident}` to do the joining for everyone. `rustc_ast` is as good a location for these as any, being the earliest-running of the several crates with a `Path` type. Two functions are needed because `Ident` printing is more complex than simple `Symbol` printing. The commit also removes `join_with_double_colon`, and `estimate_item_path_byte_length` with it. There are still a handful of places that join strings with "::" that are unchanged. They are not that important: some of them are in tests, and some of them first split a path around "::" and then rejoin with "::". This fixes one test case where `{{root}}` shows up in an error message.
2025-07-06compiler: rename {ast,hir}::BareFn* to FnPtr*Jubilee Young-3/+3
Fix some comments and related types and locals where it is obvious, e.g. - bare_fn -> fn_ptr - LifetimeBinderKind::BareFnType -> LifetimeBinderKind::FnPtrType Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2025-07-04Rollup merge of #143380 - cjgillot:kw_span, r=compiler-errorsJacob Pratt-6/+3
Replace kw_span by full span for generic const parameters. Small simplification extracted from https://github.com/rust-lang/rust/pull/127241
2025-07-03Replace kw_span by full span.Camille GILLOT-6/+3
2025-07-03Rollup merge of #134006 - klensy:typos, r=nnethercoteJana Dönszelmann-1/+1
setup typos check in CI This allows to check typos in CI, currently for compiler only (to reduce commit size with fixes). With current setup, exclude list is quite short, so it worth trying? Also includes commits with actual typo fixes. MCP: https://github.com/rust-lang/compiler-team/issues/817 typos check currently turned for: * ./compiler * ./library * ./src/bootstrap * ./src/librustdoc After merging, PRs which enables checks for other crates (tools) can be implemented too. Found typos will **not break** other jobs immediately: (tests, building compiler for perf run). Job will be marked as red on completion in ~ 20 secs, so you will not forget to fix it whenever you want, before merging pr. Check typos: `python x.py test tidy --extra-checks=spellcheck` Apply typo fixes: `python x.py test tidy --extra-checks=spellcheck:fix` (in case if there only 1 suggestion of each typo) Current fail in this pr is expected and shows how typo errors emitted. Commit with error will be removed after r+.
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-07-02Rollup merge of #142237 - benschulz:unused-parens-fn, r=fee1-deadMatthias Krüger-0/+14
Detect more cases of unused_parens around types With this change, more unused parentheses around bounds and types nested within bounds are detected.
2025-07-01Remove support for dyn*Michael Goulet-4/+2
2025-07-01Detect more cases of unused_parens around typesBenjamin Schulz-0/+14
2025-06-30Introduce `ByteSymbol`.Nicholas Nethercote-10/+18
It's like `Symbol` but for byte strings. The interner is now used for both `Symbol` and `ByteSymbol`. E.g. if you intern `"dog"` and `b"dog"` you'll get a `Symbol` and a `ByteSymbol` with the same index and the characters will only be stored once. The motivation for this is to eliminate the `Arc`s in `ast::LitKind`, to make `ast::LitKind` impl `Copy`, and to avoid the need to arena-allocate `ast::LitKind` in HIR. The latter change reduces peak memory by a non-trivial amount on literal-heavy benchmarks such as `deep-vector` and `tuple-stress`. `Encoder`, `Decoder`, `SpanEncoder`, and `SpanDecoder` all get some changes so that they can handle normal strings and byte strings. This change does slow down compilation of programs that use `include_bytes!` on large files, because the contents of those files are now interned (hashed). This makes `include_bytes!` more similar to `include_str!`, though `include_bytes!` contents still aren't escaped, and hashing is still much cheaper than escaping.
2025-06-27Rollup merge of #139858 - oli-obk:new-const-traits-syntax, r=fee1-deadMatthias Krüger-3/+3
New const traits syntax This PR only affects the AST and doesn't actually change anything semantically. All occurrences of `~const` outside of libcore have been replaced by `[const]`. Within libcore we have to wait for rustfmt to be bumped in the bootstrap compiler. This will happen "automatically" (when rustfmt is run) during the bootstrap bump, as rustfmt converts `~const` into `[const]`. After this we can remove the `~const` support from the parser Caveat discovered during impl: there is no legacy bare trait object recovery for `[const] Trait` as that snippet in type position goes down the slice /array parsing code and will error r? ``@fee1-dead`` cc ``@nikomatsakis`` ``@traviscross`` ``@compiler-errors``
2025-06-26Change const trait bound syntax from ~const to [const]Oli Scherer-3/+3
2025-06-25make `tidy-alphabetical` use a natural sortFolkert de Vries-1/+1
2025-06-24Rollup merge of #135731 - frank-king:feature/pin-borrow, r=eholk,traviscrossJubilee-0/+4
Implement parsing of pinned borrows This PR implements part of #130494. EDIT: It introduces `&pin mut $place` and `&pin const $place` as sugars for `std::pin::pin!($place)` and its shared reference equivalent, except that `$place` will not be moved when borrowing. The borrow check will be in charge of enforcing places cannot be moved or mutably borrowed since being pinned till dropped. ### Implementation steps: - [x] parse the `&pin mut $place` and `&pin const $place` syntaxes - [ ] borrowck of `&pin mut|const` - [ ] support autoref of `&pin mut|const` when needed
2025-06-17Rollup merge of #142371 - fee1-dead-contrib:push-xqlkumzurkus, r=petrochenkovJacob Pratt-4/+22
avoid `&mut P<T>` in `visit_expr` etc methods trying a different way than rust-lang/rust#141636 r? ghost
2025-06-15Implement pinned borrows, part of `pin_ergonomics`Frank King-0/+4
2025-06-13Reduce precedence of expressions that have an outer attrDavid Tolnay-4/+13
2025-06-13Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgrbors-0/+32
Rollup of 9 pull requests Successful merges: - rust-lang/rust#128425 (Make `missing_fragment_specifier` an unconditional error) - rust-lang/rust#135927 (retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features) - rust-lang/rust#140770 (add `extern "custom"` functions) - rust-lang/rust#142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches) - rust-lang/rust#142248 (Add supported asm types for LoongArch32) - rust-lang/rust#142267 (assert more in release in `rustc_ast_lowering`) - rust-lang/rust#142274 (Update the stdarch submodule) - rust-lang/rust#142276 (Update dependencies in `library/Cargo.lock`) - rust-lang/rust#142308 (Upgrade `object`, `addr2line`, and `unwinding` in the standard library) Failed merges: - rust-lang/rust#140920 (Extract some shared code from codegen backend target feature handling) r? `@ghost` `@rustbot` modify labels: rollup try-job: aarch64-apple try-job: x86_64-msvc-1 try-job: x86_64-gnu try-job: dist-i586-gnu-i586-i686-musl try-job: test-various
2025-06-13Rollup merge of #142069 - nnethercote:Zmacro-stats, r=petrochenkovMatthias Krüger-2/+19
Introduce `-Zmacro-stats` Introduce `-Zmacro-stats`. It collects data about macro expansions and prints them in a table after expansion finishes. It's very useful for detecting macro bloat, especially for proc macros. r? `@petrochenkov`
2025-06-13Rollup merge of #134847 - dtolnay:asymmetrical, r=fmeaseMatthias Krüger-5/+10
Implement asymmetrical precedence for closures and jumps I have been through a series of asymmetrical precedence designs in Syn, and finally have one that I like and is worth backporting into rustc. It is based on just 2 bits of state: `next_operator_can_begin_expr` and `next_operator_can_continue_expr`. Asymmetrical precedence is the thing that enables `(return 1) + 1` to require parentheses while `1 + return 1` does not, despite `+` always having stronger precedence than `return` [according to the Rust Reference](https://doc.rust-lang.org/1.83.0/reference/expressions.html#expression-precedence). This is facilitated by `next_operator_can_continue_expr`. Relatedly, it is the thing that enables `(return) - 1` to require parentheses while `return + 1` does not, despite `+` and `-` having exactly the same precedence. This is facilitated by `next_operator_can_begin_expr`. **Example:** ```rust macro_rules! repro { ($e:expr) => { $e - $e; $e + $e; }; } fn main() { repro!{return} repro!{return 1} } ``` `-Zunpretty=expanded` **Before:** ```console fn main() { (return) - (return); (return) + (return); (return 1) - (return 1); (return 1) + (return 1); } ``` **After:** ```console fn main() { (return) - return; return + return; (return 1) - return 1; (return 1) + return 1; } ```
2025-06-12add `extern "custom"` functionsFolkert de Vries-0/+32
2025-06-12avoid `&mut P<T>` in `visit_expr` etc methodsDeadbeef-4/+22
2025-06-12Add some useful `Path`/`PathSegment` equality operations.Nicholas Nethercote-2/+19
They will be used in a subsequent commit.
2025-06-06Rollup merge of #141603 - nnethercote:reduce-P, r=fee1-deadGuillaume Gomez-5/+4
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-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-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-05-30Rollup merge of #141430 - fee1-dead-contrib:push-nmzoprvtsvww, r=petrochenkovMatthias Krüger-1/+14
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-29remove `visit_clobber` and move `DummyAstNode` to `rustc_expand`Deadbeef-1/+14
`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-28Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.Nicholas Nethercote-11/+9
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-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-4/+3
It's barely used, and the places that use it are better if they don't.
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-10Remove `AstDeref`.Nicholas Nethercote-2/+1
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.