-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[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
Conversation
This comment has been minimized.
This comment has been minimized.
006d5d1
to
d51fe6e
Compare
This comment has been minimized.
This comment has been minimized.
b559eba
to
942b449
Compare
src/librustdoc/doctest/make.rs
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() {}
/// }
/// ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, good catch!
942b449
to
aab2b67
Compare
@bors r+ |
…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`
…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`
Something about the queue is really messed up, I'll do a resync |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
??? Does editing the treeclosed comment reopen the tree |
It's as if this PR is still being tested, so to be safe: |
@bors r- |
🌲 The tree is currently closed for pull requests below priority 1000. This pull request will be tested once the tree is reopened. |
Seems to have finished resyncing, so |
☀️ Test successful - checks-actions |
Should we backport it? |
Finished benchmarking commit (017ae1b): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis 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.
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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 783.653s -> 781.857s (-0.23%) |
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). |
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