-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix detection of main function if there are expressions around it #140220
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3536324
Fix detection of `main` function if there are expressions around it
GuillaumeGomez 81438c0
Add regression ui test for #140162 and for #139651
GuillaumeGomez 3ededc1
Improve code
GuillaumeGomez 3ef98a5
If there is a `;` alone, we consider that the doctest needs to be put…
GuillaumeGomez aa69e3a
Fix bad handling of macros if there is already a `main` function
GuillaumeGomez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
use std::string::String; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 2 additions & 25 deletions
27
tests/rustdoc-ui/doctest/failed-doctest-extra-semicolon-on-item.stdout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,6 @@ | ||
|
||
running 1 test | ||
test $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) ... FAILED | ||
test $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) ... ok | ||
|
||
failures: | ||
|
||
---- $DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) stdout ---- | ||
error: expected item, found `;` | ||
--> $DIR/failed-doctest-extra-semicolon-on-item.rs:12:12 | ||
| | ||
LL | struct S {}; // unexpected semicolon after struct def | ||
| ^ | ||
| | ||
= help: braced struct declarations are not followed by a semicolon | ||
help: remove this semicolon | ||
| | ||
LL - struct S {}; // unexpected semicolon after struct def | ||
LL + struct S {} // unexpected semicolon after struct def | ||
| | ||
|
||
error: aborting due to 1 previous error | ||
|
||
Couldn't compile the test. | ||
|
||
failures: | ||
$DIR/failed-doctest-extra-semicolon-on-item.rs - m (line 11) | ||
|
||
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// This test checks a corner case where the macro calls used to be skipped, | ||
// making them considered as statement, and therefore some cases where | ||
// `include!` macro was then put into a function body, making the doctest | ||
// compilation fail. | ||
|
||
//@ compile-flags:--test | ||
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR" | ||
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" | ||
//@ check-pass | ||
|
||
//! ``` | ||
//! include!("./auxiliary/macro-after-main.rs"); | ||
//! | ||
//! fn main() {} | ||
//! eprintln!(); | ||
//! ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
running 1 test | ||
test $DIR/macro-after-main.rs - (line 11) ... ok | ||
|
||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// This test ensures that if there is an expression alongside a `main` | ||
// function, it will not consider the entire code to be part of the `main` | ||
// function and will generate its own function to wrap everything. | ||
// | ||
// This is a regression test for: | ||
// * <https://github.com/rust-lang/rust/issues/140162> | ||
// * <https://github.com/rust-lang/rust/issues/139651> | ||
//@ compile-flags:--test | ||
//@ normalize-stdout: "tests/rustdoc-ui/doctest" -> "$$DIR" | ||
//@ normalize-stdout: "finished in \d+\.\d+s" -> "finished in $$TIME" | ||
//@ check-pass | ||
|
||
#![crate_name = "foo"] | ||
|
||
//! ``` | ||
//! # if cfg!(miri) { return; } | ||
//! use std::ops::Deref; | ||
//! | ||
//! fn main() { | ||
//! println!("Hi!"); | ||
//! } | ||
//! ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
running 1 test | ||
test $DIR/test-main-alongside-exprs.rs - (line 15) ... ok | ||
|
||
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍 Could you open an issue for that unless we already have one for that?
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.
Here it is: #140310