Skip to content

Regression on doc-tests with statements and a main function #140162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Darksonn opened this issue Apr 22, 2025 · 8 comments · Fixed by #140220
Closed

Regression on doc-tests with statements and a main function #140162

Darksonn opened this issue Apr 22, 2025 · 8 comments · Fixed by #140220
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@Darksonn
Copy link
Contributor

Code

I tried this code:

/// ```
/// # if cfg!(miri) { return; }
/// use playground::my_func;
///
/// fn main() {
///     println!("Hi!");
///     my_func();
/// }
/// ```
pub fn my_func() {
}

On stable, running this doctest succeeds. On beta, it triggers this error:

running 1 test
test src/lib.rs - my_func (line 2) ... FAILED

failures:

---- src/lib.rs - my_func (line 2) stdout ----
error: expected item, found keyword `if`
 --> src/lib.rs:4:1
  |
4 | if cfg!(miri) { return; }
  | ^^ expected item
  |
  = note: for a full list of items that can appear in modules, see <https://doc.rust-lang.org/reference/items.html>

error: aborting due to 1 previous error

Couldn't compile the test.

failures:
    src/lib.rs - my_func (line 2)

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s

Version it worked on

It most recently worked on: Latest stable (i.e. rustc 1.86.0)

Version with regression

rustc --version --verbose:

rustc 1.87.0-beta.5 (386abeb93 2025-04-19)
binary: rustc
commit-hash: 386abeb93ab8e683357f54ffe76ae53861b2d984
commit-date: 2025-04-19
host: x86_64-unknown-linux-gnu
release: 1.87.0-beta.5
LLVM version: 20.1.1

@rustbot modify labels: +regression-from-stable-to-beta -regression-untriaged

@Darksonn Darksonn added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Apr 22, 2025
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-untriaged Untriaged performance or correctness regression. labels Apr 22, 2025
@jieyouxu jieyouxu added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Apr 22, 2025
@apiraino
Copy link
Contributor

apiraino commented Apr 22, 2025

Bisecting by running rustdoc --test src/lib.rs (the file contains the reproducible code):

Regression in rust-lang-ci@cdcf730
#138104

cc @GuillaumeGomez @fmease for authoring #138104

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --without-cargo --preserve --start 2024-02-01 --script test.sh 

@GuillaumeGomez GuillaumeGomez removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 22, 2025
@GuillaumeGomez
Copy link
Member

Gonna try to take a look as soon as possible.

@fmease fmease added the A-doctests Area: Documentation tests, run by rustdoc label Apr 22, 2025
@cyrgani
Copy link
Contributor

cyrgani commented Apr 22, 2025

duplicate of #139651?

@GuillaumeGomez
Copy link
Member

That's an interesting case: your main function is never run. I'm not sure it's the desired output. However, to keep compatibility, this code should be allowed. So instead, I offer to emit a warning in case there is a main function alongside expressions that only belong to a function.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Apr 23, 2025

duplicate of #139651?

Ah yes it is!

@Darksonn
Copy link
Contributor Author

Yes, we probably need to fix these tests in Tokio regardless. The intent is that the main function should run.

@GuillaumeGomez
Copy link
Member

Yep on that we agree. I have a fix ready. Just writing the regression test and then I send it.

@GuillaumeGomez
Copy link
Member

Opened #140220.

@jieyouxu jieyouxu removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 24, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 25, 2025
…ng, r=fmease

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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`
jhpratt added a commit to jhpratt/rust that referenced this issue Apr 26, 2025
…ng, r=fmease

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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``
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 26, 2025
…, r=<try>

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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-gnu-aux
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 26, 2025
…, r=<try>

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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-gnu-aux
tgross35 added a commit to tgross35/rust that referenced this issue Apr 27, 2025
…ng, r=fmease

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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-gnu-aux
tgross35 added a commit to tgross35/rust that referenced this issue Apr 27, 2025
…ng, r=fmease

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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-gnu-aux
tgross35 added a commit to tgross35/rust that referenced this issue Apr 27, 2025
…ng, r=fmease

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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-gnu-aux
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 27, 2025
…, r=<try>

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 28, 2025
…ng, r=fmease

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 28, 2025
Rollup merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrapping, r=fmease

Fix detection of main function if there are expressions around it

Fixes rust-lang#140162.
Fixes rust-lang#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-doctests Area: Documentation tests, run by rustdoc C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
Development

Successfully merging a pull request may close this issue.

7 participants