Commit Graph

560 Commits

Author SHA1 Message Date
Redddy bc12569f94 rustdoc: avoid ICE when rendering body-less type consts 2026-05-26 01:05:57 +00: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
Jonathan Brouwer 06763ba095 Rollup merge of #156616 - notriddle:rustdoc-ui-test-cli, r=GuillaumeGomez
rustdoc: add test case for `-Drustdoc::` and `--cap-lints`

This works, but I couldn't find any test cases for it.
2026-05-17 15:52:41 +02:00
Michael Howell 0344a02261 rustdoc: add test case for --cap-lints=allow 2026-05-15 11:13:16 -07:00
Jonathan Brouwer 62c2da091b Rollup merge of #148788 - TomtheCoder2:unconstrained-parameter-fix, r=davidtwco
Unconstrained parameter fix

This PR is an attempt to solve the issue described in the issue rust-lang/rust#107295
2026-05-15 20:11:41 +02:00
Michael Howell 5f2e455a1c rustdoc: add test case for -Drustdoc:: CLI param
This works, but I couldn't find any test cases for it.
2026-05-15 10:46:35 -07:00
León Orell Valerian Liehr e205784d77 Don't try to resolve type-dependent paths in anon consts 2026-05-13 03:56:00 +02:00
León Orell Valerian Liehr 2493ef1503 rustdoc: SpanMapVisitor: Cache TypeckResults 2026-05-13 03:51:44 +02:00
Jonathan Brouwer cc434529cb Rollup merge of #156022 - tonywu6:main, r=lolbinarycat
rustdoc: Fix cosmetic issues when reporting unresolved paths in `broken_intra_doc_links`

Fix some minor issues with how the `rustdoc::broken_intra_doc_links` lint labels unresolved items:

- [`a469a4a`] For unresolved "extern prelude" links like `::unresolved::item`
  - Previously: ```no item named `` in scope```
  - Now: ```no item named `unresolved` in scope```
- [`eeb96fa`] Some malformed paths are now accounted for, for example:
  - `std:::path`
    - Previously: ```no item named `std:` in scope```
    - Now: `has invalid path separator`
  - `std::::path`
    - Previously: ```no item named `` in scope```
    - Now: `has invalid path separator`

This PR is broken down into a few commits with their own descriptions, which I hope makes reviewing easier!

Fixes rust-lang/rust#141095

[`a469a4a`]: https://github.com/rust-lang/rust/commit/a469a4ae638200c264c553e72204335e20d661a1
[`eeb96fa`]: https://github.com/rust-lang/rust/commit/eeb96fab7c7882dca4c48aa8b5817e4acbf0d7d2
2026-05-11 23:03:07 +02:00
Tony Wu 1892ccf428 rustdoc: change lint message to "invalid path separator" for consistency 2026-05-11 09:54:47 +08:00
León Orell Valerian Liehr ef282ff86b rustdoc: Reify emission types 2026-05-10 00:54:45 +02:00
Tony Wu c1965b598d rustdoc: report unresolved paths that appear invalid
- Check whether an unresolved path is in fact invalid. This prevents rustdoc
  from emitting nonsensical diagnostics like:

  - "no item named `std:` in scope"
  - "no item named `` in scope"

  Instead rustdoc will now say "has invalid path separator" (the same message
  from `MalformedGenerics::InvalidPathSeparator`)

  This is done by checking whether each path segment is empty or contains extra ":"
  after it's been split by the path separator "::".

- Add a dedicated test `tests/rustdoc-ui/intra-doc/invalid-path-separator.rs`
  for this.

- Some unrelated test snapshots have been updated because of this new check.
2026-05-10 03:39:00 +08:00
janwi_mac d02b4c8e77 Improve suggestions for unconstrained parameters in impl blocks
When an unconstrained type or lifetime parameter is detected in an
`impl`, provide more specific help based on its usage:
- If the parameter is entirely unused, suggest removing it.
- If it is used in the `impl` body but not the `Self` type, suggest
  including it in the `Self` type and the struct definition.

