Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
870f848
Add support for trait associated items
GuillaumeGomez Jan 20, 2025
ef39e42
Better handling of paths in link to def feature
GuillaumeGomez Jan 26, 2025
9457a32
Update to last rustc_hir Visitor changes
GuillaumeGomez Jan 26, 2025
687ac3f
Fix panic if an item does not have a body
GuillaumeGomez May 4, 2025
5b2c61e
Document guarantees of poisoning
purplesyringa Jul 19, 2025
45231fa
[rustdoc] Display unsafe attrs with edition 2024 `unsafe()` wrappers.
obi1kenobi Jul 23, 2025
5ae2d42
get rid of some false negatives in rustdoc::broken_intra_doc_links
lolbinarycat Nov 7, 2024
87d7d80
adjust more unit tests to reflect more aggressive intra-doc linting
lolbinarycat Nov 8, 2024
a7da4b8
rustdoc::broken_intra_doc_links: no backticks = use old behavior
lolbinarycat Apr 18, 2025
0413481
rustdoc: update tests to match new lint behavior
lolbinarycat Apr 18, 2025
6a7d488
rustdoc::broken_intra_doc_links: only be lenient with shortcut links
lolbinarycat Apr 19, 2025
bd85df1
move bad-intra-doc test into intra-doc dir
lolbinarycat Apr 19, 2025
a73d7e3
fix up issues with internal compiler docs revealed by stricter lint
lolbinarycat Jul 24, 2025
da4687b
Link to Mutex poisoning docs from RwLock docs
purplesyringa Jul 25, 2025
5b8c614
Add a list of failure conditions for poisoning
purplesyringa Jul 25, 2025
c1d06cc
Add a note on foreign exceptions
purplesyringa Jul 25, 2025
3352dfc
Skip formatting for some compiler documentation code
joshtriplett Jul 26, 2025
7150880
Improve and regularize comment placement in doc code
joshtriplett Jul 26, 2025
b6c54a9
Avoid placing `// FIXME` comments inside doc code blocks
joshtriplett Jul 26, 2025
56c5b1d
Add parentheses around expression arguments to `..`
joshtriplett Jul 26, 2025
1e2d587
Avoid making the start of a doc code block conditional
joshtriplett Jul 26, 2025
91bccd6
use `minicore` for fortanix assembly tests
folkertdev Jul 24, 2025
8b90847
update fortanix run-make test
folkertdev Jul 24, 2025
0e53d85
Fortify RemoveUnneededDrops test.
cjgillot Jun 16, 2025
ee0118f
[test][AIX] ignore extern_weak linkage test
daltenty Jul 30, 2025
5aec437
detect infinite recursion with tail calls in ctfe
WaffleLapkin Jul 31, 2025
040f71e
loop match: error on `#[const_continue]` outside `#[loop_match]`
folkertdev Jul 25, 2025
f909918
Add human readable name "Cygwin"
Berrysoft Aug 1, 2025
9377e0a
Constify additional Result functions
Randl Aug 1, 2025
bd7b8b3
Properly pass path to staged `rustc` to `compiletest` self-tests
jieyouxu Aug 1, 2025
d5ffb06
compiletest: Improve diagnostics for line annotation mismatches 2
petrochenkov Jul 31, 2025
32cf3d4
Cleanup the definition of `group_type`
JonathanBrouwer Aug 1, 2025
21ab47e
Add my previous commit name to .mailmap
scrabsha Aug 1, 2025
4c7c9de
Fix safety comment for new_unchecked in niche_types
nilehmann Aug 1, 2025
f618a05
Correctly handle `--no-run` rustdoc test option
GuillaumeGomez Jul 13, 2025
202a05b
Correctly handle `should_panic` doctest attribute
GuillaumeGomez Jul 7, 2025
cc60a24
Add regression test for #143009
GuillaumeGomez Jul 4, 2025
d67a4a5
Update std doctests
GuillaumeGomez Jul 7, 2025
0a01e8e
Add regression test for #143858
GuillaumeGomez Jul 13, 2025
7b8015c
Add FIXME comments to use `test::ERROR_EXIT_CODE` once public and fix…
GuillaumeGomez Aug 1, 2025
e6256b7
Rollup merge of #132748 - lolbinarycat:rustdoc-intra-doc-link-warn-mo…
samueltardieu Aug 2, 2025
b6e103f
Rollup merge of #135771 - GuillaumeGomez:jump-to-def-perf, r=fmease
samueltardieu Aug 2, 2025
d5942fa
Rollup merge of #143360 - folkertdev:const-continue-outside-loop-matc…
samueltardieu Aug 2, 2025
7ce24fd
Rollup merge of #143662 - obi1kenobi:pg/unsafe-attribute-wrappers, r=…
samueltardieu Aug 2, 2025
9d089e3
Rollup merge of #143771 - Randl:const-result, r=tgross35
samueltardieu Aug 2, 2025
4ceba56
Rollup merge of #143900 - GuillaumeGomez:fix-no-run, r=lolbinarycat,f…
samueltardieu Aug 2, 2025
6673017
Rollup merge of #144185 - purplesyringa:poisoning-wording, r=Amanieu
samueltardieu Aug 2, 2025
5db12cd
Rollup merge of #144395 - folkertdev:fortanix-run-make-test, r=jieyouxu
samueltardieu Aug 2, 2025
52407c7
Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=Am…
samueltardieu Aug 2, 2025
3af4da8
Rollup merge of #144614 - cjgillot:fortify-unneeded, r=scottmcm
samueltardieu Aug 2, 2025
28315df
Rollup merge of #144703 - daltenty:daltenty/extern-weak, r=Noratrieb
samueltardieu Aug 2, 2025
b639abf
Rollup merge of #144747 - petrochenkov:annusexp2, r=RalfJung
samueltardieu Aug 2, 2025
272d7fb
Rollup merge of #144756 - WaffleLapkin:inf-rec-etc-ctfe, r=lqd
samueltardieu Aug 2, 2025
aa62f13
Rollup merge of #144766 - Berrysoft:patch-1, r=GuillaumeGomez
samueltardieu Aug 2, 2025
06a7a89
Rollup merge of #144782 - jieyouxu:compiletest-selftests, r=Kobzol
samueltardieu Aug 2, 2025
d2f7196
Rollup merge of #144786 - JonathanBrouwer:cleanup-group-type, r=jdons…
samueltardieu Aug 2, 2025
78e1e21
Rollup merge of #144796 - scrabsha:push-lsnwwpwpnpxr, r=jdonszelmann
samueltardieu Aug 2, 2025
90a04e2
Rollup merge of #144797 - nilehmann:safety-comment-niche, r=Noratrieb
samueltardieu Aug 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions library/std/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ use crate::fmt::{self, Write};
/// the `Debug` output means `Report` is an ideal starting place for formatting errors returned
/// from `main`.
///
/// ```should_panic
/// ```
/// #![feature(error_reporter)]
/// use std::error::Report;
/// # use std::error::Error;
Expand Down Expand Up @@ -154,10 +154,14 @@ use crate::fmt::{self, Write};
/// # Err(SuperError { source: SuperErrorSideKick })
/// # }
///
/// fn main() -> Result<(), Report<SuperError>> {
/// fn run() -> Result<(), Report<SuperError>> {
/// get_super_error()?;
/// Ok(())
/// }
///
/// fn main() {
/// assert!(run().is_err());
/// }
/// ```
///
/// This example produces the following output:
Expand All @@ -170,7 +174,7 @@ use crate::fmt::{self, Write};
/// output format. If you want to make sure your `Report`s are pretty printed and include backtrace
/// you will need to manually convert and enable those flags.
///
/// ```should_panic
/// ```
/// #![feature(error_reporter)]
/// use std::error::Report;
/// # use std::error::Error;
Expand Down Expand Up @@ -201,12 +205,16 @@ use crate::fmt::{self, Write};
/// # Err(SuperError { source: SuperErrorSideKick })
/// # }
///
/// fn main() -> Result<(), Report<SuperError>> {
/// fn run() -> Result<(), Report<SuperError>> {
/// get_super_error()
/// .map_err(Report::from)
/// .map_err(|r| r.pretty(true).show_backtrace(true))?;
/// Ok(())
/// }
///
/// fn main() {
/// assert!(run().is_err());
/// }
/// ```
///
/// This example produces the following output:
Expand Down
7 changes: 4 additions & 3 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub(crate) fn run_tests(
);

