447 Commits

Author SHA1 Message Date
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
Scott Schafer
6bef238b63
refactor: Make -Ztrack-diagnostics emit like a note 2025-07-03 07:19:25 -06:00
Guillaume Gomez
76df2656df Replace ItemCtxt::report_placeholder_type_error match with a call to TyCtxt::def_descr 2025-06-30 20:36:16 +02: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
David Wood
da47753496
rustdoc: {Meta,Pointee,}Sized in non-minicore
Some rustdoc tests are `no_core` and need to have `MetaSized` and
`PointeeSized` added to them.
2025-06-16 23:04:36 +00:00
Guillaume Gomez
21aabafbd1 Add new extracted option doctest ui test for result returning doctest 2025-06-10 13:54:47 +02:00
Guillaume Gomez
5864247b10 Give more information into extracted doctest information 2025-06-10 13:54:46 +02:00
bors
c31cccb7b5 Auto merge of #142008 - RalfJung:const-eval-error-here, r=oli-obk
const-eval error: always say in which item the error occurred

I don't see why "is this generic" should make a difference. It may be reasonable to key this on whether the error occurs in a `const fn` that was invoked by a const (making it non-obvious which constant it is) vs inside the body of the const.

r? `@oli-obk`
2025-06-08 23:18:34 +00:00
Guillaume Gomez
2c8a9cccd9
Rollup merge of #140560 - Urgau:test_attr-module-level, r=GuillaumeGomez
Allow `#![doc(test(attr(..)))]` everywhere