This also adds a comprehensive UI test for these cases.
2026-05-09 17:50:35 +12:00
Tony Wu a469a4ae63 rustdoc: correctly display unresolved item for "extern prelude" paths
- Add a check while trying to resolve parents, so that for links like
  [`::unresolved::path`], rustdoc will say:
    "no item named `unresolved` in scope"
  instead of:
    "no item named `` in scope"

- Update corresponding test
2026-05-01 07:56:40 +08:00
Urgau d3bdea115d Stabilize --remap-path-prefix in rustdoc 2026-04-17 18:52:21 +02:00
Tony Wu b967de6255 rustdoc: fix issues with redundant_explicit_links 2026-04-17 19:17:42 +08:00
Urgau ae6dbdd9f0 Add --remap-path-scope as unstable in rustdoc 2026-04-15 21:26:48 +02:00
Jacob Pratt 1700a21d10 Rollup merge of #155126 - folkertdev:target-object-format, r=Urgau
add `cfg(target_object_format = "...")`

tracking issue: https://github.com/rust-lang/rust/issues/152586

I'm implementing the predicate as `target_object_format`, because that's what is useful to me (for testing `#[link_section = "..."]` where `mach-o` has some extra restrictions) and maps cleanly to the `BinaryFormat` enum that is used internally. There is still room for a future `target_executable_format` when there is a use case.

cc @joshtriplett as the lang sponsor of this feature, @workingjubilee as the author of the proposal.

r? JonathanBrouwer a sidequest from the sidequest that is https://github.com/rust-lang/rust/pull/155065
2026-04-11 21:12:20 -04:00
Folkert de Vries 6bcd172f5a add cfg(target_object_format = "...") 2026-04-11 14:12:39 +02:00
Jacob Pratt ca34f771c0 Rollup merge of #154827 - scrabsha:push-zuosxmmnzkrq, r=jdonszelmann
distinguish "expected a single argument" and "expected an argument" on attribute parsing
2026-04-11 04:50:15 -04:00
Jonathan Brouwer 65745a1b95 Revert #152369 because of multiple regressions
The regressions are documented in the PR comments.
This reverts commit 2972b5e, reversing changes made to f908263.
2026-04-09 18:53:59 +02:00
Sasha Pourcelot 362e0f9160 special case expected_single_argument when no argument is provided 2026-04-09 16:39:58 +00:00
Scott Schafer 63ed113d84 chore: Update annotate-snippets to 0.12.15 2026-04-06 14:48:52 -06:00
bors 2972b5e59f Auto merge of #152369 - Bryntet:lint_attrs, r=JonathanBrouwer,jdonszelmann
Port lint attributes to attribute parser

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/152369)*

Tracking issue: rust-lang/rust#131229

Ports `#[allow]`, `#[deny]`, `#[expect]`, `#[forbid]`, and `#[warn]` to being parsed attrs

I tried my best to make this PR as small as possible, it was difficult. I hope it isn't too difficult to review

r? @JonathanBrouwer 
r? @jdonszelmann
2026-04-03 13:51:50 +00:00
Edvin Bryntesson bd864efa70 bless tests and tidy
also removes E0452 and splits
`tests/rustdoc-ui/lints/renamed-lint-still-applies` into 2 tests

this is because of delayed warn lint being lost on compiler aborting on
error
2026-04-03 11:08:11 +02:00
Matthias Krüger 7a740135c2 Rollup merge of #154696 - lolbinarycat:rustdoc-missing_doc_code_examples-macro_rules, r=GuillaumeGomez
rustdoc_missing_doc_code_examples: lint on macro_rules macros

part of rust-lang/rust#154640

accidentally built this on top of rust-lang/rust#154644, but since that PR is already approved it should be fine if we just wait for it to be merged.

