Commit graph

489 commits

Author SHA1 Message Date
León Orell Valerian Liehr
36e6625457
[beta] rustdoc: Stop unconditionally evaluating the initializer of associated consts 2026-01-17 12:25:36 +01:00
xonx4l
4b000cfacd Merge E0412 into E0425 2025-12-02 18:25:13 +00:00
Matthias Krüger
97b5b9b817
Rollup merge of #148169 - fmease:rustdoc-bad-intra-bad-preprocess, r=lolbinarycat
Fix bad intra-doc-link preprocessing

How did rust-lang/rust#147981 happen?

1. We don't parse intra-doc links as Rust paths or qpaths. Instead they follow a very lenient bespoke grammar. We completely ignore Markdown links if they contain characters that don't match `/[a-zA-Z0-9_:<>, !*&;]/` (we don't even emit lint *broken-intra-doc-links* for these).
2. PR [#132748](https://github.com/rust-lang/rust/pull/132748) made rustdoc intepret more Markdown links as potential intra-doc links. Namely, if the link is surrounded by backticks (and some other conditions apply) then it doesn't matter if the (partially processed) link contains bad characters as defined above (cc `ignore_urllike && should_ignore_link(path_str)`).
3. However, rustdoc's `preprocess_link` must be kept in sync with a simplified counterpart in rustc. More specifically, whenever rustdoc's preprocessor returns a successful result then rustc's must yield the same result. Otherwise, rustc doesn't resolve the necessary links for rustdoc.
4. This uncovered a "dormant bug" / "mistake" in rustc's `preprocess_link`. Namely, when presented with a link like `struct@Type@suffix`, it didn't cut off the disambiguator if present (here: `struct@`). Instead it `rsplit('``@')``` which is incorrect if the "path" contains ```@``` itself (yielding `suffix` instead of `Type@suffix` here). Prior to PR [#132748](https://github.com/rust-lang/rust/pull/132748), a link like ``[`struct@Type@suffix`]`` was not considered a potential intra-doc link / worth querying rustc for. Now it is due to the backticks.
5. Finally, since rustc didn't record a resolution for `Type@suffix` (it only recorded `suffix` (to be `Res::Err`)), we triggered an assertion we have in place to catch cases like this.

Fixes rust-lang/rust#147981.

I didn't and still don't have the time to investigate if rust-lang/rust#132748 led to more rustc/rustdoc mismatches (after all, the PR made rustdoc's `preprocess_link` return `Some(Ok(_))` in more cases). I've at least added another much needed "warning banner" & made the existing one more flashy.

While this fixes a stable-to-beta regression, I don't think it's worth beta backporting, esp. since it's only P-medium and since the final 1.91 release steps commence today / the next days, so it would only be stressful to get it in on time. However, feel free to nominate.

<sub>(I've written such a verbose PR description since I tend to reread my old PR descriptions in the far future to fully freshen my memories when I have to work again in this area)</sub>

r? ``@lolbinarycat``
2025-11-30 18:44:22 +01:00
León Orell Valerian Liehr
55d90c0653
Fix bad intra-doc-link preprocessing 2025-11-30 13:08:59 +01:00
lcnr
8e08af1769 fix tooling 2025-11-26 11:09:03 +01:00
Jacob Pratt
fdcf1f2d80
Rollup merge of #149197 - lolbinarycat:rustdoc-bad-render-attr, r=GuillaumeGomez
validate usage of crate-level doc attributes

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

r? `@GuillaumeGomez`
2025-11-23 16:28:13 -05:00
binarycat
2ee6196078 validate usage of crate-level doc attributes 2025-11-23 12:00:53 -06:00
Scott Schafer
1befb0bac0
fix: Only add extra padding to the first group's last file 2025-11-18 19:26:02 -07:00
Stuart Cook
6487148d80
Rollup merge of #146495 - fmease:rustdoc-erase-doc-priv-items-attr, r=GuillaumeGomez
rustdoc: Erase `#![doc(document_private_items)]`

I just found out about the existence of `#![doc(document_private_items)]`. Apparently it was added by PR rust-lang/rust#50669 back in 2018 without any tests or docs as a replacement for some specific forms of the removed `#![doc(passes)]` / `#![doc(no_default_passes)]`.

However, rustc and rustdoc actually emit the deny-by-default lint `invalid_doc_attributes` for it (but if you allow it, the attribute does function)! To be more precise since PR rust-lang/rust#82708 (1.52, May 2021) which introduced lint `invalid_doc_attributes`, rust{,do}c has emitted a future-incompat warning for this attribute. And since PR rust-lang/rust#111505 (1.78, May 2024) that lint is deny by default. I presume nobody knew this attribute existed and thus it was never allowlisted.

Given the fact that since 2021 nobody has ever opened a ticket ([via](https://github.com/rust-lang/rust/issues?q=is%3Aissue+document_private_items)) complaining about the lint emission and the fact that GitHub code search doesn't yield any actual uses ([via](https://github.com/search?q=%2F%23%21%5C%5Bdoc%5C%28.*%3Fdocument_private_items%2F+language%3ARust&type=code&ref=advsearch)), I'm led to believe that nobody knows about and uses this attribute.

I don't find the existence of this attribute to be justified since in my view the flag `--document-private-items` is strictly superior: In most if not all cases, you don't want to "couple" your crate with this "mode" even if you gate it behind a cfg; instead, you most likely want to set this manually at invocation time, via a build config file like `.cargo/config.toml` or via a command runner like `just` I'd say.

Because of this I propose to wipe this attribute from existence. I don't believe it's worth cratering this (i.e., temporarily emitting a hard error for this attribute and running crater) given the fact that it's been undocumented since forever and led to a warning for years.
2025-11-11 21:09:33 +11:00
bors
72b21e1a64 Auto merge of #139558 - camelid:mgca-const-items, r=oli-obk,BoxyUwU
mgca: Add ConstArg representation for const items

tracking issue: rust-lang/rust#132980
fixes rust-lang/rust#131046
fixes rust-lang/rust#134641

As part of implementing `min_generic_const_args`, we need to distinguish const items that can be used in the type system, such as in associated const equality projections, from const items containing arbitrary const code, which must be kept out of the type system. Specifically, all "type consts" must be either concrete (no generics) or generic with a trivial expression like `N` or a path to another type const item.

To syntactically distinguish these cases, we require, for now at least, that users annotate all type consts with the `#[type_const]` attribute. Then, we validate that the const's right-hand side is indeed eligible to be a type const and represent it differently in the HIR.

We accomplish this representation using a new `ConstItemRhs` enum in the HIR, and a similar but simpler enum in the AST. When `#[type_const]` is **not** applied to a const (e.g. on stable), we represent const item right-hand sides (rhs's) as HIR bodies, like before. However, when the attribute is applied, we instead lower to a `hir::ConstArg`. This syntactically distinguishes between trivial const args (paths) and arbitrary expressions, which are represented using `AnonConst`s. Then in `generics_of`, we can take advantage of the existing machinery to bar the `AnonConst` rhs's from using parent generics.
2025-11-08 22:31:33 +00:00
Noah Lev
ad69a7a449 Fix rustdoc UI tests
Also removed a test that was literally a duplicate of the one I kept.
2025-11-08 13:50:48 -05:00
Scott Schafer
9243928c6c
feat: Use annotate-snippets by default on nightly 2025-11-05 09:01:07 -07:00
Matthias Krüger
844a41903e
Rollup merge of #148290 - oli-obk:push-qwxvxyopypry, r=nnethercote
Do not emit solver errors that contain error types

any follow-up errors are going to either be duplicates or often disappear if the error itself is fixed.

in this PR it mostly silences dyn-compat errors as all the other errors are already deduplicated outside of the test suite. The dyn compat errors are independent errors and I think if the dyn compatiblity depended on an error type it would not actually show, so this is PR is actually silencing independent errors, too.

I am opening this PR because I am seeing lots of `{type error}: const Trait` errors when adding more const checking. So instead of targetting just those specific errors, I wanted to try out fully avoiding such errors near the trait solver.

cc ````@rust-lang/types```` for thoughts
2025-11-02 09:10:38 +01:00
Oli Scherer
cac6f8760a Do not emit solver errors that contain error types 2025-10-31 08:17:44 +00:00
Jacob Pratt
35fcb55827
Rollup merge of #148115 - fmease:rustdoc-no-capture, r=notriddle
rustdoc: Rename unstable option `--nocapture` to `--no-capture` in accordance with `libtest`

Context: https://github.com/rust-lang/rust/issues/133073, https://github.com/rust-lang/rust/pull/139224 (TL;DR: `libtest` has soft-deprecated `--nocapture` in favor a new & stable `--no-capture`; we should follow suit).

Since the rustdoc flag is unstable (tracking issue: https://github.com/rust-lang/rust/issues/148116), we're allowed to remove the old flag immediately. However since the flag has existed for 4 years we could hard-deprecate the flag first or at least be considerate and provide a diagnostic referring users to the new flag. This PR does neither. Let me know what you would think would be best.

Cargo doesn't use this flag, not yet at least (https://github.com/rust-lang/cargo/pull/9705), so we really are free to sunset this flag without bigger consequences.
2025-10-30 02:43:43 -04: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
León Orell Valerian Liehr
11b82e134c
rustdoc: Rename unstable option --nocapture to --no-capture 2025-10-25 19:45:49 +02:00
Guillaume Gomez
e1e851dc57 [rustdoc] Check doc(cfg()) even of private/hidden items 2025-10-22 17:32:20 +02:00
Stuart Cook
f87f9a456c
Rollup merge of #147734 - fmease:tighten-relaxed, r=lcnr
Further tighten up relaxed bounds

Follow-up to rust-lang/rust#142693, rust-lang/rust#135331 and rust-lang/rust#135841.
Fixes rust-lang/rust#143122.

* Reject relaxed bounds `?Trait` in the bounds of trait aliases.
  Just like `trait Trait {}` doesn't mean `trait Trait: Sized {}` and we therefore reject `trait Trait: ?Sized {}`, `trait Trait =;` (sic!) doesn't mean `trait Trait = Sized;` (never did!) and as a logical consequence `trait Trait = ?Sized;` is meaningless and should be forbidden.
* Don't permit `?Sized` in more places (e.g., supertrait bounds, trait object types) if feature `more_maybe_bounds` is enabled.
  That internal feature is only meant to allow the user to define & use *new* default traits (that have fewer rules to follow for now to ease experimentation).
* Unconditionally check that the `Trait` in `?Trait` is a default trait.
  Previously, we would only perform this check in selected places which was very brittle and led to bugs slipping through.
* Slightly improve diagnostics.
2025-10-20 22:30:53 +11:00
Guillaume Gomez
b3bb7500b6 Add regression tests for intra-doc links 2025-10-17 15:55:28 +02:00
León Orell Valerian Liehr
ce68cd3762
Reject relaxed bounds inside trait alias bounds 2025-10-16 19:53:31 +02:00
James Barford-Evans
2c1e796ed0 Improve missing create level error message 2025-10-08 11:35:20 +01:00
Matthias Krüger
dbc5e72ea2
Rollup merge of #147292 - Urgau:rustdoc-test-unstable_opts, r=fmease
Respect `-Z` unstable options in `rustdoc --test`

This PR makes rustdoc respect `-Z` unstable options when collecting doctests (`rustdoc --test`).

In the process I also realized that `--error-format` wasn't respected as well, making UI annotations impossible to write so I fixed that as well.

Best reviewed commit by commit.

Fixes https://github.com/rust-lang/rust/issues/147276
Fixes https://github.com/rust-lang/rust/issues/143930
r? fmease
2025-10-03 21:10:33 +02:00
Urgau
c1443e2591 Add regression test for -Zcrate-attr in rustdoc --test 2025-10-03 17:04:17 +02:00
Urgau
e914a1a6e0 Respect --error-format in rustdoc --test 2025-10-03 17:04:17 +02:00
Urgau
3d5f54ad55 Respect -Z unstable options in rustdoc --test 2025-10-03 12:05:31 +02:00
Guillaume Gomez
06a6dcd4d2 Move doc cfg propagation pass before items stripping passes 2025-09-29 18:08:51 +02:00
Matthias Krüger
a11a211d7c
Rollup merge of #147032 - GuillaumeGomez:fix-doctest-compilation-time-display, r=lolbinarycat
Fix doctest compilation time display

Fixes rust-lang/rust#146960.

Small corner case that happened in case everything went fine and there was only merged doctests.

r? lolbinarycat
2025-09-27 21:25:58 +02:00
Guillaume Gomez
653e1036ed Apply first review round suggestions 2025-09-27 11:29:50 +02:00
Guillaume Gomez
77885fef2c Improve code comments and extend tests for doc_cfg feature 2025-09-27 11:29:50 +02: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
Guillaume Gomez
b7e444de16 Add regression test for merged doctests compilation time display 2025-09-26 22:04:00 +02:00
Guillaume Gomez
dba45cde68 Add tests for new tyalias intra-doc link disambiguator 2025-09-26 15:07:12 +02:00
binarycat
82c4018619 fix ICE in rustdoc::invalid_html_tags 2025-09-22 14:57:36 -05:00
León Orell Valerian Liehr
044d15b748
Erase #![doc(document_private_items)] 2025-09-13 02:52:01 +02:00
Guillaume Gomez
3205e4db0f Add new ui tests for rustdoc::bare_urls 2025-09-10 18:44:20 +02:00
Guillaume Gomez
f3c023433f Add ui test for unsupported doc(attribute = "...") case for attributes with namespace 2025-08-28 18:24:58 +02:00
Guillaume Gomez
75cbd05d19 Add tests for doc(attribute = "...") attribute 2025-08-28 15:56:30 +02:00
Stuart Cook
aecc0287ef
Rollup merge of #145535 - lolbinarycat:rustdoc-invalid_html_tags-svg-145529, r=GuillaumeGomez
make rustdoc::invalid_html_tags more robust

best reviewed a commit at a time.

I kept finding more edge case so I ended up having to make quite significant changes to the parser in order to make it preserve state across events and handle multiline attributes correctly.

fixes rust-lang/rust#145529
2025-08-26 14:19:16 +10:00
Camille Gillot
0327e2b87e Bless rustdoc-ui. 2025-08-22 20:31:24 +00: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
Jonathan Brouwer
4bb7bf64e0
Update uitests
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-14 18:18:42 +02:00
Stuart Cook
31e5316cd9
Rollup merge of #144921 - lolbinarycat:rustdoc-intra-doc-gfm-141866, r=fmease,GuillaumeGomez
Don't emit `rustdoc::broken_intra_doc_links` for GitHub-flavored Markdown admonitions like `[!NOTE]`

fixes rust-lang/rust#141866
2025-08-12 20:37:50 +10:00
binarycat
c022ed9927 don't emit rustdoc::broken_intra_doc_links for stuff like [!NOTE] 2025-08-11 10:50:44 -05:00
Trevor Gross
289fe36d37 Print thread ID in panic message if thread name is unknown
`panic!` does not print any identifying information for threads that are
unnamed. However, in many cases, the thread ID can be determined.

This changes the panic message from something like this:

    thread '<unnamed>' panicked at src/main.rs:3:5:
    explicit panic

To something like this:

    thread '<unnamed>' (0xff9bf) panicked at src/main.rs:3:5:
    explicit panic

Stack overflow messages are updated as well.

This change applies to both named and unnamed threads. The ID printed is
the OS integer thread ID rather than the Rust thread ID, which should
also be what debuggers print.
2025-08-06 23:59:47 +00:00