for (doctest, scraped_test) in &doctests {
tests_runner.add_test(doctest, scraped_test, &target_str);
tests_runner.add_test(doctest, scraped_test, &target_str, rustdoc_options);
}
let (duration, ret) = tests_runner.run_merged_tests(
rustdoc_test_options,
Expand Down Expand Up @@ -828,7 +828,8 @@ fn run_test(
match result {
Err(e) => return (duration, Err(TestFailure::ExecutionError(e))),
Ok(out) => {
if langstr.should_panic && out.status.success() {
// FIXME: use test::ERROR_EXIT_CODE once public
if langstr.should_panic && out.status.code() != Some(101) {
return (duration, Err(TestFailure::UnexpectedRunPass));
} else if !langstr.should_panic && !out.status.success() {
return (duration, Err(TestFailure::ExecutionFailure(out)));
Expand Down Expand Up @@ -1138,7 +1139,7 @@ fn doctest_run_fn(
eprint!("Test compiled successfully, but it's marked `compile_fail`.");
}
TestFailure::UnexpectedRunPass => {
eprint!("Test executable succeeded, but it's marked `should_panic`.");
eprint!("Test didn't panic, but it's marked `should_panic`.");
}
TestFailure::MissingErrorCodes(codes) => {
eprint!("Some expected error codes were not found: {codes:?}");
Expand Down
25 changes: 18 additions & 7 deletions src/librustdoc/doctest/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ impl DocTestRunner {
doctest: &DocTestBuilder,
scraped_test: &ScrapedDocTest,
target_str: &str,
opts: &RustdocOptions,
) {
let ignore = match scraped_test.langstr.ignore {
Ignore::All => true,
Expand All @@ -62,6 +63,7 @@ impl DocTestRunner {
self.nb_tests,
&mut self.output,
&mut self.output_merged_tests,
opts,
),
));
self.supports_color &= doctest.supports_color;
Expand Down Expand Up @@ -134,13 +136,21 @@ mod __doctest_mod {{
}}

#[allow(unused)]
pub fn doctest_runner(bin: &std::path::Path, test_nb: usize) -> ExitCode {{
pub fn doctest_runner(bin: &std::path::Path, test_nb: usize, should_panic: bool) -> ExitCode {{
let out = std::process::Command::new(bin)
.env(self::RUN_OPTION, test_nb.to_string())
.args(std::env::args().skip(1).collect::<Vec<_>>())
.output()
.expect(\"failed to run command\");
if !out.status.success() {{
if should_panic {{
// FIXME: use test::ERROR_EXIT_CODE once public
if out.status.code() != Some(101) {{
eprintln!(\"Test didn't panic, but it's marked `should_panic`.\");
ExitCode::FAILURE
}} else {{
ExitCode::SUCCESS
}}
}} else if !out.status.success() {{
if let Some(code) = out.status.code() {{
eprintln!(\"Test executable failed (exit status: {{code}}).\");
}} else {{
Expand Down Expand Up @@ -223,6 +233,7 @@ fn generate_mergeable_doctest(
id: usize,
output: &mut String,
output_merged_tests: &mut String,
opts: &RustdocOptions,
) -> String {
let test_id = format!("__doctest_{id}");

Expand Down Expand Up @@ -256,22 +267,21 @@ fn main() {returns_result} {{
)
.unwrap();
}
let not_running = ignore || scraped_test.langstr.no_run;
let not_running = ignore || scraped_test.no_run(opts);
writeln!(
output_merged_tests,
"
mod {test_id} {{
pub const TEST: test::TestDescAndFn = test::TestDescAndFn::new_doctest(
{test_name:?}, {ignore}, {file:?}, {line}, {no_run}, {should_panic},
{test_name:?}, {ignore}, {file:?}, {line}, {no_run}, false,
test::StaticTestFn(
|| {{{runner}}},
));
}}",
test_name = scraped_test.name,
file = scraped_test.path(),
line = scraped_test.line,
no_run = scraped_test.langstr.no_run,
should_panic = !scraped_test.langstr.no_run && scraped_test.langstr.should_panic,
no_run = scraped_test.no_run(opts),
// Setting `no_run` to `true` in `TestDesc` still makes the test run, so we simply
// don't give it the function to run.
runner = if not_running {
Expand All @@ -280,11 +290,12 @@ test::StaticTestFn(
format!(
"
if let Some(bin_path) = crate::__doctest_mod::doctest_path() {{
test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}))
test::assert_test_result(crate::__doctest_mod::doctest_runner(bin_path, {id}, {should_panic}))
}} else {{
test::assert_test_result(doctest_bundle::{test_id}::__main_fn())
}}
",
should_panic = scraped_test.langstr.should_panic,
)
},
)
Expand Down
36 changes: 36 additions & 0 deletions tests/run-make/rustdoc-should-panic/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Ensure that `should_panic` doctests only succeed if the test actually panicked.
// Regression test for <https://github.com/rust-lang/rust/issues/143009>.

//@ needs-target-std

use run_make_support::rustdoc;

fn check_output(output: String, edition: &str) {
let should_contain = &[
"test test.rs - bad_exit_code (line 1) ... FAILED",
"test test.rs - did_not_panic (line 6) ... FAILED",
"test test.rs - did_panic (line 11) ... ok",
"---- test.rs - bad_exit_code (line 1) stdout ----
Test executable failed (exit status: 1).",
"---- test.rs - did_not_panic (line 6) stdout ----
Test didn't panic, but it's marked `should_panic`.",
"test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out;",
];
for text in should_contain {
assert!(
output.contains(text),
"output (edition: {edition}) doesn't contain {:?}\nfull output: {output}",
text
);
}
}

fn main() {
check_output(rustdoc().input("test.rs").arg("--test").run_fail().stdout_utf8(), "2015");

// Same check with the merged doctest feature (enabled with the 2024 edition).
check_output(
rustdoc().input("test.rs").arg("--test").edition("2024").run_fail().stdout_utf8(),
"2024",
);
}
14 changes: 14 additions & 0 deletions tests/run-make/rustdoc-should-panic/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/// ```
/// std::process::exit(1);
/// ```
fn bad_exit_code() {}

/// ```should_panic
/// std::process::exit(1);
/// ```
fn did_not_panic() {}

/// ```should_panic
/// panic!("yeay");
/// ```
fn did_panic() {}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test $DIR/failed-doctest-should-panic-2021.rs - Foo (line 10) ... FAILED
failures:

---- $DIR/failed-doctest-should-panic-2021.rs - Foo (line 10) stdout ----
Test executable succeeded, but it's marked `should_panic`.
Test didn't panic, but it's marked `should_panic`.

failures:
$DIR/failed-doctest-should-panic-2021.rs - Foo (line 10)
Expand Down
5 changes: 3 additions & 2 deletions tests/rustdoc-ui/doctest/failed-doctest-should-panic.stdout
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@

running 1 test
test $DIR/failed-doctest-should-panic.rs - Foo (line 12) - should panic ... FAILED
test $DIR/failed-doctest-should-panic.rs - Foo (line 12) ... FAILED

failures:

---- $DIR/failed-doctest-should-panic.rs - Foo (line 12) stdout ----
note: test did not panic as expected at $DIR/failed-doctest-should-panic.rs:12:0
Test didn't panic, but it's marked `should_panic`.


failures:
$DIR/failed-doctest-should-panic.rs - Foo (line 12)
Expand Down
12 changes: 12 additions & 0 deletions tests/rustdoc-ui/doctest/no-run.edition2021.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

running 7 tests
test $DIR/no-run.rs - f (line 14) - compile ... ok
test $DIR/no-run.rs - f (line 17) - compile ... ok
test $DIR/no-run.rs - f (line 20) ... ignored
test $DIR/no-run.rs - f (line 23) - compile ... ok
test $DIR/no-run.rs - f (line 29) - compile fail ... ok
test $DIR/no-run.rs - f (line 34) - compile ... ok
test $DIR/no-run.rs - f (line 38) - compile ... ok

test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME

18 changes: 18 additions & 0 deletions tests/rustdoc-ui/doctest/no-run.edition2024.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

running 5 tests
test $DIR/no-run.rs - f (line 14) - compile ... ok
test $DIR/no-run.rs - f (line 17) - compile ... ok
test $DIR/no-run.rs - f (line 23) - compile ... ok
test $DIR/no-run.rs - f (line 34) - compile ... ok
test $DIR/no-run.rs - f (line 38) - compile ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME


running 2 tests
test $DIR/no-run.rs - f (line 20) ... ignored
test $DIR/no-run.rs - f (line 29) - compile fail ... ok

test result: ok. 1 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME

all doctests ran in $TIME; merged doctests compilation took $TIME
44 changes: 44 additions & 0 deletions tests/rustdoc-ui/doctest/no-run.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// This test ensures that the `--no-run` flag works the same between normal and merged doctests.
// Regression test for <https://github.com/rust-lang/rust/issues/143858>.

//@ check-pass
//@ revisions: edition2021 edition2024
//@ [edition2021]edition:2021
//@ [edition2024]edition:2024
//@ compile-flags:-Z unstable-options --test --no-run --test-args=--test-threads=1
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME"
//@ normalize-stdout: "ran in \d+\.\d+s" -> "ran in $$TIME"
//@ normalize-stdout: "compilation took \d+\.\d+s" -> "compilation took $$TIME"

/// ```
/// let a = true;
/// ```
/// ```should_panic
/// panic!()
/// ```
/// ```ignore (incomplete-code)
/// fn foo() {
/// ```
/// ```no_run
/// loop {
/// println!("Hello, world");
/// }
/// ```
/// fails to compile
/// ```compile_fail
/// let x = 5;
/// x += 2; // shouldn't compile!
/// ```
/// Ok the test does not run
/// ```
/// panic!()
/// ```
/// Ok the test does not run
/// ```should_panic
/// loop {
/// println!("Hello, world");
/// panic!()
/// }
/// ```
pub fn f() {}
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/doctest/wrong-ast-2024.stdout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

running 1 test
test $DIR/wrong-ast-2024.rs - three (line 20) - should panic ... ok
test $DIR/wrong-ast-2024.rs - three (line 20) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

Expand Down