r? @GuillaumeGomez
2026-04-03 09:30:17 +02:00
Jacob Pratt 62a9658ca5 Rollup merge of #154590 - scrabsha:push-xzmtpsntoxwm, r=jdonszelmann
Make #[cfg] suggest any or all on #[cfg(a, b)]
2026-04-02 20:53:32 -04:00
Sasha Pourcelot 4e019ac160 make cfg parser suggest any or all on #[cfg(a, b)] 2026-04-02 14:13:11 +00:00
Jacob Adam 3888a633b7 Add a regression test for rustdoc ICEing on negative Deref/DerefMut impls 2026-04-01 23:05:41 +01:00
binarycat 6fd96ddc3d rustdoc_missing_doc_code_examples: lint on macro_rules macros 2026-04-01 15:17:23 -05:00
Guillaume Gomez 0ba684b705 Rollup merge of #154453 - chenyukang:yukang-fix-154383, r=notriddle
Fix ice in rustdoc of private reexport

Fixes rust-lang/rust#154383

The root cause is rustdoc could still try to resolve links for source docs that resolver did not cache in `ResolveDocLinks::Exported` mode. The test case will not crash with `--document-private-items` option, which will use `ResolveDocLinks::All`.

The fix makes rustdoc skip link resolution based on the source `DefId` of each doc fragment, so its behavior stays aligned with resolver's logic here: https://github.com/chenyukang/rust/blob/dc5cb1719eed6ac9275fe93d914d32141606b2ac/compiler/rustc_resolve/src/late.rs#L685
2026-03-29 00:06:52 +01:00
Ralf Jung d400f17222 Rollup merge of #154394 - aDotInTheVoid:in-one-word-he-told-me-secret-of-success-in-testing-normalize, r=fmease
Normalize rustc path prefix when testing `-Z track-diagnostics`

Fixes https://github.com/rust-lang/rust/issues/154392
2026-03-28 13:15:52 +01:00
Alona Enraght-Moony d10baae9ce Normalize rustc path prefix when testing -Z track-diagnostics
Fixes https://www.github.com/rust-lang/rust/issues/154392
2026-03-28 12:01:38 +00:00
yukang dc5cb1719e Fix ice in rustdoc of private reexport 2026-03-27 12:10:58 +08:00
yukang 7e95a22e1f rustdoc rejects html emits with json output 2026-03-27 08:59:51 +08:00
Stuart Cook 319df85a09 Rollup merge of #154048 - GuillaumeGomez:missing_doc_code_examples-improvement, r=lolbinarycat
Don't emit rustdoc `missing_doc_code_examples` lint on impl items

