about summary refs log tree commit diff
path: root/compiler/rustc_ast_pretty/src/pprust/state/item.rs
AgeCommit message (Collapse)AuthorLines
2025-08-11Extract ast TraitImplHeaderCameron Steffen-27/+29
2025-08-09remove `P`Deadbeef-3/+2
2025-07-17parse `const trait Trait`Deadbeef-0/+2
2025-06-12Introduce `-Zmacro-stats`.Nicholas Nethercote-2/+2
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. Details: - It measures code snippets by pretty-printing them and then measuring lines and bytes. This required a bunch of additional pretty-printing plumbing, in `rustc_ast_pretty` and `rustc_expand`. - The measurement is done in `MacroExpander::expand_invoc`. - The measurements are stored in `ExtCtxt::macro_stats`.
2025-05-28Reorder `ast::ItemKind::{Struct,Enum,Union}` fields.Nicholas Nethercote-4/+4
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-04Initial support for dynamically linked cratesBryanskiy-0/+11
2025-04-28Inline and remove three pretty-printer methods.Nicholas Nethercote-42/+22
They all have a single call site, aren't that big, and removing them avoids having to pass some `BoxMarker`s.
2025-04-28Introduce `BoxMarker` to pretty-printing.Nicholas Nethercote-61/+69
The pretty-printers open and close "boxes" of text a lot. The open and close operations must be matched. The matching is currently all implicit and very easy to get wrong. (#140280 and #140246 are two recent pretty-printing fixes that both involved unclosed boxes.) This commit introduces `BoxMarker`, a marker type that represents an open box. It makes box opening/closing explicit, which makes it much easier to understand and harder to get wrong. The commit also removes many comments are on `end` calls saying things like "end outer head-block", "Close the outer-box". These demonstrate how confusing the implicit approach was, but aren't necessary any more.
2025-04-01Move `ast::Item::ident` into `ast::ItemKind`.Nicholas Nethercote-41/+42
`ast::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, `Trait`, `TraitAlias`, `MacroDef`, `Delegation`. - It's always empty for these item kinds: `Use`, `ForeignMod`, `GlobalAsm`, `Impl`, `MacCall`, `DelegationMac`. There is a similar story for `AssocItemKind` and `ForeignItemKind`. Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. The commit is large but it's mostly obvious plumbing work. Some notable things. - `ast::Item` got 8 bytes bigger. This could be avoided by boxing the fields within some of the `ast::ItemKind` variants (specifically: `Struct`, `Union`, `Enum`). I might do that in a follow-up; this commit is big enough already. - For the visitors: `FnKind` no longer needs an `ident` field because the `Fn` within how has one. - In the parser, the `ItemInfo` typedef is no longer needed. It was used in various places to return an `Ident` alongside an `ItemKind`, but now the `Ident` (if present) is within the `ItemKind`. - In a few places I renamed identifier variables called `name` (or `foo_name`) as `ident` (or `foo_ident`), to better match the type, and because `name` is normally used for `Symbol`s. It's confusing to see something like `foo_name.name`.
2025-03-25Allow defining opaques in statics and constsMichael Goulet-20/+45
2025-03-25Make printing define_opaque less goofyMichael Goulet-7/+19
2025-03-11Implement `#[define_opaque]` attribute for functions.Oli Scherer-2/+11
2025-03-01Implment `#[cfg]` and `#[cfg_attr]` in `where` clausesFrank King-1/+2
2025-02-03Express contracts as part of function header and lower it to the contract ↵Celina G. Val-1/+20
lang items includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
2025-01-28Refactor FnKind variant to hold &FnCelina G. Val-19/+9
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-1/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-4/+7
2024-10-24Print safety correctly in extern static itemsMichael Goulet-1/+6
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-2/+2
2024-08-07Use more slice patterns inside the compilerLeón Orell Valerian Liehr-2/+2
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-20StaticForeignItem and StaticItem are the sameMichael Goulet-6/+1
2024-06-14delegation: Implement glob delegationVadim Petrochenkov-19/+32
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-1/+2
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-1/+7
2024-05-17Rename Unsafe to SafetySantiago Pastorino-7/+7
2024-05-15delegation: Implement list delegationVadim Petrochenkov-14/+60
```rust reuse prefix::{a, b, c} ```
2024-05-08Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=NilstriebMatthias Krüger-2/+2
Remove braces when fixing a nested use tree into a single item [Back in 2019](https://github.com/rust-lang/rust/pull/56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`. This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then. A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`. This PR is best reviewed commit-by-commit.
2024-05-03AST pretty: Use `builtin_syntax` for type ascriptionLeón Orell Valerian Liehr-0/+1
2024-04-29Add StaticForeignItem and use it on ForeignItemKindSantiago Pastorino-9/+11
2024-04-19Move pretty-printer FixupContext to a moduleDavid Tolnay-1/+1
Required for being able to make the fields private and force the use of accessor methods, which will be added in the next commit.
2024-04-14store the span of the nested part of the use tree in the astPietro Albini-2/+2
2024-02-29AST: Refactor type alias where clausesLeón Orell Valerian Liehr-11/+4
2024-01-12Delegation implementation: step 1Bryanskiy-0/+31
2023-12-22Rid the AST & HIR pretty printers of syntactic cruftLeón Orell Valerian Liehr-15/+2
2023-12-22Auto merge of #119163 - fmease:refactor-ast-trait-bound-modifiers, ↵bors-3/+5
r=compiler-errors Refactor AST trait bound modifiers Instead of having two types to represent trait bound modifiers in the parser / the AST (`parser::ty::BoundModifiers` & `ast::TraitBoundModifier`), only to map one to the other later, just use `parser::ty::BoundModifiers` (moved & renamed to `ast::TraitBoundModifiers`). The struct type is more extensible and easier to deal with (see [here](https://github.com/rust-lang/rust/pull/119099/files#r1430749981) and [here](https://github.com/rust-lang/rust/pull/119099/files#r1430752116) for context) since it more closely models what it represents: A compound of two kinds of modifiers, constness and polarity. Modeling this as an enum (the now removed `ast::TraitBoundModifier`) meant one had to add a new variant per *combination* of modifier kind, which simply isn't scalable and which lead to a lot of explicit non-DRY matches. NB: `hir::TraitBoundModifier` being an enum is fine since HIR doesn't need to worry representing invalid modifier kind combinations as those get rejected during AST validation thereby immensely cutting down the number of possibilities.
2023-12-20Refactor AST trait bound modifiersLeón Orell Valerian Liehr-3/+5
2023-12-20Give `VariantData::Struct` named fields, to clairfy `recovered`.Alona Enraght-Moony-1/+1
2023-12-08Do not parenthesize exterior struct lit inside match guardsDavid Tolnay-2/+3
2023-11-22Auto merge of #117928 - nnethercote:rustc_ast_pretty, r=fee1-deadbors-7/+8
`rustc_ast_pretty` cleanups Some improvements I found while looking at this code. r? `@fee1-dead`
2023-11-22Remove or downgrade unnecessary `pub` visibility markers.Nicholas Nethercote-4/+4
2023-11-22Remove `IterDelimited`.Nicholas Nethercote-3/+4
itertools has `with_position` which does the same thing.
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-1/+1
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-08-24Parse unnamed fields and anonymous structs or unionsFrank King-1/+5
Anonymous structs or unions are only allowed in struct field definitions. Co-authored-by: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com>
2023-07-28Parse generic const itemsLeón Orell Valerian Liehr-9/+26
2023-06-15Fix suggestion for E0404 not dealing with multiple generics许杰友 Jieyou Xu (Joe)-13/+15
2023-04-04Rename `ast::Static` to `ast::StaticItem` to match `ast::ConstItem`Oli Scherer-2/+2
2023-04-04box a bunch of large typesOli Scherer-3/+3
2023-04-04Split out ast::ItemKind::Const into its own structOli Scherer-4/+11
2023-04-04rust-analyzer guided tuple field to named fieldOli Scherer-1/+1