diff options
| author | León Orell Valerian Liehr <me@fmease.dev> | 2025-04-29 02:11:41 +0200 |
|---|---|---|
| committer | León Orell Valerian Liehr <me@fmease.dev> | 2025-05-01 11:56:11 +0200 |
| commit | 714ea10ea41e97310a1b3d90fed4cfb3e2dd6b73 (patch) | |
| tree | 16c13a8387fb1200ad6fc286aa3c9338747f9eb4 /tests/rustdoc-ui/doctest/main-alongside-macro-calls.rs | |
| parent | 25cdf1f67463c9365d8d83778c933ec7480e940b (diff) | |
| download | rust-714ea10ea41e97310a1b3d90fed4cfb3e2dd6b73.tar.gz rust-714ea10ea41e97310a1b3d90fed4cfb3e2dd6b73.zip | |
rustdoc: Fix doctest heuristic for main fn wrapping
Diffstat (limited to 'tests/rustdoc-ui/doctest/main-alongside-macro-calls.rs')
| -rw-r--r-- | tests/rustdoc-ui/doctest/main-alongside-macro-calls.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/rustdoc-ui/doctest/main-alongside-macro-calls.rs b/tests/rustdoc-ui/doctest/main-alongside-macro-calls.rs new file mode 100644 index 00000000000..b455d8b0cc3 --- /dev/null +++ b/tests/rustdoc-ui/doctest/main-alongside-macro-calls.rs @@ -0,0 +1,44 @@ +// This test ensures that if there is are any macro calls alongside a `main` function, +// it will indeed consider the `main` function as the program entry point and *won't* +// generate its own `main` function to wrap everything even though macro calls are +// valid in statement contexts, too, and could just as well expand to statements or +// expressions (we don't perform any macro expansion to find `main`, see also +// <https://github.com/rust-lang/rust/issues/57415>). +// +// See <./main-alongside-stmts.rs> for comparison. +// +//@ compile-flags:--test --test-args --test-threads=1 +//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR" +//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" +//@ revisions: pass fail +//@[pass] check-pass +//@[fail] failure-status: 101 + +// Regression test for <https://github.com/rust-lang/rust/pull/140220#issuecomment-2831872920>: + +//! ``` +//! fn main() {} +//! include!("./auxiliary/items.rs"); +//! ``` +//! +//! ``` +//! include!("./auxiliary/items.rs"); +//! fn main() {} +//! ``` + +// Regression test for <https://github.com/rust-lang/rust/issues/140412>: +// We test the "same" thing twice: Once via `compile_fail` to more closely mirror the reported +// regression and once without it to make sure that it leads to the expected rustc errors, +// namely `println!(…)` not being valid in item contexts. + +#![cfg_attr(pass, doc = " ```compile_fail")] +#![cfg_attr(fail, doc = " ```")] +//! fn main() {} +//! println!(); +//! ``` +//! +#![cfg_attr(pass, doc = " ```compile_fail")] +#![cfg_attr(fail, doc = " ```")] +//! println!(); +//! fn main() {} +//! ``` |