@lolbinarycat realized in [this comment](https://github.com/rust-lang/rust/pull/153964#discussion_r2953956702) that we weren't testing some cases for the `missing_doc_code_examples` lint. Turns out that it was not handling this case well. =D

So in short: `missing_doc_code_examples` lint should not be emitted on impl items and this PR fixes that.

r? @lolbinarycat
2026-03-20 15:33:05 +11:00
Guillaume Gomez 6d3b7809cf Add more tests for rustdoc missing_doc_code_examples lint 2026-03-18 17:28:55 +01:00
Matthias Krüger 81549a3cc1 Rollup merge of #153881 - estebank:const-e0308, r=Kivooeo
Provide more context on type errors in const context

- On `const` and `static` point at the type (like we do for let bindings)
- On fn calls, point at const parameter in fn definition
- On type, point at const parameter in type definition
- On array type lengths, explain that array length is always `usize`
- On enum variant discriminant, mention `repr`
- On default field value using type parameter, provide more context (Fix rust-lang/rust#147748)
2026-03-15 16:52:44 +01:00
Michael Howell 77eea39d45 rustdoc: error out on --test with --emit
These options don't behave reasonably when combined right now, and there
are no tests and no docs for how they should.

For the short term, make this a fatal error. If we decide to assign this
some semantics, then we can do that at any time.
2026-03-14 19:06:32 -07:00
Esteban Küber 724c1a02e1 Update rustdoc-ui test 2026-03-14 20:13:43 +00:00
Jynn Nelson 84442006ab Rustdoc lints on duplicate, unused, and stable features 2026-03-10 13:18:10 +01:00
Esteban Küber 37684bdfc5 Make all multipart suggestions verbose
The ShowAlways style of suggestions is usually easier to understand than the inline style.
2026-02-18 18:33:35 +00:00
Esteban Küber c73b3d20c6 Unify wording of resolve error
Remove "failed to resolve" and use the same format we use in other resolution errors "cannot find `name`".

```
error[E0433]: cannot find `nonexistent` in `existent`
  --> $DIR/custom_attr_multisegment_error.rs:5:13
   |
LL | #[existent::nonexistent]
   |             ^^^^^^^^^^^ could not find `nonexistent` in `existent`
```
2026-02-17 16:51:44 +00:00
Keith-Cancel 73a991fb9d Allow provisional mgca syntax of type const <IDENT> = <EXPR> to be reconized.
Revert, but without type const.

Update symbol for feature err, then update suggestion output, and lastly update tests that change because of those.

Update these new tests with the correct syntax, and few existing tests with the new outputs the merge with main added.

Fix for tidyfmt and some errors when manually resolving a merge conflicts.

Update these tests to use update error messages and type const syntax.

Update comments and error message to use new syntax instead of old type_const attribute.

Remove the type_const attribute

update some more tests to use the new syntax.

Update these test cases.

update feature gate test

Change gate logic for `mgca_type_const_syntax` to work also if `min_generic_const_args` is enabled.

Create a new feature gate that checks for the feature before expansion.

Make rustfmt handle the `type const` syntax correctly.

Add a convience method to check if a RhsKind is type const.

Rename `Const` discriminant to `Body` for `ConstItemRhsKind`

Give the `TraitItemKind` flag an enum instead of a simple bool to better describe what the flag is for.

Update formatting for these match statements.

Update clippy test to use type const syntax.

Update test to use type const syntax.

update rustfmt to match ast items.

Update clippy to match ast and hir items.

Few more test cases that used old attribute, instead of 'type const'

Update to match the output from the feature gate checks.

tidyfmt adjustments.

Update the is_type_const, so I can constrain record!(..) in encoder.rs

Update conditional compilation test.

Move the feature gate to after expansion to allow for cfg(...) to work.

Update some more tests to use the new syntax.

Update type const tests in associated-const-bindings to use new syntax.

Don't check based off the attribute, but the item here.

Update some tests outside of the const_generics folder that were using #[type_const]

update the tests in associated consts that use #[type_const] to use type const

Update these mgca tests with the type const syntax.

Add a flag to TraitItemKind for detecting type const for now. Maybe later change ItemConstRhs to have optional consts but that touches a lot more lines of code.

Don't need into for these now that it's a query.

Add is_type_const query to handle foreign def ids.

update this test to use type const syntax.

Fix logic here, we only want to lower if there is expression in this case.

Update built-in macros to use ConstItemRhsKind

Update more instance of the old ConstItemRhs.

Rename ConstItemKind to ConstItemRhsKind, I noticed there is a typed called ConstantItemKind, so add the Rhs to the name to avoid confusion.

Update lower to use ConstItemKind

Add an other helper method to check if the rhs kinda has an expr.

Update item parse to use ConstItemKind enum.

Felt the field name could a be little clear when editing a few other things.

Change the ConstItem struct see know if we have a type const or regular const.

Make sure this syntax is properly feature gated.
2026-02-09 07:59:24 -08:00
Jonathan Brouwer c1091da34c Fix existing messages in stderrs 2026-02-07 09:13:42 +01:00
Guillaume Gomez c910511cab Move remaining doc attribute parsing errors to warnings 2026-02-04 10:54:45 +01:00
Guillaume Gomez 6d713489d0 Make more doc attribute parsing error into future warnings 2026-02-04 10:54:45 +01:00
Guillaume Gomez 7dbbab63e2 Emit a future error warning for duplicate doc attribute 2026-02-04 10:54:44 +01:00
Jonathan Brouwer 775abf4f36 Rollup merge of #151449 - GuillaumeGomez:regression-test-for-151411, r=lolbinarycat
[rustdoc] Add regression test for #151411

Fixes rust-lang/rust#151411.

Seems like the ICE was already solved by https://github.com/rust-lang/rust/pull/151255. Well in any case, more regression tests won't hurt.

r? @lolbinarycat
2026-01-28 21:10:54 +01:00
Guillaume Gomez 35ccf18477 Add regression test for #151411 2026-01-28 00:23:30 +01:00