Commit graph

763 commits

Author SHA1 Message Date
Stuart Cook
1367126837
Rollup merge of #151783 - mu001999-contrib:impl/final-method, r=fee1-dead
Implement RFC 3678: Final trait methods

Tracking: https://github.com/rust-lang/rust/issues/131179

This PR is based on rust-lang/rust#130802, with some minor changes and conflict resolution.

Futhermore, this PR excludes final methods from the vtable of a dyn Trait.

And some excerpt from the original PR description:
> Implements the surface part of https://github.com/rust-lang/rfcs/pull/3678.
>
> I'm using the word "method" in the title, but in the diagnostics and the feature gate I used "associated function", since that's more accurate.

cc @joshtriplett
2026-02-17 13:02:21 +11:00
binarycat
dca86a9521 rustdoc: sort stable items first 2026-02-13 14:44:41 -06:00
mu001999
f0a019bf90 Render final associated functions correctly in rustdoc
Co-authored-by: Michael Goulet <michael@errs.io>
2026-02-12 15:18:15 +08:00
neo
b4c4d95950 rustdoc: render doc(hidden) as a code attribute
Move `#[doc(hidden)]` into the shared code-attribute renderer so it
matches the styling and placement of other attributes in rustdoc HTML.
2026-01-22 09:15:53 +09:00
Stuart Cook
88df8fd3ef
Rollup merge of #151091 - hide-deprecated-items, r=lolbinarycat
Add new "hide deprecated items" setting in rustdoc

This PR adds a new JS setting which allows the JS to hide deprecated items. This is especially useful for crates like `std` which accumulates deprecated items but never removes them.

Nicely enough, the "deprecation" information was already in the search index, meaning I didn't need to change anything there. Before this PR, it was only used to make the deprecated items rank lower. Well now it's also used to generate an extra CSS class, allowing the JS setting to work.

This is taking over https://github.com/rust-lang/rust/pull/149551.

