about summary refs log tree commit diff
path: root/src/librustdoc/clean
AgeCommit message (Collapse)AuthorLines
2025-05-30Rollup merge of #141746 - Urgau:rework-doc_cfg-checks, r=GuillaumeGomezMatthias Krüger-44/+4
Rework `#[doc(cfg(..))]` checks as distinct pass in rustdoc This PR reworks how rustdoc calls `rustc_attr_parsing::cfg_matches` to be in a separate pass, instead of being wired-up in a ad-hoc way, which is causing problems in https://github.com/rust-lang/rust/pull/138907#issuecomment-2920026627. This un-does most part of https://github.com/rust-lang/rust/pull/140894, but the result is IMO much cleaner, easier to reason about, and most importantly no longer interfears with rust-lang/rust#138907. r? `@GuillaumeGomez`
2025-05-30Auto merge of #141573 - nnethercote:rustdoc-alloc-cleanups, r=camelidbors-14/+8
rustdoc: cleanups relating to allocations These commits generally clean up the code a bit and also reduce allocation rates a bit. r? `@camelid`
2025-05-30Rollup merge of #141747 - lolbinarycat:rustdoc-cfg-138112, r=GuillaumeGomezMatthias Krüger-3/+12
rustdoc: display doc(cfg(false)) properly before we had an extra 'on' that was ungramatical. fixes https://github.com/rust-lang/rust/issues/138112 this is what it looks like now: ![screenshot: Available nowhere](https://github.com/user-attachments/assets/e27b4990-09a7-4f13-8bcf-26d44c8c1bea)
2025-05-29rustdoc: display doc(cfg(false)) properlybinarycat-3/+12
before we had an extra 'on' that was ungramatical. fixes https://github.com/rust-lang/rust/issues/138112
2025-05-29Rework `#[doc(cfg(..))]` checks as distinct pass in rustdocUrgau-44/+4
2025-05-30Reorder fields in `hir::ItemKind` variants.Nicholas Nethercote-9/+9
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match the textual order in the source code. The interesting part of the change is in `compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical refactoring.
2025-05-27Rollup merge of #140894 - Urgau:check-cfg-rustdoc, r=GuillaumeGomezTrevor Gross-5/+39
Make check-cfg diagnostics work in `#[doc(cfg(..))]` This PR makes it so that the check-cfg `unexpected_cfgs` lint, is correctly emitted in `rustdoc`'s `#[doc(cfg(..))]`. This is achieved by adding a custom trait to `cfg_matches` (the method that emits the lint) which permits `rustc` and `rustdoc` to each have their way to emitting lints (via buffered lints/AST for `rustc` and via `TyCtxt`/HIR for `rustdoc`). The reason this is required is because buffered lints operates on the AST but `rustdoc` uses the HIR and by the time `rustdoc` calls `cfg_matches` we are way passed the point where buffered lints have been drain and emitted. Best reviewed commit by commit. r? `@jieyouxu` (for the compiler part) r? `@GuillaumeGomez` (for the rustdoc part)
2025-05-27Rename unpack to kindMichael Goulet-3/+3
2025-05-26rustdoc: use custom `CfgMatchesLintEmitter` to make check-cfg workUrgau-5/+39
2025-05-26Avoid some unnecessary cloning.Nicholas Nethercote-1/+1
2025-05-26Make `{Type,Path}::generics` return iterators.Nicholas Nethercote-13/+7
Instead of a `Vec`, to avoid some allocations.
2025-05-25Update to new APIGuillaume Gomez-1/+1
2025-05-25Improve codeGuillaume Gomez-5/+6
2025-05-25Tweak attribute rendering depending on wether or not it is a type aliasGuillaume Gomez-61/+68
2025-05-25Split `Item::attributes` method into threeGuillaume Gomez-67/+78
2025-05-25Unify rendering of type aliases without ADT itemsGuillaume Gomez-0/+13
2025-05-25Rename `clean::Enum::variants` method into `non_stripped_variants`Guillaume Gomez-1/+1
2025-05-23Rollup merge of #141369 - ↵Matthias Krüger-72/+23
yotamofek:pr/rustdoc/format_integer_with_underscore_sep, r=notriddle Simplify `format_integer_with_underscore_sep` Noticed that this helper fn only ever gets called with decimal-base-formatted ints, so can be simplified a lot by not trying to handle hex and octal radixes. Second commit is completely unrelated, just simplified some code I wrote a while back 😁
2025-05-23Small cleanup for `qpath_to_string`Yotam Ofek-9/+2
2025-05-23Simplify `format_integer_with_underscore_sep`Yotam Ofek-63/+21
Only ever needs to handle decimal reprs
2025-05-22rustdoc JSON: Don't apply `#[repr]` privacy heuristicsLeón Orell Valerian Liehr-15/+7
2025-05-19Rollup merge of #140874 - mejrs:rads, r=WaffleLapkinStuart Cook-6/+8
make `rustc_attr_parsing` less dominant in the rustc crate graph It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly. Previous graph: ![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd) Graph with this PR: ![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a) The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*. The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-18Remove rustc_attr_data_structures re-export from rustc_attr_parsingmejrs-6/+8
2025-05-17Make some `match`es slightly more ergonomic in `librustdoc`Yotam Ofek-56/+50
2025-05-09Remove `Ident::empty`.Nicholas Nethercote-1/+1
All uses have been removed. And it's nonsensical: an identifier by definition has at least one char. The commits adds an is-non-empty assertion to `Ident::new` to enforce this, and converts some `Ident` constructions to use `Ident::new`. Adding the assertion requires making `Ident::new` and `Ident::with_dummy_span` non-const, which is no great loss. The commit amends a couple of places that do path splitting to ensure no empty identifiers are created.
2025-05-07rustdoc-json: Remove newlines from attributesAlona Enraght-Moony-1/+5
2025-04-28Rollup merge of #140316 - nnethercote:BoxMarker, r=dtolnayGuillaume Gomez-4/+4
Introduce `BoxMarker` to improve pretty-printing correctness Box opening/closing is really easy to get wrong in the pretty-printers. This PR makes it much harder to get wrong. r? `@Urgau`
2025-04-28Introduce `BoxMarker` to pretty-printing.Nicholas Nethercote-4/+4
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-24Remove `weak` alias terminologyBoxy-2/+2
2025-04-22Auto merge of #139897 - nnethercote:rm-OpenDelim-CloseDelim, r=petrochenkovbors-2/+2
Remove `token::{Open,Close}Delim` 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 { ``` r? `@petrochenkov`
2025-04-21Remove `token::{Open,Close}Delim`.Nicholas Nethercote-2/+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-04-19Rollup merge of #140008 - GuillaumeGomez:cleanup-clean_maybe_renamed_item, ↵Chris Denton-14/+33
r=nnethercote Improve `clean_maybe_renamed_item` function code a bit Follow-up of #139846. This is what I tried to say in there: the `name` variable can be unwrapped in most cases so better do it directly once and for all if possible and move the cases where it's not possible above. r? `@nnethercote`
2025-04-18Improve `clean_maybe_renamed_item` function code a bitGuillaume Gomez-14/+33
2025-04-18Rollup merge of #139913 - fmease:rustdoc-fix-fn-param-handling, r=GuillaumeGomezMatthias Krüger-121/+92
rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions) **(0)** PR #136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional. **(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two: ```rs pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32); unsafe extern "C" { pub fn foreign_fn(_: i32); } // Since 1.86 the fns above gets mis-rendered as: pub fn assoc_fn(: i32) // <-- BUTCHERED pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED ``` **(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of #44306 I once fixed in PR #103885. **(1)** Lastly, PR #139035 introduced an ICE triggered by the following input file: ```rs trait Trait { fn anon(()) {} } // internal error: entered unreachable code ``` --- This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible. ~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC #137978.~~ Independently done in PR #139846 a day prior.
2025-04-18Rollup merge of #139615 - nnethercote:rm-name_or_empty, r=jdonszelmannMatthias Krüger-1/+1
Remove `name_or_empty` Another step towards #137978. r? ``@jdonszelmann``
2025-04-17Rollup merge of #139943 - fmease:rustdoc-ixcre-trait-aliases, r=GuillaumeGomezMatthias Krüger-21/+22
rustdoc: Support inlined cross-crate re-exported trait aliases Previously we'd just drop them. As a result of this PR, [`core::ptr::Thin`](https://doc.rust-lang.org/nightly/core/ptr/traitalias.Thin.html) will be admitted into the `std` façade! Also, render the where clause *after* the bounds / the `=`, not before them, as it should be. r? rustdoc
2025-04-17rustdoc: Properly clean fn params in all contextsLeón Orell Valerian Liehr-35/+32
2025-04-17rustdoc/clean: Change terminology of items pertaining to (formal) fn params ↵León Orell Valerian Liehr-96/+70
from "argument" to "parameter"
2025-04-17Support inlined cross-crate re-exported trait aliasesLeón Orell Valerian Liehr-21/+22
2025-04-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-1/+1
I'm removing empty identifiers everywhere, because in practice they always mean "no identifier" rather than "empty identifier". (An empty identifier is impossible.) It's better to use `Option` to mean "no identifier" because you then can't forget about the "no identifier" possibility. Some specifics: - When testing an attribute for a single name, the commit uses the `has_name` method. - When testing an attribute for multiple names, the commit uses the new `has_any_name` method. - When using `match` on an attribute, the match arms now have `Some` on them. In the tests, we now avoid printing empty identifiers by not printing the identifier in the `error:` line at all, instead letting the carets point out the problem.
2025-04-17Rollup merge of #139846 - nnethercote:kw-Empty-rustdoc, r=GuillaumeGomezMatthias Krüger-29/+35
Remove `kw::Empty` uses in rustdoc Helps with #137978. r? ``@GuillaumeGomez``
2025-04-15Rollup merge of #138455 - yotamofek:pr/rustdoc/more-impl-display, ↵Matthias Krüger-1/+1
r=GuillaumeGomez `librustdoc`: more `impl fmt::Display` Continuation of #137425 and #136828 and #136784 Working towards getting rid of the `write_str` helper r? `@GuillaumeGomez` (if you want!)
2025-04-15Avoid another `kw::Empty` use.Nicholas Nethercote-1/+1
`sym::dummy` also appears to work.
2025-04-15Remove another `kw::Empty` use in rustdoc.Nicholas Nethercote-18/+21
Again by using `Option<Symbol>` to represent "no name".
2025-04-15Remove some `kw::Empty` uses in rustdoc.Nicholas Nethercote-16/+19
Some `unwrap` uses here, but they are on paths involving item kinds that are known to have an identifier.
2025-04-15Move `name` field from `AssocItem` to `AssocKind` variants.Nicholas Nethercote-7/+7
To accurately reflect that RPITIT assoc items don't have a name. This avoids the use of `kw::Empty` to mean "no name", which is error prone. Helps with #137978.
2025-04-15Move `opt_rpitit_info` field to `hir::AssocKind::Type`.Nicholas Nethercote-1/+1
From `hir::AssocItem`.
2025-04-14Move `has_self` field to `hir::AssocKind::Fn`.Nicholas Nethercote-8/+8
`hir::AssocItem` currently has a boolean `fn_has_self_parameter` field, which is misplaced, because it's only relevant for associated fns, not for associated consts or types. This commit moves it (and renames it) to the `AssocKind::Fn` variant, where it belongs. This requires introducing a new C-style enum, `AssocTag`, which is like `AssocKind` but without the fields. This is because `AssocKind` values are passed to various functions like `find_by_ident_and_kind` to indicate what kind of associated item should be searched for, and having to specify `has_self` isn't relevant there. New methods: - Predicates `AssocItem::is_fn` and `AssocItem::is_method`. - `AssocItem::as_tag` which converts `AssocItem::kind` to `AssocTag`. Removed `find_by_name_and_kinds`, which is unused. `AssocItem::descr` can now distinguish between methods and associated functions, which slightly improves some error messages.
2025-04-10make `link_tooltip` return `impl fmt::Display`Yotam Ofek-1/+1
2025-04-10Rollup merge of #139510 - nnethercote:name-to-ident, r=fee1-deadMatthias Krüger-14/+14
Rename some `name` variables as `ident`. It bugs me when variables of type `Ident` are called `name`. It leads to silly things like `name.name`. `Ident` variables should be called `ident`, and `name` should be used for variables of type `Symbol`. This commit improves things by by doing `s/name/ident/` on a bunch of `Ident` variables. Not all of them, but a decent chunk. r? `@fee1-dead`