Commit Graph

1501 Commits

Author SHA1 Message Date
bors 809200ec95 Auto merge of #137229 - GuillaumeGomez:expand-macro, r=lolbinarycat
Add support for macro expansion in rustdoc source code pages

This is what it looks like:

![Screenshot From 2025-02-18 18-08-51](https://github.com/user-attachments/assets/ce2b3806-6218-47df-94bf-e9e9ed40cd41)

![image](https://github.com/user-attachments/assets/891042db-8632-4dba-9343-e28570c058fe)

You can test it [here](https://rustdoc.crud.net/imperio/macro-expansion/src/lib/lib.rs.html). In this case, I also enabled the `--generate-link-to-definition` to show that both options work well together.

Note: <del>There is a bug currently in firefox where the line numbers are not displayed correctly if they're inside the "macro expansion" span: https://bugzilla.mozilla.org/show_bug.cgi?id=1949948<del> Found a workaround around this bug.

r? `@notriddle`
2025-08-24 19:46:17 +00:00
Karol Zwolak b8313dfb04 rustdoc: render attributes in Field and Variants sections 2025-08-24 12:01:08 +02:00
Samuel Tardieu cc90b4f216 Rollup merge of #145782 - karolzwolak:rustdoc-consistent-attributes-rendering, r=GuillaumeGomez
rustdoc: make attributes render consistently

While working on rust-lang/rust#132304, I discovered that even standard attributes aren't consistently rendered.
For some constructs/fields, attributes were missing entirely, and the attributes were only sometimes wrapped in a code-attribute divs so they appear greyed out.

In short this PR:
* makes attributes render inside code elements and inside divs with class `code-attribute`
* renders attributes for macros, associated constants, and struct/union fields

Attributes in `Fields` and `Variants` sections are still not rendered (see struct and enum screenshots), because I wasn't sure we want that.

[Compirison of tests/rustdoc/attributes.rs](https://github.com/karolzwolak/rust/blob/90aa25a1c5dbae1e94099b1a2015dfb83783dbe0/tests/rustdoc/attributes.rs)
Before (left) / after (right):

<img width="279" height="97" alt="image" src="https://github.com/user-attachments/assets/baca4b75-f809-4a76-8ac1-e3aa6389aad4" />
<img width="363" height="112" alt="image" src="https://github.com/user-attachments/assets/14970fb0-6fe5-474f-983e-5a95e16175c5" />

<img width="368" height="492" alt="image" src="https://github.com/user-attachments/assets/f9a25583-10e3-49c7-961b-34f3587b552e" />
<img width="415" height="515" alt="image" src="https://github.com/user-attachments/assets/f2fe4aa0-c731-4f2f-a3c2-04e524a858d1" />

<img width="383" height="483" alt="image" src="https://github.com/user-attachments/assets/bccc1b6e-f236-4948-8557-f9b25cad8a07" />
<img width="402" height="528" alt="image" src="https://github.com/user-attachments/assets/2cea9250-37e1-439e-8010-0603905d0f52" />

<img width="372" height="485" alt="image" src="https://github.com/user-attachments/assets/cd49bc0a-90e1-4d08-af0f-084c42af1834" />
<img width="406" height="542" alt="image" src="https://github.com/user-attachments/assets/67fb4ac7-746b-4e20-9c80-97702a71def8" />

<img width="357" height="131" alt="image" src="https://github.com/user-attachments/assets/42769532-1e4d-486d-bdca-6ecc409554b9" />
<img width="366" height="161" alt="image" src="https://github.com/user-attachments/assets/0b4d01d4-dd8e-4467-8cfc-ad58200ba0d7" />

<img width="291" height="65" alt="image" src="https://github.com/user-attachments/assets/43f61335-8eff-491b-a297-1953d17bbfc0" />
<img width="259" height="57" alt="image" src="https://github.com/user-attachments/assets/598618a3-e52f-4a4e-b790-2c8d5f1b4c77" />

r? ``@GuillaumeGomez``
2025-08-23 22:22:21 +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
Guillaume Gomez f8b8cc4cce Do macro expansion at AST level rather than HIR 2025-08-23 00:57:29 +02:00
Guillaume Gomez ab000e15e1 Clean up computation of macro expansion span and correctly handle spans open inside expansion spans 2025-08-23 00:57:28 +02:00
Guillaume Gomez f8ce37621a Add new unstable --generate-macro-expansion rustdoc command line flag 2025-08-23 00:57:28 +02:00
Guillaume Gomez ba3099f60b Add support for macro expansion in rustdoc source code pages 2025-08-23 00:57:28 +02:00
binarycat eeaad503df unbox raw pointers in type-based search 2025-08-21 17:50:12 -05:00
binarycat ead9f58251 make primitive:pointer work in type-based search. 2025-08-21 15:48:29 -05: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
Eval EXEC 20a134f5f0 rustdoc: Use discrs Display impl to render the value with the correct signedness 2025-08-10 23:33:23 +08: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
binarycat 9e75032a9d rustdoc: avoid allocating a temp String for aliases in search index 2025-07-22 14:51:38 -05:00
Matthias Krüger dda505850a Rollup merge of #143988 - GuillaumeGomez:alias-inexact, r=lolbinarycat
[rustdoc] Make aliases search support partial matching

Fixes rust-lang/rust#140782.

To make this work, I moved aliases into the `searchIndex` like any other item. It links to the "original" item with a new `original` field. No so great part is that we need to have some fields like `bitIndex` to be set on the alias to make the description load to work but I consider it minor enough to be ok.

This PR voluntarily doesn't handle de-prioritization of aliases as ```@lolbinarycat``` wished to work on this so I'll leave them this part. 😉

cc ```@lolbinarycat```
2025-07-20 08:56:06 +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
Guillaume Gomez 47b138b2b8 Make aliases search support partial matching 2025-07-16 14:27:22 +02: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 45b80ac21a Auto merge of #142869 - nnethercote:join_path-mini, r=camelid
Use `join_with_double_colon` in `write_shared.rs`.

For consistency. Also, it's faster because `join_with_double_colon` does a better job estimating the allocation size than `join` from `itertools`.

r? `@camelid`
2025-07-08 06:32:37 +00: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
klensy c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
Yotam Ofek 6992739ab8 Lazy-ify some markdown rendering 2025-06-29 12:41:16 +00:00
Matthias Krüger 8f30a98591 Rollup merge of #142987 - lolbinarycat:rustdoc-non_exhaustive-enum-v-142599, r=GuillaumeGomez
rustdoc: show attributes on enum variants

mostly for #[non_exhaustive]

unsure if there's any attributes we should take care to *not* include, it could use `render_code_attribute` and `is_non_exhaustive` instead, if that is a concern.

fixes rust-lang/rust#142599
2025-06-28 22:05:30 +02:00
binarycat b2be01c815 rustdoc: show attributes on enum variants
mostly for #[non_exhaustive]
2025-06-26 12:33:30 -05:00
Alona Enraght-Moony 84f92f3211 rustdoc: Don't mark #[target_feature] functions as ⚠
Closes https://www.github.com/rust-lang/rust/issues/142952
2025-06-24 18:55:45 +00:00
Jonathan Brouwer 2084831cd5 Port #[no_mangle] to new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-22 22:17:04 +02:00
Nicholas Nethercote 0cf0f9fc74 Use join_with_double_colon in write_shared.rs.
For consistency. Also, it's faster because `join_with_double_colon` does
a better job estimating the allocation size than `join` from
`itertools`.
2025-06-22 20:28:48 +10:00
bors fa2f3552da Auto merge of #142667 - yotamofek:pr/rustdoc/more-write-shared-perf, r=nnethercote
Avoid a few more allocations in `write_shared.rs`

Inspired by rust-lang/rust#141421 , avoids a few `Vec`, `PathBuf` and `String` allocations in `write_shared.rs`. I don't think these will show up on benchmarks, but are still worthwhile IMHO.
Also includes a few small cleanups.
r? nnethercote - if you'd like :)
2025-06-21 23:18:00 +00:00
Alona Enraght-Moony aab941ff30 rustdoc: Remove FormatRenderer::cache
We only called it it one place, which isn't generic and can be replaced
with a field access.
2025-06-19 23:21:38 +00:00
Yotam Ofek 2bf66e3887 Options are Iterators 2025-06-19 10:26:13 +00:00
Yotam Ofek 569aa26e7b avoid intermediately collecting into vectors 2025-06-19 10:26:13 +00:00
Yotam Ofek 867c1d5ebf one less pathbuf allocation 2025-06-19 10:26:13 +00:00
Yotam Ofek b2fe858a4e Result::expect instead of match and panic! 2025-06-18 09:42:43 +00:00
binarycat 00c104225f rustdoc: make srcIndex no longer a global variable
this is one-time initialization data, it can just
be a function parameter.

we also move the json parsing into createSrcSidebar
to save a few bytes.
2025-06-16 20:22:24 -05:00
Nicholas Nethercote 79b3c08bdb Avoid more clones in rustdoc JSON output.
By making `JsonRenderer::item` take `&clean::Item` instead of a
`clean::Item`. This required also changing `FromClean` and `IntoJson`
methods to take references, which required a lot of follow-on sigil
wrangling that is mostly tedious.
2025-06-11 13:48:43 +10:00
binarycat 1140e90074 rustdoc search: prefer stable items in search results
fixes https://github.com/rust-lang/rust/issues/138067
2025-06-10 12:56:58 -05:00
Nicholas Nethercote cc671754a3 Simplify JsonRenderer.
- It doesn't need to be cloneable.
- Some of the `Rc`s and `RefCell`s aren't doing anything.
- `after_krate` can consume `self`.
2025-06-10 16:25:02 +10:00
bors e6152cdf5b Auto merge of #141573 - nnethercote:rustdoc-alloc-cleanups, r=camelid
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-30 08:55:18 +00:00
Nicholas Nethercote 68f32169e5 Address review comments. 2025-05-30 13:26:36 +10:00
Nicholas Nethercote 8dde6d5349 Streamline TypeAliasPart::get.
- `ret` only ever gets at most one entry, so it can be an `Option`
  instead of a `Vec`.
- Which means we can use `filter_map` instead of `flat_map`.
- Move `trait_` next to the `ret` assignment, which can only happen
  once.
- No need for `impls` to be a `Vec`, it can remain an iterator.
- Avoid `Result` when collecting `impls`.
2025-05-27 08:26:50 +10:00
Nicholas Nethercote 4f1f1a2b57 Avoid some unnecessary cloning. 2025-05-26 16:47:44 +10:00
Nicholas Nethercote f19d40a3d6 Rename some methods.
Most of the methods returning `impl Display` have `print` in their name.
This commit renames a few that didn't follow that convention.
2025-05-26 15:07:47 +10:00
Guillaume Gomez ec97b0f0b5 Update to new API 2025-05-25 15:27:32 +02:00