Skip to content

[rustdoc] Do not consider nested functions as main function even if named main in doctests #132105

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

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

GuillaumeGomez
Copy link
Member

Fixes #131893.

If a nested function is called main, it is not considered as the entry point of the program. Therefore, doctests should not consider such functions as such either.

r? @notriddle

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Oct 24, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@@ -298,12 +303,14 @@ fn parse_source(
match item.kind {
ast::ItemKind::Fn(ref fn_item) if !info.has_main_fn => {
if item.ident.name == sym::main {
info.has_main_fn = true;
info.has_main_fn = is_top_level;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
info.has_main_fn = is_top_level;
info.has_main_fn = info.has_main_fn || is_top_level;

Also, please add this test case

/// ```
/// fn main() {
///     fn main() {}
/// }
/// ```

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oof, good catch!

@notriddle
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Oct 24, 2024

📌 Commit aab2b67 has been approved by notriddle

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 24, 2024
@bors
Copy link
Collaborator

bors commented Oct 25, 2024

⌛ Testing commit aab2b67 with merge 9372bec...

bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 25, 2024
…r=notriddle

[rustdoc] Do not consider nested functions as main function even if named `main` in doctests

Fixes rust-lang#131893.

If a nested function is called `main`, it is not considered as the entry point of the program. Therefore, doctests should not consider such functions as such either.

r? `@notriddle`
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 25, 2024
…r=notriddle

[rustdoc] Do not consider nested functions as main function even if named `main` in doctests

Fixes rust-lang#131893.

If a nested function is called `main`, it is not considered as the entry point of the program. Therefore, doctests should not consider such functions as such either.

r? `@notriddle`
@bors
Copy link
Collaborator

bors commented Oct 25, 2024

⌛ Testing commit aab2b67 with merge 044686e...

@jieyouxu
Copy link
Member

jieyouxu commented Oct 25, 2024

Something about the queue is really messed up, I'll do a resync
EDIT: #t-infra zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/242791-t-infra/topic/bors.20merging.20merged.20PRs
@bors treeclosed=1000

@jieyouxu

This comment was marked as outdated.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2024
@jieyouxu

This comment was marked as outdated.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 25, 2024
@jieyouxu

This comment was marked as outdated.

@bors

This comment was marked as outdated.

@bors

This comment was marked as outdated.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2024
@jieyouxu
Copy link
Member

??? Does editing the treeclosed comment reopen the tree
@bors treeclosed=1000

@jieyouxu
Copy link
Member

It's as if this PR is still being tested, so to be safe:
@bors r- retry

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2024
@jieyouxu
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 25, 2024
@jieyouxu
Copy link
Member

@bors r=@notriddle

@bors
Copy link
Collaborator

bors commented Oct 25, 2024

📌 Commit aab2b67 has been approved by notriddle

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Oct 25, 2024

🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 25, 2024
@jieyouxu
Copy link
Member

Seems to have finished resyncing, so
@bors treeclosed-

@bors
Copy link
Collaborator

bors commented Oct 25, 2024

⌛ Testing commit aab2b67 with merge 017ae1b...

@bors
Copy link
Collaborator

bors commented Oct 25, 2024

☀️ Test successful - checks-actions
Approved by: notriddle
Pushing 017ae1b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 25, 2024
@bors bors merged commit 017ae1b into rust-lang:master Oct 25, 2024
7 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Oct 25, 2024
@GuillaumeGomez GuillaumeGomez deleted the doctest-nested-main branch October 25, 2024 08:08
@GuillaumeGomez
Copy link
Member Author

Should we backport it?

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (017ae1b): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.0% [-1.5%, -0.4%] 2
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary 2.4%, secondary 3.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.4% [2.4%, 2.4%] 1
Regressions ❌
(secondary)
3.8% [3.8%, 3.8%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.4% [2.4%, 2.4%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 783.653s -> 781.857s (-0.23%)
Artifact size: 333.71 MiB -> 333.71 MiB (0.00%)

@notriddle
Copy link
Contributor

Should we backport it?

I wouldn't. There's a very easy workaround, it went a long time without anyone hitting the bug, and it causes a failed compile instead of something worse (like a miscompile or a spurious test pass).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"the main function must be defined at the crate level" for doc test regression 1.81->1.82
7 participants