rust
rust copied to clipboard
[rustdoc] Give more information into extracted doctest information
Follow-up of https://github.com/rust-lang/rust/pull/134531.
This update fragment the doctest code into its sub-parts to give more control to the end users on how they want to use it.
The new JSON looks like this:
{
"format_version":2,
"doctests":[
{
"file":"$DIR/extract-doctests-result.rs",
"line":8,
"doctest_attributes":{
"original":"",
"should_panic":false,
"no_run":false,
"ignore":"None",
"rust":true,
"test_harness":false,
"compile_fail":false,
"standalone_crate":false,
"error_codes":[],
"edition":null,
"added_css_classes":[],
"unknown":[]
},
"original_code":"let x = 12;\nOk(())",
"doctest_code":{
"crate_level":"#![allow(unused)]\n",
"code":"let x = 12;\nOk(())",
"wrapper":{
"before":"fn main() { fn _inner() -> core::result::Result<(), impl core::fmt::Debug> {\n",
"after":"\n} _inner().unwrap() }",
"returns_result":true
}
},
"name":"$DIR/extract-doctests-result.rs - (line 8)"
}
]
}
for this doctest:
let x = 12;
Ok(())
With this, I think it matches what you need @ojeda? If so, once merged I'll update the patch I sent to RfL.
r? @aDotInTheVoid
The job mingw-check-tidy failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
info: removing rustup binaries
info: rustup is uninstalled
##[group]Image checksum input
mingw-check-tidy
# We use the ghcr base image because ghcr doesn't have a rate limit
# and the mingw-check-tidy job doesn't cache docker images in CI.
FROM ghcr.io/rust-lang/ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
---
COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check/validate-error-codes.sh /scripts/
# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 python2.7 ../x.py test \
--stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#12 2.946 Building wheels for collected packages: reuse
#12 2.947 Building wheel for reuse (pyproject.toml): started
#12 3.162 Building wheel for reuse (pyproject.toml): finished with status 'done'
#12 3.163 Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132719 sha256=d2a2565e7037ad3883fb9337653f2e25bbb588534fbef3697286cbc26d1bf634
#12 3.164 Stored in directory: /tmp/pip-ephem-wheel-cache-yhbuhldf/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#12 3.166 Successfully built reuse
#12 3.166 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#12 3.570 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#12 3.570 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#12 4.134 Collecting virtualenv
#12 4.184 Downloading virtualenv-20.31.2-py3-none-any.whl (6.1 MB)
#12 4.431 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.1/6.1 MB 24.7 MB/s eta 0:00:00
#12 4.498 Collecting filelock<4,>=3.12.2
#12 4.506 Downloading filelock-3.18.0-py3-none-any.whl (16 kB)
#12 4.528 Collecting distlib<1,>=0.3.7
#12 4.536 Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB)
#12 4.548 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 48.1 MB/s eta 0:00:00
#12 4.586 Collecting platformdirs<5,>=3.9.1
#12 4.593 Downloading platformdirs-4.3.8-py3-none-any.whl (18 kB)
#12 4.677 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#12 4.874 Successfully installed distlib-0.3.9 filelock-3.18.0 platformdirs-4.3.8 virtualenv-20.31.2
#12 4.874 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#12 DONE 5.0s
#13 [7/8] COPY host-x86_64/mingw-check/validate-toolstate.sh /scripts/
#13 DONE 0.0s
---
DirectMap4k: 151488 kB
DirectMap2M: 9285632 kB
DirectMap1G: 9437184 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
+ TIDY_PRINT_DIFF=1 python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
##[group]Building bootstrap
Finished `dev` profile [unoptimized] target(s) in 0.05s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI rustc is not currently built with debug assertions.
---
Diff in /checkout/src/librustdoc/doctest/extracted.rs:5:
use serde::Serialize;
-use super::{BuildDocTestBuilder, ScrapedDocTest};
use super::make::DocTestWrapper;
+use super::{BuildDocTestBuilder, ScrapedDocTest};
use crate::config::Options as RustdocOptions;
use crate::html::markdown;
fmt: checked 6022 files
Build completed unsuccessfully in 0:01:19
local time: Thu May 22 16:02:26 UTC 2025
network time: Thu, 22 May 2025 16:02:26 GMT
Fixed fmt.
Updated.
The job mingw-check-tidy failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
info: removing rustup binaries
info: rustup is uninstalled
##[group]Image checksum input
mingw-check-tidy
# We use the ghcr base image because ghcr doesn't have a rate limit
# and the mingw-check-tidy job doesn't cache docker images in CI.
FROM ghcr.io/rust-lang/ubuntu:22.04
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
g++ \
---
COPY host-x86_64/mingw-check-1/validate-toolstate.sh /scripts/
COPY host-x86_64/mingw-check-1/validate-error-codes.sh /scripts/
# NOTE: intentionally uses python2 for x.py so we can test it still works.
# validate-toolstate only runs in our CI, so it's ok for it to only support python3.
ENV SCRIPT TIDY_PRINT_DIFF=1 npm install eslint@$(head -n 1 /tmp/eslint.version) && \
python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
#
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --allow-unsafe --generate-hashes reuse-requirements.in
---
#15 2.792 Building wheels for collected packages: reuse
#15 2.793 Building wheel for reuse (pyproject.toml): started
#15 3.007 Building wheel for reuse (pyproject.toml): finished with status 'done'
#15 3.007 Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132719 sha256=d2a2565e7037ad3883fb9337653f2e25bbb588534fbef3697286cbc26d1bf634
#15 3.008 Stored in directory: /tmp/pip-ephem-wheel-cache-_jla5sk0/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#15 3.010 Successfully built reuse
#15 3.010 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#15 3.402 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#15 3.403 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#15 3.935 Collecting virtualenv
#15 4.020 Downloading virtualenv-20.31.2-py3-none-any.whl (6.1 MB)
#15 4.171 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.1/6.1 MB 40.8 MB/s eta 0:00:00
#15 4.213 Collecting distlib<1,>=0.3.7
#15 4.233 Downloading distlib-0.3.9-py2.py3-none-any.whl (468 kB)
#15 4.240 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 469.0/469.0 KB 94.2 MB/s eta 0:00:00
#15 4.277 Collecting filelock<4,>=3.12.2
#15 4.296 Downloading filelock-3.18.0-py3-none-any.whl (16 kB)
#15 4.330 Collecting platformdirs<5,>=3.9.1
#15 4.350 Downloading platformdirs-4.3.8-py3-none-any.whl (18 kB)
#15 4.431 Installing collected packages: distlib, platformdirs, filelock, virtualenv
#15 4.623 Successfully installed distlib-0.3.9 filelock-3.18.0 platformdirs-4.3.8 virtualenv-20.31.2
#15 4.624 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#15 DONE 4.7s
#16 [10/11] COPY host-x86_64/mingw-check-1/validate-toolstate.sh /scripts/
#16 DONE 0.0s
---
DirectMap4k: 141248 kB
DirectMap2M: 9295872 kB
DirectMap1G: 9437184 kB
##[endgroup]
Executing TIDY_PRINT_DIFF=1 npm install eslint@$(head -n 1 /tmp/eslint.version) && python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
+ head -n 1 /tmp/eslint.version
+ TIDY_PRINT_DIFF=1 npm install [email protected]
npm WARN deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated @humanwhocodes/[email protected]: Use @eslint/config-array instead
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated @humanwhocodes/[email protected]: Use @eslint/object-schema instead
npm WARN deprecated [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
added 89 packages in 3s
17 packages are looking for funding
run `npm fund` for details
+ python2.7 ../x.py test --stage 0 src/tools/tidy tidyselftest --extra-checks=py,cpp
##[group]Building bootstrap
Finished `dev` profile [unoptimized] target(s) in 0.05s
##[endgroup]
WARN: currently no CI rustc builds have rustc debug assertions enabled. Please either set `rust.debug-assertions` to `false` if you want to use download CI rustc or set `rust.download-rustc` to `false`.
WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI rustc is not currently built with debug assertions.
---
fmt: checked 6036 files
Diff in /checkout/src/librustdoc/doctest/tests.rs:1:
use std::path::PathBuf;
-use super::{BuildDocTestBuilder, GlobalTestOptions, ScrapedDocTest};
+use rustc_span::edition::Edition;
+use rustc_span::{DUMMY_SP, FileName};
+
use super::extracted::ExtractedDocTests;
+use super::{BuildDocTestBuilder, GlobalTestOptions, ScrapedDocTest};
use crate::html::markdown::LangString;
-use rustc_span::{DUMMY_SP, FileName};
-use rustc_span::edition::Edition;
fn make_test(
test_code: &str,
Build completed unsuccessfully in 0:00:49
Applied suggestions!
I fixed the book example.
The Miri subtree was changed
cc @rust-lang/miri
Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter gets adapted for the changes, if necessary.
cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr
Some changes occurred in src/tools/clippy
cc @rust-lang/clippy
cool, this seems really useful!
For now I only know rust-for-linux as potential users, we'll see if more users will appear in the future.
:umbrella: The latest upstream changes (presumably #142181) made this pull request unmergeable. Please resolve the merge conflicts.
Setting @aDotInTheVoid as reviewer since they already reviewed it and it's another JSON output. :)
r? aDotInTheVoid
Requested reviewer is already assigned to this pull request.
Please choose another assignee.
The job aarch64-gnu-llvm-19-2 failed! Check out the build log: (web) (plain)
Click to see the possible cause of the failure (guessed by this bot)
477 | | Vec::new(),
... |
480 | | DUMMY_SP,
481 | | ),
| |_________- argument #7 of type `Vec<std::string::String>` is missing
|
note: associated function defined here
--> src/librustdoc/doctest.rs:845:8
|
845 | fn new(
---
478 - LangString::default(),
479 - code.to_string(),
480 - DUMMY_SP,
481 - ),
474 + ScrapedDocTest::new(FileName::Custom(String::new()), 0, Vec::new(), LangString::default(), code.to_string(), DUMMY_SP, /* Vec<std::string::String> */),
|
For more information about this error, try `rustc --explain E0061`.
[RUSTC-TIMING] rustdoc test:true 11.515
error: could not compile `rustdoc` (lib test) due to 1 previous error
Added explanations in the rustdoc book about the new JSON fields.
Added an inner attribute to better show the difference between doctest_code and code.
It's now ready for review. :)
@bors r+
:pushpin: Commit f1ceb07a7db3f8eb94da1369f1ea20da49213d8e has been approved by aDotInTheVoid
It is now in the queue for this repository.