This feature got approved by the rustdoc team in the [meeting of december](https://rust-lang.zulipchat.com/#narrow/channel/393423-t-rustdoc.2Fmeetings/topic/2025-12-08/near/562553156).

You can give it a try [here](https://rustdoc.crud.net/imperio/hide-deprecated-items/foo/index.html).

r? @lolbinarycat
2026-01-20 18:00:09 +11:00
Guillaume Gomez
9e5e432662 Simplify IndexItem::deprecation field: since we only need a boolean value in the end, no need to keep it around. Also: takes into account "is_in_effect" 2026-01-19 23:10:20 +01:00
León Orell Valerian Liehr
ac8e8505b7
rustdoc: Stop unconditionally evaluating the initializer of associated consts 2026-01-17 12:12:36 +01:00
Guillaume Gomez
4ded6397b3 Add new "hide deprecated items" setting in rustdoc 2026-01-14 22:08:33 +01:00
Folkert de Vries
3be74a7441
render intra-doc links in the #[deprectated] note 2026-01-08 11:35:33 +01:00
Folkert de Vries
64c78f6e74
make MarkdownItemInfo a field struct 2026-01-08 11:33:31 +01:00
Urgau
fb7ab6de16 Adapt rustdoc to the overhauled filename handling 2025-12-12 07:34:51 +01:00
Matthias Krüger
d6966fa15a
Rollup merge of #149274 - GuillaumeGomez:tyalias-method-link, r=lolbinarycat
Fix invalid link generation for type alias methods

Fixes https://github.com/rust-lang/rust/issues/149205.

That one was quite the wild ride. First commit is the actual fix, the second commit is just a small name variable improvement while I was going through the code. Anyway, let's go through it:

 * We don't generate directly implementations in the HTML files for local impls (which I think is a mistake and should be changed, gonna do that as a follow-up) but instead generate a JS file for each type alias containing the HTML for these impls.
 * So in `write_shared.rs::TypeAliasPart::get`, when generating the JS file, we generate the impl into a `String` by calling `render_impl`. This method expects an `AssocItemLink` to help it generate the correct link to the item (I'm planning to also remove this enum because it's yet another way to generate anchors/hrefs).
 * Problem was: we call the `provided_trait_methods` method on the impl item... which is empty if not a trait impl. This becomes an issue when we arrive in `render::assoc_href_attr` because of this code:
     ```rust
            AssocItemLink::GotoSource(did, provided_methods) => {
                let item_type = match item_type {
                    ItemType::Method | ItemType::TyMethod => {
                        if provided_methods.contains(&name) {
                            ItemType::Method
                        } else {
                            ItemType::TyMethod
                        }
                    }
                    item_type => item_type,
                };
                // ...
            }
    ```

     Since `provided_methods` is always empty, it means all methods on type aliases will be `TyMethod`, generating `#tymethod.` URLs instead of `#method.`.
 * So generating `AssocItemLink::GoToSource` only on traits (when `provided_trait_methods` is supposed to return something) was the fix.
 * And finally, because it's (currently) generating implementations only through JS, it means we cannot test it in `tests/rustdoc` so I had to write the test in `tests/rustdoc-gui`. Once I change how we generate local implementations for type aliases, I'll move it to `tests/rustdoc`.

r? ```@lolbinarycat```
2025-11-25 17:51:17 +01:00
Guillaume Gomez
3181c21b6c Improve variable naming 2025-11-24 17:01:32 +01:00
Guillaume Gomez
c524ed710d Make more functions return fmt::Result and reduce number of .unwrap() calls 2025-11-24 11:41:03 +01:00
Guillaume Gomez
4d3d3b39bd Improve code 2025-11-11 18:45:36 +01:00
Guillaume Gomez
f2794ce6c0 Switch clean print methods into a function 2025-11-07 11:42:04 +01:00
Cameron Steffen
e60e9f0826 Split impl_(opt_)trait_ref 2025-10-17 08:36:34 -05:00
Yotam Ofek
c5ab530749 move serde impls to separate module 2025-10-07 13:37:49 +03:00
Yotam Ofek
978ab7c542 nicer serde impls 2025-10-07 13:23:10 +03:00
Yotam Ofek
eb8d87d1d8 avoid in-process serializing&deserializing 2025-10-07 12:58:05 +03:00
bors
dd091003ac Auto merge of #145898 - lolbinarycat:rustdoc-search-trait-parent, r=GuillaumeGomez,notriddle
If a trait item appears in rustdoc search, hide the corrosponding impl items

fixes rust-lang/rust#138251

cc `@notriddle`
2025-10-03 08:43:43 +00:00
binarycat
c407d340de if a trait item is shown in search results, hide the impl item
for example, if we're showing `Iterator::next`,
we don't need to also show `Range::next` in the results.

Co-authored-by: Michael Howell <michael@notriddle.com>
2025-10-02 15:27:40 -05:00
Yotam Ofek
2d03ab1486 Replace rustc_span::Span with a stripped down version for librustdoc's highlighter 2025-09-30 22:01:30 +03:00
Matthias Krüger
f349faa25f
Rollup merge of #146942 - yotamofek:pr/rustdoc/finish_deprecating_write_str, r=GuillaumeGomez
[rustdoc] Finish getting rid of usages `write_str`

This PR, along with rust-lang/rust#146933 , get rid of all the last usages of the `write_str` fn that was introduced back in rust-lang/rust#136784 .

This *shouldn't* be rolled up along with rust-lang/rust#146933 , since the later of the two to be merged will need to delete the no-longer-used `write_str` fn.
Commits can be reviewed separately.
2025-09-28 09:15:25 +02:00
Yotam Ofek
a40032d9e3 Simplify notable traits map serialization 2025-09-26 11:42:52 +03:00
Yotam Ofek
82fecf0ee3 Cleanup notable_traits_decl 2025-09-26 11:42:52 +03:00
Yotam Ofek
78ff5ddad9 Remove usages of write_str from render_assoc_items_inner 2025-09-26 11:42:44 +03:00
Matthias Krüger
1285b164e1
Rollup merge of #147047 - notriddle:toolbar-index, r=GuillaumeGomez
rustdoc: put the toolbar on the all item index
2025-09-26 06:36:33 +02:00
Michael Howell
8daad494b1 rustdoc: put the toolbar on the all item index 2025-09-25 14:19:22 -07:00
Matthias Krüger
a39d5134cd
Rollup merge of #116882 - fmease:rustdoc-generalized-priv-repr-heuristic, r=rustdoc
rustdoc: hide `#[repr]` if it isn't part of the public ABI

> [!IMPORTANT]
> Temporarily stacked on top of PR https://github.com/rust-lang/rust/pull/146527; only the last commit is relevant!

Follow-up to rust-lang/rust#115439.
Unblocks rust-lang/rust#116743, CC ``@dtolnay.``

Fixes rust-lang/rust#66401.
Fixes rust-lang/rust#128364.
Fixes rust-lang/rust#137440.

Only display the representation `#[repr(REPR)]` (where `REPR` is not `Rust` or `transparent`) of a given type if none of its variants (incl. the synthetic variants of structs) are `#[doc(hidden)]` and all of its fields are public and not `#[doc(hidden)]` since it's likely not meant to be considered part of the public ABI otherwise.

`--document-{private,hidden}-items` works as expected in this context, too.

Moreover, we now also factor in the presence of `#[doc(hidden)]` when checking whether to show `repr(transparent)` or not.
2025-09-25 18:15:06 +02:00
León Orell Valerian Liehr
85c193a4ed
rustdoc: hide #[repr(...)] if it isn't part of the public ABI 2025-09-25 11:49:27 +02:00
León Orell Valerian Liehr
d7d7725b8c
rustdoc: Fully escape link section and export name
Escape "special characters" (e.g., double quotes `"` and line breaks `\n`).
Escape HTML.

Lastly, add regression tests and clean up existing tests.
2025-09-25 11:30:58 +02:00
León Orell Valerian Liehr
88e797784e
rustdoc: Slightly clean up attr rendering 2025-09-25 10:16:52 +02:00
Cameron Steffen
9ecca51bbe Remove ImplSubject 2025-09-17 18:37:35 -05:00
León Orell Valerian Liehr
15f6d2e8d2
rustdoc: Move HTML-specific attr rendering code into HTML rendering mod
These functions used to be shared with the JSON backend but nowadays they
aren't.
2025-09-14 01:30:05 +02:00
Janis
f67e29e5a8
squash fix render_call_locations panic when default span points at file outside of local_sources
add test against crashing with --html-after-content file

correctly add --html-after-content to env not args

formatting fix for rustdoc-call-locations-after-content/rmake.rs

Use local crate source file as default span in `render_call_locations`

- avoids unwrapping the first file added to the source map as a local file in
`href_from_span`

move test to tests/rustdoc-gui, rename to scrape_examples_ice

test link is correct

use rustdocflags, rename path in example, track lock file

factor out duplicate function calls

use compile-flags to make sure the after.html file is actually included in the rustdoc call

fix goml go-to path

increment assert-count in sidebar-source-code.goml

adjust crate-search width in search-result-display.goml

renamed Bar in scrape_examples_ice test

make crate name shorter ..
2025-09-02 01:38:23 +02:00
Guillaume Gomez
ab0ee84eac Add new doc(attribute = "...") attribute 2025-08-28 15:56:29 +02:00
Karol Zwolak
3ac32cace1 rustdoc: make attributes render consistently
* make attributes render inside code elements and inside divs with class `code-attribute`
* render attributes for macros, associated constants, and struct/union fields
2025-08-23 10:31:57 +02:00
Michael Howell
8511e40e72 rustdoc-search: search backend with partitioned suffix tree 2025-08-15 10:26:03 -07:00
Guillaume Gomez
a195cf63b8 Revert "rustdoc search: prefer stable items in search results"
This reverts commit 1140e90074.
2025-08-14 13:06:05 +02:00
Guillaume Gomez
2820fcc830 Revert "rustdoc: IndexItem::{stability -> is_unstable}"
This reverts commit 5e8ebd5ecd.
2025-08-14 13:04:08 +02:00
Stuart Cook
48f5929604
Rollup merge of #141658 - lolbinarycat:rustdoc-search-stability-rank-138067, r=GuillaumeGomez
rustdoc search: prefer stable items in search results

fixes https://github.com/rust-lang/rust/issues/138067

this does add a new field to the search index, but since we're only listing unstable items instead of adding a boolean flag to every item, it should only increase the search index size of sysroot crates, since those are the only ones using the `staged_api` feature, at least as far as the rust project is concerned.
2025-08-09 13:58:42 +10:00
binarycat
5e8ebd5ecd rustdoc: IndexItem::{stability -> is_unstable} 2025-08-08 11:40:03 -05:00
Jana Dönszelmann
e1d3ad89c7
remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
Guillaume Gomez
c75edc982c Fix clippy lints in librustdoc 2025-07-19 16:20:47 +02:00
Camille GILLOT
83255f57e0 Include ErrorGuaranteed in StableSince::Err. 2025-07-17 23:27:19 +00:00
Nicholas Nethercote
fb7aa9e4fd Improve path segment joining.
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-17 08:37:19 +10:00
Alona Enraght-Moony
078332fdc8 rustdoc-json: Structured attributes
Implements https://www.github.com/rust-lang/rust/issues/141358.

This has 2 primary benefits:

1. For rustdoc-json consumers, they no longer need to parse strings of
   attributes, but it's there in a structured and normalized way.
2. For rustc contributors, the output of HIR pretty printing is no
   longer a versioned thing in the output. People can work on
   https://github.com/rust-lang/rust/issues/131229 without needing to
   bump `FORMAT_VERSION`.

(Over time, as the attribute refractor continues, I expect we'll add new
things to `rustdoc_json_types::Attribute`. But this can be done
separately to the rustc changes).
2025-07-15 16:52:41 +00:00
Deadbeef
6b02597ed3 update issue number for const_trait_impl 2025-07-13 23:55:06 +08:00
bors
a413f77285 Auto merge of #143363 - jdonszelmann:rollup-7cv1kql, r=jdonszelmann
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#134006 (setup typos check in CI)
 - rust-lang/rust#142876 (Port `#[target_feature]` to new attribute parsing infrastructure)
 - rust-lang/rust#143038 (avoid suggesting traits from private dependencies)
 - rust-lang/rust#143083 (Fix rustdoc not correctly showing attributes on re-exports)
 - rust-lang/rust#143283 (document optional jobs)
 - rust-lang/rust#143329 (minicore: use core's `diagnostic::on_unimplemented` messages)

Failed merges:

 - rust-lang/rust#143237 (Port `#[no_implicit_prelude]` to the new attribute parsing infrastructure)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-03 13:55:05 +00:00