Commit Graph

74 Commits

Author SHA1 Message Date
Jonathan Brouwer b0d9ae60e1 Rollup merge of #156401 - shivendra02467:doc-cfg-sort-fix, r=GuillaumeGomez
rustdoc: deterministic sorting for `doc_cfg` badges

Fixes rust-lang/rust#156391

Currently, target-exclusive `doc_cfg` badges (eg. "Available on...") reuse the order of predicates as they appear in the source code. This often buries popular targets behind niche ones and leads to inconsistent UI rendering.

This PR introduces a deterministic sorting mechanism to the `Cfg` AST prior to HTML/JSON rendering.

**Note for Reviewers:**
To provide the best UX, I implemented a lightweight tiering heuristic (prioritizing major platforms like Linux/Apple/Windows first, followed by mobile, then BSDs, and alphabetizing the rest). However, I am completely open to tweaking these priority groupings or falling back to a different sorting logic if the team prefers. Let me know what you think!
2026-05-28 14:59:41 +02:00
Shivendra Sharma f658bf6bb8 rustdoc: deterministic sorting for doc_cfg badges 2026-05-28 16:15:20 +05:30
bors e1ff77d898 Auto merge of #156736 - GuillaumeGomez:primitive-assoc-methods, r=fmease
Fix jump to def link generation on primitive type associated methods

Fixes rust-lang/rust#156707.

Interestingly enough, the inference fails on primitive type, so instead I go around a bit by generating a `PrimitiveType` and then tweak a bit the `href` generation.

r? @fmease
2026-05-24 03:17:11 +00:00
Guillaume Gomez 0c7388c750 Fix jump to def link generation on primitive type associated methods 2026-05-23 19:07:36 +02:00
Yotam Ofek 877d57c2c2 Also emit "Dyn Compatibility" section for traits that *are* dyn compatible 2026-05-22 18:08:11 +03:00
bors 4d276d7fdb Auto merge of #155307 - Urgau:rustdoc-stabilize-remap-path-prefix, r=GuillaumeGomez
Stabilize `--remap-path-prefix` in rustdoc



# Stabilization report of  `--remap-path-prefix` in rustdoc

## Summary

`rustc` supports remapping source paths prefixes as a best effort in all compiler generated output, including compiler diagnostics, debugging information, macro expansions, documentation, doctests, etc.

This is useful for normalizing build products, for example, by removing the current directory out of the paths emitted into object files.

This stabilization stabilize the same flag used by `rustc` in `rustdoc`.

There are no tracking issue.

