427 Commits

Author SHA1 Message Date
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
Vadim Petrochenkov
20faf8532b compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
Guillaume Gomez
a782b54e01
Rollup merge of #140220 - GuillaumeGomez:doctest-main-wrapping, r=fmease
Fix detection of main function if there are expressions around it

Fixes #140162.
Fixes #139651.

Once this is merged, we can backport and I'll send a follow-up to emit a warning in case a `main` function is about to be "wrapped" (and therefore not run).

r? `@fmease`

try-job: x86_64-mingw-1
2025-04-28 13:30:44 +02:00
Guillaume Gomez
aa69e3a0cb Fix bad handling of macros if there is already a main function 2025-04-27 00:12:32 +02:00
Guillaume Gomez
3ef98a55ef If there is a ; alone, we consider that the doctest needs to be put inside a function 2025-04-25 22:04:50 +02:00
Guillaume Gomez
c44068b916 Add rustdoc-ui regression test for #140289 2025-04-25 15:55:54 +02:00
Guillaume Gomez
70c389e069 Correctly display stdout and stderr in case a doctest is failing 2025-04-25 14:13:24 +02:00
Guillaume Gomez
81438c0b05 Add regression ui test for #140162 and for #139651 2025-04-23 22:09:35 +02:00
Guillaume Gomez
88a5e1ef68 Add regression test for #140026 2025-04-19 21:10:40 +02:00
Matthias Krüger
0de803c38d
Rollup merge of #138632 - clubby789:stabilize-cfg-boolean-lit, r=davidtwco,Urgau,traviscross
Stabilize `cfg_boolean_literals`

Closes #131204
`@rustbot` labels +T-lang +I-lang-nominated
This will end up conflicting with the test in #138293 so whichever doesn't land first will need updating

--

# Stabilization Report

## General design

### What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized?

[RFC 3695](https://github.com/rust-lang/rfcs/pull/3695), none.

### What behavior are we committing to that has been controversial? Summarize the major arguments pro/con.

None

### Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those?

None

## Has a call-for-testing period been conducted? If so, what feedback was received?

Yes; only positive feedback was received.

## Implementation quality

### Summarize the major parts of the implementation and provide links into the code (or to PRs)

Implemented in [#131034](https://github.com/rust-lang/rust/pull/131034).

### Summarize existing test coverage of this feature

- [Basic usage, including `#[cfg()]`, `cfg!()` and `#[cfg_attr()]`](6d71251cf9/tests/ui/cfg/true-false.rs)
- [`--cfg=true/false` on the command line being accessible via `r#true/r#false`](6d71251cf9/tests/ui/cfg/raw-true-false.rs)
- [Interaction with the unstable `#[doc(cfg(..))]` feature](https://github.com/rust-lang/rust/tree/6d71251/tests/rustdoc-ui/cfg-boolean-literal.rs)
- [Denying `--check-cfg=cfg(true/false)`](https://github.com/rust-lang/rust/tree/6d71251/tests/ui/check-cfg/invalid-arguments.rs)
- Ensuring `--cfg false` on the command line doesn't change the meaning of `cfg(false)`: `tests/ui/cfg/cmdline-false.rs`
- Ensuring both `cfg(true)` and `cfg(false)` on the same item result in it being disabled: `tests/ui/cfg/both-true-false.rs`

### What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking?

The above mentioned issue; it should not block as it interacts with another unstable feature.

### What FIXMEs are still in the code for that feature and why is it ok to leave them there?

None

### Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization
- `@clubby789` (RFC)
- `@Urgau` (Implementation in rustc)

### Which tools need to be adjusted to support this feature. Has this work been done?

`rustdoc`'s  unstable`#[doc(cfg(..)]` has been updated to respect it. `cargo` has been updated with a forward compatibility lint to enable supporting it in cargo once stabilized.

## Type system and execution rules

### What updates are needed to the reference/specification? (link to PRs when they exist)

A few lines to be added to the reference for configuration predicates, specified in the RFC.
2025-04-17 06:25:15 +02:00
León Orell Valerian Liehr
307a67a02a
Replace flag --doctest-compilation-args with a simpler one: --doctest-build-arg
More notably, the value of the new flag does *not* get lexed shell-like and ad hoc.
2025-04-15 15:44:45 +02:00
bors
07d3fd1d9b Auto merge of #138603 - xizheyin:issue-137405, r=chenyukang
Report line number of test when should_panic test failed

Closes #137405

---

try-job: x86_64-gnu-llvm-19-3
try-job: test-various
2025-04-14 13:33:44 +00:00
xizheyin
c73598f0fb Report span of test when should_panic test failed
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-14 10:36:11 +08:00
Vadim Petrochenkov
93bee0789a UI tests: migrate remaining compile time error-patterns to line annotations
when possible.
2025-04-13 21:48:53 +03:00
bors
71b68da1bd Auto merge of #139578 - ferrocene:pa-compiletest-edition, r=jieyouxu
Fix breakage when running compiletest with `--test-args=--edition=2015`

Compiletest has an `--edition` flag to change the default edition tests are run with. Unfortunately no test suite successfully executes when that flag is passed. If the edition is set to something greater than 2015 the breakage is expected, since the test suite currently supports only edition 2015 (Ferrous Systems will open an MCP about fixing that soonish). Surprisingly, the test suite is also broken if `--edition=2015` is passed to compiletest. This PR focuses on fixing the latter.

This PR fixes the two categories of failures happening when `--edition=2015` is passed:

* Some edition-specific tests set their edition through `//@ compile-flags` instead of `//@ edition`. Compiletest doesn't parse the compile flags, so it would see no `//@ edition` and add another `--edition` flag, leading to a rustc error.
* Compiletest would add the edition after `//@ compile-flags`, while some tests depend on flags passed to `//@ compile-flags` being the last flags in the rustc invocation.

Note that for the first category, I opted to manually go and replace all `//@ compile-flags` setting an edition with an explicit `//@ edition`. We could've changed compiletest to instead check whether an edition was set in `//@ compile-flags`, but I thought it was better to enforce a consistent way to set the edition in tests.

I also added the edition to the stamp, so that changing `--edition` results in tests being re-executed.

r? `@jieyouxu`
2025-04-11 10:53:45 +00:00
Pietro Albini
cd371b90e2
replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
Noah Lev
8b227a42fa rustdoc: Enable Markdown extensions when looking for doctests
We should enable these to avoid misinterpreting uses of the extended
syntax as code blocks. This happens in practice with multi-paragraph
footnotes, as discovered in #139064.
2025-04-09 13:04:57 -04:00
Vadim Petrochenkov
b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
Matthias Krüger
cfc2297cfc
Rollup merge of #139328 - GuillaumeGomez:fix-panic-output-137970, r=fmease
Fix 2024 edition doctest panic output

Fixes #137970.

The problem was that the output was actually displayed by rustc itself because we're exiting with `Result<(), String>`, and the display is really not great. So instead, we get the output, we print it and then we return an `ExitCode`.

r? ````@aDotInTheVoid````
2025-04-04 21:54:57 +02:00
clubby789
984c51f6a1 Stabilize cfg_boolean_literals 2025-04-03 18:10:48 +00:00
Guillaume Gomez
f9927ee042 Use eprint! instead of eprintln! 2025-04-03 19:37:18 +02:00