This PR adds the ability to specify [`#![doc(test(attr(..)))]`](https://doc.rust-lang.org/nightly/rustdoc/write-documentation/the-doc-attribute.html#testattr) ~~at module level~~ everywhere in addition to allowing it at crate-root.

This is motivated by a recent PR #140323 (by ````@tgross35)```` where we have to duplicate 2 attributes to every single `f16` and `f128` doctests, by allowing `#![doc(test(attr(..)))]` at module level (and everywhere else) we can omit them entirely and just have (in both module):

```rust
#![doc(test(attr(feature(cfg_target_has_reliable_f16_f128))))]
#![doc(test(attr(expect(internal_features))))]
```

Those new attributes are appended to the one found at crate-root or at a previous module. Those "global" attributes are compatible with merged doctests (they already were before).

Given the small addition that this is, I'm proposing to insta-stabilize it, but I can feature-gate it if preferred.

Best reviewed commit by commit.

r? ````@GuillaumeGomez````
2025-06-07 22:22:55 +02:00
Ralf Jung
17946c22b1 const-eval error: always say in which item the error occurred
also adjust the wording a little so that we don't say "the error occurred here" for two different spans
2025-06-07 13:42:30 +02:00
Matthias Krüger
f574c0edb5
Rollup merge of #141698 - oli-obk:ctfe-err-flip, r=RalfJung
Use the informative error as the main const eval error message

r? `@RalfJung`

I only did the minimal changes necessary to the const eval error machinery. I'd prefer not to mix test changes with refactorings 😆
2025-06-03 21:53:37 +02:00
Oli Scherer
020216c31c Clarify why we are talking about a failed const eval at a random place 2025-06-02 15:37:15 +00:00
Oli Scherer
b331b8b96d Use the informative error as the main const eval error message 2025-06-02 15:37:15 +00:00
Urgau
9d0845a782 Rework #[doc(cfg(..))] checks as distinct pass in rustdoc 2025-05-29 21:50:14 +02:00
Trevor Gross
77c7f76297
Rollup merge of #141411 - lolbinarycat:rustdoc-link-proc-macro-91274, r=GuillaumeGomez
rustdoc: linking to a local proc macro no longer warns

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

tried to keep the fix general in case we ever have any other kind of item that occupies
multiple namespaces simultaniously.
2025-05-28 10:28:09 -04:00
binarycat
871327e9c7 rustdoc: linking to a local proc macro no longer warns
fixes https://github.com/rust-lang/rust/issues/91274

Co-authored-by: Guillaume Gomez <guillaume1.gomez@gmail.com>
2025-05-27 10:03:05 -05:00
Urgau
3fd0265fbb rustdoc: use custom CfgMatchesLintEmitter to make check-cfg work 2025-05-26 21:52:21 +02:00
Matthias Krüger
1c2ea28727
Rollup merge of #136400 - lolbinarycat:rustdoc-link-lint-135851, r=GuillaumeGomez
Improve handling of rustdoc lints when used with raw doc fragments.

1. `rustdoc::bare_urls` no longer outputs incoherent suggestions if `source_span_for_markdown_range` returns None, instead outputting no suggestion
2. `source_span_for_markdown_range` has one more heuristic, so it will return `None` less often.
3. add ui test to make sure we don't emit nonsense suggestions.

fixes https://github.com/rust-lang/rust/issues/135851
2025-05-23 13:34:17 +02:00
Urgau
d96d3bed6f Collect and use #[doc(test(attr(..)))] at every level 2025-05-22 20:12:50 +02:00
Urgau
316e62a058 Allow #![doc(test(attr(..)))] at every level 2025-05-22 20:12:50 +02:00
Urgau
041d95d4dc Allow #![doc(test(attr(..)))] doctests to be again merged together 2025-05-22 20:12:50 +02:00
Urgau
9d9705f4c3 Collect and use #![doc(test(attr(..)))] at module level too 2025-05-22 20:10:32 +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
Urgau
80c6a08850 Allow #![doc(test(attr(..)))] at module level too 2025-05-22 19:12:13 +02:00
bors
1d679446b0 Auto merge of #140527 - GuillaumeGomez:doctest-main-fn, r=notriddle
Emit a warning if the doctest `main` function will not be run

Fixes #140310.

I think we could try to go much further like adding a "link" (ie UI annotations) on the `main` function in the doctest. However that will require some more computation, not sure if it's worth it or not. Can still be done in a follow-up if we want it.

For now, this PR does two things:
1. Pass the `DiagCtxt` to the doctest parser to emit the warning.
2. Correctly generate the `Span` to where the doctest is starting (I hope the way I did it isn't too bad either...).

cc `@fmease`
r? `@notriddle`
2025-05-22 08:40:58 +00:00
Matthias Krüger
7a5bbe0527
Rollup merge of #139863 - fmease:simp-doctest-build-arg-passing, r=GuillaumeGomez
rustdoc: Replace unstable flag `--doctest-compilation-args` with a simpler one: `--doctest-build-arg`

Tracking issue: https://github.com/rust-lang/rust/issues/134172.
Context: https://github.com/rust-lang/rust/pull/137096#issuecomment-2776318800

Yeets the ad hoc shell-like lexer for 'nested' program arguments.
No FCP necessary since the flag is unstable.

I've chosen to replace `compilation` with `build` because it's shorter (you now need to pass it multiple times in order to pass many arguments to the doctest compiler, so it matters a bit) and since I prefer it esthetically.

**Issue**: Even though we don't process the argument passed to `--doctest-build-arg`, we end up passing it via an argument file (`rustc `@argfile`)` which delimits arguments by line break (LF or CRLF, [via](https://doc.rust-lang.org/rustc/command-line-arguments.html#path-load-command-line-flags-from-a-path)) meaning ultimately the arguments still get split which is unfortunate. Still, I think this change is an improvement over the status quo.

I'll update the tracking issue if/once this PR merges. I'll also add the (CR)LF issue to 'unresolved question'.

r? GuillaumeGomez
r? notriddle
2025-05-09 21:50:06 +02:00
Michael Howell
e648e5b710 rustdoc: remove unportable markdown lint and old parser
Follow up https://github.com/rust-lang/rust/pull/127127
2025-05-06 10:33:04 -07:00
Vadim Petrochenkov
56d6b4e427 compiletest: Support matching on non-json lines in compiler output
and migrate most of remaining `error-pattern`s to it.
2025-05-04 18:27:45 +03:00
Guillaume Gomez
5b86fa8282 Add regression test for #140310 2025-05-02 13:57:53 +02:00
Guillaume Gomez
b791eaa448 Emit a warning if the doctest main function will not be run 2025-05-02 13:57:53 +02:00
Guillaume Gomez
96faee497a
Rollup merge of #140420 - fmease:rustdoc-fix-doctest-heur, r=GuillaumeGomez
rustdoc: Fix doctest heuristic for main fn wrapping

Fixes #140412 which regressed in #140220 that I reviewed. As mentioned in https://github.com/rust-lang/rust/pull/140220#issuecomment-2837061779, at the time I didn't have the time to re-review its latest changes and should've therefore invalided my previous "r=me" and blocked the PR on another review given the fragile nature of the doctest impl. This didn't happen which is my fault.

Contains some other small changes. Diff best reviewed modulo whitespace.
r? ``@GuillaumeGomez``
2025-05-01 22:27:23 +02:00
León Orell Valerian Liehr
714ea10ea4
rustdoc: Fix doctest heuristic for main fn wrapping 2025-05-01 11:56:11 +02:00