Stabilization was discussed at the last meeting, [#t-rustdoc/meetings > 2026-04-13 @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/393423-t-rustdoc.2Fmeetings/topic/2026-04-13/near/585264347).

### What is stabilized

The rustdoc `--remap-path-prefix` flag is being stabilized by this PR. (It's equivalent to rustc flag)

It permits remapping (as a best effort) source path prefixes in all output, including diagnostics, debug information, macro expansions, generated documentation, etc.

It takes a value of the form `FROM=TO` where a path prefix equal to `FROM` is rewritten to the value `TO`.

#### Example

```sh
rustdoc src/lib.rs --remap-path-prefix="$PWD=/foo"
```

### What isn't stabilized

Neither `--remap-path-scope` (~~soon to be added as unstable in `rustdoc`~~ https://github.com/rust-lang/rust/issues/155451) or the already unstable in `rustc` `documentation` scope are being stabilized or added here.

## Design

### Implementation history

- rust-lang/rust#107099

### Unresolved questions

There are no unresolved questions.

### Post-implementation changes

The implementation has evolved with `rustc`, but no changes to the flag it-self have been made.

### Nightly extensions

The `documentation` scope, which currently can only be set from `rustc`, as we need to add an equivalent to the `--remap-path-scope` flag, ~~which is planned~~ (EDIT: https://github.com/rust-lang/rust/issues/155451), but not required, the current `--remap-path-prefix` defaults to the `all` scope, like `rustc`.

### Doors closed

We are committing to having to having a flag that permits remapping paths. The compiler team already made the same commitment.

## Feedback

### Call for testing

No call for testing has been done.

### Nightly use

Unable to determine. A [GitHub search](https://github.com/search?q=%20%2F--remap-path-prefix%2F&type=code) only seems to only reveals the `rustc` usage (over 6k though).

Rust-for-Linux is using the [flag](https://github.com/torvalds/linux/blob/e80d033851b3bc94c3d254ac66660ddd0a49d72c/Makefile#L1151-L1153).

## Implementation

### Major parts

- rust-lang/rust#107099
- rust-lang/rust#149709
- rust-lang/rust#150172
- rust-lang/rust#151589

### Coverage

- [`tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-failed-doctest-output.rs)
- [`tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-invalid-doctest.rs)
- [`tests/rustdoc-ui/remap-path-prefix-macro.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-macro.rs)
- [`tests/rustdoc-ui/remap-path-prefix-passed-doctest-output.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/remap-path-prefix-passed-doctest-output.rs)
- [`tests/rustdoc-ui/lints/remap-path-prefix-lint.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-ui/lints/remap-path-prefix-lint.rs)
- [`tests/rustdoc-html/import-remapped-paths.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-html/import-remapped-paths.rs)
- [`tests/rustdoc-html/macro/external-macro-src.rs`](https://github.com/rust-lang/rust/blob/12f35ad39ed3e39df4d953c46d4f6cc6c82adc96/tests/rustdoc-html/macro/external-macro-src.rs)

### Outstanding bugs

There are no outstanding bugs regarding `--remap-path-prefix` in `rustdoc`.

There are [caveats and limitation](https://doc.rust-lang.org/nightly/rustc/remap-source-paths.html#caveats-and-limitations) in `rustc`, but they mostly concern generated object files, which we don't really have. 

### Outstanding FIXMEs

There are no FIXME regarding `--remap-path-prefix`.

## Acknowledgments

- @edward-shen
- @Urgau
2026-05-21 22:46:41 +00:00
abdul2801 afedb8727e Update turbofish.rs 2026-05-19 19:29:13 +05:30
Abdul Rafey Ahmed c454d92f61 fix: improve turbofish jump-to-def handling
Handle turbofish syntax correctly in rustdoc jump-to-def links
and add regression tests covering type aliases.
2026-05-19 16:20:38 +05:30
bors d3cd04068e Auto merge of #152449 - GuillaumeGomez:rustdoc-bang-attr-macro, r=lolbinarycat,mejrs
rustdoc: properly support macros with multiple kinds



Since it seems like I can't reopen https://github.com/rust-lang/rust/pull/145458, opening this one. Although, it's the same PR minus the last new commit to handle a comment that was left unresolved in the original PR. All relevant details are still in the original PR though.

It's an alternative (and likely a take-over) of https://github.com/rust-lang/rust/pull/148005 since lang-team rejected the idea to add documentation on macro branches, making the multiple files approach less suitable.

This implements rust-lang/rust#145153 in rustdoc. This PR voluntarily doesn't touch anything related to intra-doc links, I'll send a follow-up if needed.

So now about the implementation itself: this is a weird case where a macro can be different things at once but still only gets one file generated. I saw two ways to implement this:
1. Handle `ItemKind::Macro` differently and iter through its `MacroKinds` values.
2. Add new placeholder variants in the `ItemKind` enum, which means that when we encounter them in rendering, we need to ignore them. It also makes the `ItemKind` enum bigger (and also needs more code to be handled). Another downside is that it needs to be handled in the JSON output.

Now there was an interesting improvement that came with this PR in the `html::render::print_item::item_module` function: I simplified its implementation and split the different parts in a `HashMap` where the key is the item type. So then, we can just iterate through the keys and open/close the section at each iteration instead of keeping an `Option<section>` around.

From RFCs:
* https://github.com/rust-lang/rust/pull/144579
* https://github.com/rust-lang/rust/pull/145208

derive:

<img width="442" height="327" alt="Screenshot From 2026-04-18 03-11-40" src="https://github.com/user-attachments/assets/f69587a0-8a2b-4080-bc8a-b63dd18f21c1" />

attr:

<img width="442" height="327" alt="Screenshot From 2026-04-18 03-11-31" src="https://github.com/user-attachments/assets/bf9b235a-9d2f-435c-a91e-167562df6b68" />

both:

<img width="442" height="327" alt="Screenshot From 2026-04-18 03-11-50" src="https://github.com/user-attachments/assets/b7e8b3c6-eb99-495b-bdf9-17ba8fb4da0d" />

r? @notriddle
2026-05-16 18:54:36 +00:00
Jonathan Brouwer 6708081d6b Rollup merge of #156587 - GuillaumeGomez:assoc-items-macro-expansion, r=Urgau
Correctly handle associated items in rustdoc macro expansion

Fixes rust-lang/rust#156075.

The bug was simply that it didn't cover associated items.

r? @Urgau
2026-05-15 20:11:48 +02:00
Guillaume Gomez 899be9fe47 Add regression tests for associated items in rustdoc macro expansion 2026-05-15 00:42:17 +02:00
León Orell Valerian Liehr 2493ef1503 rustdoc: SpanMapVisitor: Cache TypeckResults 2026-05-13 03:51:44 +02:00
Guillaume Gomez 1cbb922c16 Change HTML IDs for attribute macros and attributes
Rename `ItemType::BangMacro*` into `ItemType::DeclMacro*`
Rename `isBangMacro` field into `forceMacroHref`
2026-05-10 02:37:58 +02:00
Guillaume Gomez daec3d8384 Improve code and docs 2026-05-10 02:37:58 +02:00
Guillaume Gomez 9b2fecbfe9 Handle new kinds of macros at once 2026-05-10 02:37:57 +02:00
Guillaume Gomez 5dd3e5e2bf Add a doc_cfg regression test to ensure foreign types impls are working as expected 2026-05-04 00:05:38 +02:00
Guillaume Gomez ba27564259 Keep the original import DefId when inlining items through multiple reexports 2026-05-03 03:27:09 +02:00
Guillaume Gomez d4997ca71d Fix doc_cfg feature on reexports 2026-05-02 18:08:26 +02:00
Jacob Pratt 0a05ddf92b Rollup merge of #155954 - cijiugechu:doc_cfg-decl-macro, r=notriddle
rustdoc: preserve parent doc cfg for `macro_export` macros

The detached-item context is discovered before `propagate_doc_cfg`, it is carried on the clean item and consumed by the pass.

Closes rust-lang/rust#100916
2026-04-30 22:28:27 -04:00
cijiugechu 09e9d3f6da rustdoc: preserve parent doc cfg for macro_export macros 2026-04-30 16:31:22 +08:00
Guillaume Gomez 36138dc0b8 Fix doc_cfg feature for extern items 2026-04-29 18:02:25 +02:00
Folkert de Vries a4f5c6e971 error on invalid macho section specifier 2026-04-25 20:06:30 +02:00
teor c0441d42ed Fix Mlibc env pretty print to Managarm C Library 2026-04-23 17:07:21 +10:00
Zac Harrold fe2b39f064 Move std::io::ErrorKind to core::io
Move `std::io::ErrorKind` to `core::io`
* Update `rustdoc-html` tests for the new path
* Add `core_io` feature to control stability. This replaces the use of `core_io_borrowed_buf` on the `core::io` module itself.
* Re-export `core::io::ErrorKind` in `std::io::error`
2026-04-20 18:38:25 +10:00
Urgau d3bdea115d Stabilize --remap-path-prefix in rustdoc 2026-04-17 18:52:21 +02:00
Stuart Cook 0ab3a69f3c Rollup merge of #154970 - shivendra02467:fix-rustdoc-154921, r=GuillaumeGomez
rustdoc: preserve `doc(cfg)` on locally re-exported type aliases

When a type alias is locally re-exported from a private module (an implicit inline), rustdoc drops its `cfg` attributes because it treats it like a standard un-inlined re-export. Since type aliases have no inner fields to carry the `cfg` badge (unlike structs or enums), the portability info is lost entirely.

This patch explicitly preserves the target's `cfg` metadata when the generated item is a `TypeAliasItem`, ensuring the portability badge renders correctly without breaking standard cross-crate re-export behavior.

Fixes rust-lang/rust#154921
2026-04-17 16:17:53 +10:00
Stuart Cook 3c61fba50b Rollup merge of #154491 - Jules-Bertholet:case-docs, r=Mark-Simulacrum,GuillaumeGomez
Extend `core::char`'s documentation of casing issues (and fix a rustdoc bug)

@rustbot label A-unicode A-docs
2026-04-17 16:17:50 +10:00
Shivendra Sharma 52ad8c071c rustdoc: preserve doc(cfg) on locally re-exported type aliases
When a type alias is locally re-exported from a private module (an implicit
inline), rustdoc drops its `cfg` attributes because it treats it like a
standard un-inlined re-export. Since type aliases have no inner fields to
carry the `cfg` badge (unlike structs or enums), the portability info
is lost entirely.

This patch explicitly preserves the target's `cfg` metadata when the
generated item is a `TypeAliasItem`, ensuring the portability badge
renders correctly without breaking standard cross-crate re-export behavior.
2026-04-16 11:51:51 +05:30
Jules Bertholet a9d7027f39 rustdoc: percent-encode URL fragments 2026-04-15 22:32:07 -04:00
usamoi 05081b96c9 fix arch names in cfg pretty printer 2026-04-14 23:38:25 +08:00
Jacob Pratt a2d7d8c8da Rollup merge of #154955 - cijiugechu:fix-rustdoc-pattern-type-implementors, r=notriddle
Fix pattern types rendering in rustdoc

Closes rust-lang/rust#150889 .

`core` was rendering local pattern-type impls through `clean_ty`, which formatted `rustc_hir::TyPat` with derived Debug, while inlined docs go through `clean_middle_ty` and get the pretty-printed `rustc_middle::ty::Pattern`.
Lower local HIR pattern types before formatting so both paths share the same canonical pattern printer and stop exposing `TyPat { ... }` in implementors.

#### Current result:
<img width="1133" height="738" alt="截屏2026-04-07 22 47 26" src="https://github.com/user-attachments/assets/bb5f8942-30b1-400a-a0a0-f581da5bb59f" />
2026-04-09 02:31:08 -04:00
cijiugechu 854d2abd78 fix pattern types rendering in rustdoc 2026-04-07 22:26:21 +08:00
Shivendra Sharma f8d3c27650 rustdoc: Inherit inline attributes for declarative macros
When explicitly re-exporting a declarative macro by name, rustdoc
previously bypassed intermediate re-exports and dropped `#[doc(inline)]`
attributes, causing the macro to be incorrectly stripped if the original
definition was `#[doc(hidden)]`.

This updates `generate_item_with_correct_attrs` to walk the
`reexport_chain` specifically for declarative macros, allowing them to
inherit inline attributes exactly as glob imports do, while preserving
strict visibility rules for standard items.
2026-04-07 11:50:34 +05:30
Jacob Pratt e5e3c25df2 Rollup merge of #154444 - jakubadamw:issue-128801, r=fmease
rustdoc ICE fix: When collecting `Deref` impls with their targets, skip the negative ones

rustdoc assumed every `Deref` impl has an associated `Target` type, but negative impls (e.g. `impl !Deref for T {}`) have none.

Skip them in both the trait-impl collection pass and the HTML render pass to avoid panicking on the missing `Target`.

Closes rust-lang/rust#128801.
2026-04-02 20:53:31 -04:00
Jacob Adam 02a73dbe9b Address review feedback. 2026-04-01 23:05:42 +01:00
binarycat 9bdf217810 rustdoc: seperate methods and associated functions in sidebar 2026-03-31 12:51:12 -05:00
Sasha Pourcelot 9f0944832b rustdoc: add missing target_{os,arch,env} values for cfg pretty printer 2026-03-29 16:02:23 +00:00
Sasha Pourcelot c67380d6fe rustdoc: add test showing cfg pretty-printing of all targets 2026-03-29 15:56:39 +00:00
Guillaume Gomez 73fe4c5a3b Add regression test for #153655 2026-03-23 21:25:46 +01:00
Jonathan Brouwer 2263a8e19e Rollup merge of #153072 - ferrocene:jyn/libcore-doctest-merge, r=jdonszelmann
Allow merging all libcore/alloc doctests into a single binary

This is only the changes needed to *allow* merging the tests. This doesn't actually turn doctest merging on in bootstrap. I think that might be a useful follow-up, since it makes them much faster to run, but it's not without downsides because it means we'll no longer be testing that doctests have all necessary `feature()` attributes.

The motivation for this change is to run the tests with `-C instrument-coverage` and then generate a coverage report from the output. Currently, this is very expensive because it requires parsing DWARF for each doctest binary. Merging the binaries decreases the time taken from several hours to ~30 seconds.

---

There are several parts to this change, most of which are independent and I'm happy to split out into other PRs.

- Upgrade process spawning logging from debug->info so it's easier to see, including in a rustdoc built without debug symbols.
- Core doctests now support being run with `-C panic=abort`. Ferrocene needs this downstream for complicated reasons; it's a one-line change so I figured it's not a big deal.
- Downgrade errors about duplicate features from a hard error to a warning. The meaning is clear here, and doctest merging often creates duplicate features since it lifts them all to the crate root. This involves changes to the compiler but generally I expect this to be low-impact.
  - Enable this new warning, as well as several related feature lints, in rustdoc. By default rustdoc doesn't lint on anything except the lints it manually adds.
- Rustdoc now treats `allow(incomplete_features)` as a crate-level attribute, just like `internal_features`. Without this, it's possible to get hard errors if rustdoc lifts features to the crate level but not `allow`s.
- Core doctests now support being built with `--merge-doctests=yes`. In particular, I removed a few `$crate` usages and explicitly marked a few doctests as `standalone_crate`.
2026-03-11 10:58:50 +01:00
Jynn Nelson 84442006ab Rustdoc lints on duplicate, unused, and stable features 2026-03-10 13:18:10 +01:00
Matthias Krüger b60f58f505 Rollup merge of #149931 - lolbinarycat:rustdoc-depr-html-future, r=GuillaumeGomez
rustdoc: don't give depreciation notes special handling

based on discussion in rust-lang/rust#149741

we're currently using pre-wrap here which forces us to do a bunch of other hacky weird stuff, but getting rid of all that would likely break some existing docs, so i'm proposing we do it across an edition.

r? @GuillaumeGomez
2026-03-09 23:47:01 +01:00
Stuart Cook d16ec8534b Rollup merge of #153280 - GuillaumeGomez:add-test-reexport, r=lolbinarycat
Add regression test for `doc(fake_variadic)` on reexports

Follow-up of https://github.com/rust-lang/rust/pull/153136. Out of the four doc attributes remaining to be tested (`fake_variadic`, `keyword`, `attribute` and `notable_trait`), only `fake_variadic` could have been impacted by reexports:

* `attribute` and `keyword` are not supposed to be reexported (they're supposed to be used on private modules)
* `notable_trait` is applied to a trait, so whether it's reexported or not, it still works.

r? @lolbinarycat
2026-03-04 11:54:08 +11:00
joboet e9ca34fe64 reference more reliable items in rustdoc tests 2026-03-02 11:57:04 +01:00
Guillaume Gomez ae8890fa54 Add regression test for doc(fake_variadic) on reexports 2026-03-02 11:44:40 +01:00
Jacob Pratt 10edd16dcb Rollup merge of #152977 - arferreira:fix-extern-html-relative-depth, r=notriddle
Fix relative path handling for --extern-html-root-url

When `--extern-html-root-url` receives a relative path (like `../`), rustdoc uses it as a literal prefix regardless of page depth. This works at depth 1 (`crate/index.html`) but breaks at depth 2+ (`crate/module/struct.Foo.html`) because the relative path doesn't account for the extra nesting.

This patch detects relative vs absolute URLs in the `Remote` branch of `url_parts` and prepends the necessary `../` segments based on the current page depth. Absolute URLs (`https://...`) and server-absolute paths (`/docs/...`) are unchanged.

This makes relative paths a viable option for `--extern-html-root-url`, which they weren't before.

Related to rust-lang/rust#152917, which exposed that relative paths weren't handled correctly.

cc @eggyal
2026-02-24 22:51:40 -05:00
arferreira b3a41f2385 Add test cases for intra-doc links 2026-02-24 11:41:26 -05:00
Guillaume Gomez e62880676a rustdoc: Improve sentence for documented empty impl blocks 2026-02-23 16:25:27 +01:00
arferreira b9614b2dc2 Fix relative path handling for --extern-html-root-url 2026-02-23 09:59:15 -05:00
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