You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Regression on doc-tests with statements and a main function #140162
/// ```/// # if cfg!(miri) { return; }/// use playground::my_func;////// fn main() {/// println!("Hi!");/// my_func();/// }/// ```pubfnmy_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)
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.
Activity
apiraino commentedon 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:
GuillaumeGomez commentedon Apr 22, 2025
Gonna try to take a look as soon as possible.
cyrgani commentedon Apr 22, 2025
duplicate of #139651?
GuillaumeGomez commentedon Apr 23, 2025
That's an interesting case: your
mainfunction 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 amainfunction alongside expressions that only belong to a function.GuillaumeGomez commentedon Apr 23, 2025
Ah yes it is!
4 remaining items
Rollup merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrappi…
Rollup merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrappi…
Auto merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrapping…
Auto merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrapping…
Rollup merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrappi…
Rollup merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrappi…
Rollup merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrappi…
Auto merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrapping…
Rollup merge of rust-lang#140220 - GuillaumeGomez:doctest-main-wrappi…
Unrolled build for rust-lang#140220
Add regression ui test for rust-lang#140162 and for rust-lang#139651