479 Commits

Author SHA1 Message Date
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
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
Samuel Tardieu
fc4b3fa3f9
Rollup merge of #132748 - lolbinarycat:rustdoc-intra-doc-link-warn-more-54191, r=GuillaumeGomez
get rid of some false negatives in rustdoc::broken_intra_doc_links

rustdoc will not try to do intra-doc linking if the "path" of a link looks too much like a "real url".

however, only inline links (`[text](url)`) can actually contain a url, other types of links (reference links, shortcut links) contain a *reference* which is later resolved to an actual url.

the "path" in this case cannot be a url, and therefore it should not be skipped due to looking like a url.

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

to minimize the number of false positives that will be introduced, the following heuristic is used:

If there's no backticks, be lenient revert to old behavior.
This is to prevent churn by linting on stuff that isn't meant to be a link.
only shortcut links have simple enough syntax that they
are likely to be written accidentlly, collapsed and reference links
need 4 metachars, and reference links will not usually use
backticks in the reference name.
therefore, only shortcut syntax gets the lenient behavior.
here's a truth table for how link kinds that cannot be urls are handled:

|              |  is shortcut link  | not shortcut link |
|--------------|--------------------|-------------------|
| has backtick |    never ignore    |    never ignore   |
| no backtick  | ignore if url-like |    never ignore   |
2025-08-02 11:24:20 +02:00
Samuel Tardieu
61760fbda4
Rollup merge of #144308 - GuillaumeGomez:merged-doctest-times, r=lolbinarycat
[rustdoc] Display total time and compilation time of merged doctests

Fixes rust-lang/rust#144270.

Does it look good to you `@kpreid?`

<img width="908" height="263" alt="image" src="https://github.com/user-attachments/assets/cd5d082d-c4e0-42ed-91dd-bd263b413dcd" />
2025-07-30 19:49:02 +02:00
Scott Schafer
aa9767290e
feat: Right align line numbers 2025-07-28 16:32:11 -06:00
binarycat
bd85df192d move bad-intra-doc test into intra-doc dir 2025-07-24 11:17:14 -05:00
binarycat
6a7d4882a2 rustdoc::broken_intra_doc_links: only be lenient with shortcut links
collapsed links and reference links have a pretty particular syntax,
it seems unlikely they would show up on accident.

Co-authored-by: León Orell Valerian Liehr <me@fmease.dev>
2025-07-24 11:17:14 -05:00
binarycat
041348110e rustdoc: update tests to match new lint behavior 2025-07-24 11:17:14 -05:00
binarycat
87d7d80cec adjust more unit tests to reflect more aggressive intra-doc linting 2025-07-24 11:17:13 -05:00
binarycat
5ae2d42a8c get rid of some false negatives in rustdoc::broken_intra_doc_links
rustdoc will not try to do intra-doc linking if the "path"
of a link looks too much like a "real url".

however, only inline links ([text](url)) can actually contain
a url, other types of links (reference links, shortcut links)
contain a *reference* which is later resolved to an actual url.

the "path" in this case cannot be a url, and therefore it should
not be skipped due to looking like a url.

Co-authored-by: Michael Howell <michael@notriddle.com>
2025-07-24 11:17:13 -05:00
Guillaume Gomez
64e3078bbd Update rustdoc ui tests 2025-07-24 11:06:28 +02:00
Camille GILLOT
87a27f94b0 Specify of_trait in Target::Impl. 2025-07-17 22:21:21 +00:00