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
Michael Howell
0344a02261
rustdoc: add test case for --cap-lints=allow
2026-05-15 11:13:16 -07: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
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
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
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
binarycat
6fd96ddc3d
rustdoc_missing_doc_code_examples: lint on macro_rules macros
2026-04-01 15:17:23 -05:00
Guillaume Gomez
6d3b7809cf
Add more tests for rustdoc missing_doc_code_examples lint
2026-03-18 17:28:55 +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
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
Guillaume Gomez
ef1e4e65b7
Move checks from check_doc_attrs directly into rustc_attr_parsing
2026-01-11 18:36:03 +01:00
Guillaume Gomez
d025cdef7d
If there are too many suggestions for malformed attribute, do not suggest them
2025-12-12 14:55:17 +01:00
Guillaume Gomez
4936973d49
Fix ui tests
2025-12-10 12:28:05 +01:00
Guillaume Gomez
e4f57dd4b3
Finish fixing ui tests
2025-12-10 12:27:34 +01:00
Guillaume Gomez
9c8c67bfdd
Fix warning messages
2025-12-10 12:27:34 +01:00
Aarav Desai
0715745c1c
Move rustdoc tests to appropriate subdirectories
...
Reorganize rustdoc tests into their correct subdirectories for better
categorization:
- Move lint-related tests to rustdoc-ui/lints/
- Move intra-doc link tests to rustdoc-ui/intra-doc/
- Move deref-related tests to rustdoc-ui/deref/
- Move doc-cfg test to rustdoc/doc-cfg/
This improves test organization and makes it easier to find tests
related to specific rustdoc functionality.
2025-10-26 19:16:41 -07:00
James Barford-Evans
2c1e796ed0
Improve missing create level error message
2025-10-08 11:35:20 +01:00
Guillaume Gomez
553308b115
Improve code and better check doc(cfg(...)) attributes
2025-09-27 11:29:49 +02:00
Guillaume Gomez
1561efe41a
Add code documentation, improve code and improve error message
2025-09-27 11:29:49 +02:00
Guillaume Gomez
c06a076634
Put back the doc_cfg code behind a nightly feature
2025-09-27 11:29:49 +02:00
Guillaume Gomez
63aefe0737
Strenghten checks for doc(auto_cfg(show/hide)) attributes
2025-09-27 11:29:48 +02:00
Guillaume Gomez
6537278e11
Update rustdoc tests
2025-09-27 11:29:48 +02:00
binarycat
82c4018619
fix ICE in rustdoc::invalid_html_tags
2025-09-22 14:57:36 -05:00
Guillaume Gomez
3205e4db0f
Add new ui tests for rustdoc::bare_urls
2025-09-10 18:44:20 +02:00
binarycat
15a8999aed
refactor rustdoc::invalid_html_tags tag parser
...
previously, this lint did not distinguish between `<img` and `<img>`,
and since the latter should be accepted under html5,
the former was also accepted.
the parser now also handles multi-line tags and multi-line attributes.
2025-08-21 15:00:01 -05:00
binarycat
e50fed79a8
add regression test for #145529
2025-08-21 15:00:00 -05:00
binarycat
87d7d80cec
adjust more unit tests to reflect more aggressive intra-doc linting
2025-07-24 11:17:13 -05:00
Guillaume Gomez
3b5525bc42
Improve code and documentation
2025-06-23 16:12:49 +02:00
Guillaume Gomez
a0d64177f0
Add ui test for redundant_explicit_links rustdoc lint for items coming from expansion
2025-06-23 16:02:33 +02:00
binarycat
3005a09fed
rustdoc: improve diagnostics on raw doc fragments
...
1. rustdoc::bare_urls doesn't output
invalid suggestions if source_span_for_markdown_range
fails to find a span
2. source_span_for_markdown_range tries harder to
return a span by applying an additional diagnostic
fixes https://github.com/rust-lang/rust/issues/135851
2025-05-22 12:31:28 -05:00
Vadim Petrochenkov
4d64990690
compiletest: Require //~ annotations even if error-pattern is specified
2025-04-03 11:08:55 +03:00
Vadim Petrochenkov
8d5109aa6e
compiletest: Support matching on diagnostics without a span
2025-03-25 17:33:09 +03:00
Esteban Küber
f0845adb0c
Show diff suggestion format on verbose replacement
...
```
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> $DIR/attempted-access-non-fatal.rs:7:15
|
LL | let _ = 2.l;
| ^
|
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
|
LL - let _ = 2.l;
LL + let _ = 2.0f64;
|
```
2025-02-10 20:21:39 +00:00
Zalathar
835fbcbcab
Remove the -test suffix from normalize directives
2024-12-27 19:58:16 +11:00
Esteban Küber
19e44f4db4
Point at lint name instead of whole attr for gated lints
...
```
warning: unknown lint: `test_unstable_lint`
--> $DIR/warn-unknown-unstable-lint-inline.rs:4:10
|
LL | #![allow(test_unstable_lint, another_unstable_lint)]
| ^^^^^^^^^^^^^^^^^^
|
= note: the `test_unstable_lint` lint is unstable
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
note: the lint level is defined here
--> $DIR/warn-unknown-unstable-lint-inline.rs:3:9
|
LL | #![warn(unknown_lints)]
| ^^^^^^^^^^^^^
warning: unknown lint: `test_unstable_lint`
--> $DIR/warn-unknown-unstable-lint-inline.rs:4:29
|
LL | #![allow(test_unstable_lint, another_unstable_lint)]
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: the `test_unstable_lint` lint is unstable
= help: add `#![feature(test_unstable_lint)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
note: the lint level is defined here
--> $DIR/warn-unknown-unstable-lint-inline.rs:3:9
|
LL | #![warn(unknown_lints)]
| ^^^^^^^^^^^^^
```
This is particularly relevant when there are multiple lints in the same `warn` attribute. Pointing at the smaller span makes it clearer which one the warning is complaining about.
2024-12-18 19:27:44 +00:00
Esteban Küber
9f1044ef76
Account for /// when rendering multiline spans
...
Don't consider `///` and `//!` docstrings to be empty for the purposes of multiline span rendering.
2024-12-13 18:48:33 +00:00
Esteban Küber
49a22a4245
Filter empty lines, comments and delimiters from previous to last multiline span rendering
2024-12-12 23:36:27 +00:00
Esteban Küber
65a54a7f27
Tweak multispan rendering
...
Consider comments and bare delimiters the same as an "empty line" for purposes of hiding rendered code output of long multispans. This results in more aggressive shortening of rendered output without losing too much context, specially in `*.stderr` tests that have "hidden" comments.
2024-12-12 23:36:27 +00:00
Guillaume Gomez
7cf3f8ba7a
Do not emit missing_doc_code_examples rustdoc lint on module and a few other items
2024-11-28 21:22:06 +01:00
Guillaume Gomez
632fed891d
Improve mistyped docblock attribute warning messages
2024-09-28 18:38:11 +02:00
Esteban Küber
140392b041
Adjust rustdoc automatic link suggestion
...
Use more accurate spans for multipart suggestion.
2024-07-04 00:40:04 +00:00
xFrednet
d9e32a69a7
RFC 2373: Update tests for rustdoc for lint_reasons
2024-06-25 17:50:55 +02:00
xFrednet
8b14e23dce
RFC 2383: Stabilize lint_reasons 🎉
2024-06-25 17:22:22 +02:00
Esteban Küber
cc9631a371
When displaying multispans, ignore empty lines adjacent to ...
...
```
error[E0308]: `match` arms have incompatible types
--> tests/ui/codemap_tests/huge_multispan_highlight.rs:98:18
|
6 | let _ = match true {
| ---------- `match` arms have incompatible types
7 | true => (
| _________________-
8 | | // last line shown in multispan header
... |
96 | |
97 | | ),
| |_________- this is found to be of type `()`
98 | false => "
| __________________^
... |
119 | |
120 | | ",
| |_________^ expected `()`, found `&str`
error[E0308]: `match` arms have incompatible types
--> tests/ui/codemap_tests/huge_multispan_highlight.rs:215:18
|
122 | let _ = match true {
| ---------- `match` arms have incompatible types
123 | true => (
| _________________-
124 | |
125 | | 1 // last line shown in multispan header
... |
213 | |
214 | | ),
| |_________- this is found to be of type `{integer}`
215 | false => "
| __________________^
216 | |
217 | |
218 | | 1 last line shown in multispan
... |
237 | |
238 | | ",
| |_________^ expected integer, found `&str`
```
2024-03-18 16:25:36 +00:00
Guillaume Gomez
8e817af3ae
Update ui tests
2024-02-29 14:43:43 +01:00