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
This doc test code compiles fine even though the code would not be accepted normally. Notice the semicolon in struct Example{}; this semicolon is not allowed in the actual code but is accepted in the doc example.
Sorry if this is a potential duplicate or if this is expected behavior.
I found issue #91398 which indicates that rust doc did indeed handle this as I would expect at some point earlier.
I think this is expected behavior. Because the doctest contains no main function, it gets wrapped in an implicit main function and this is perfectly valid rust code:
fnmain(){structExample{};}
It's an item statement, followed by an empty statement.
The issue you linked fails to compile, because its doctest does contain a main function and is therefore not wrapped in another main function.
I see now. Thanks.
I was expecting to be able to rely on the doc test code always compiling if copy pasted and compiled as a standalone program.
I can see how I cannot always rely on this and how it is not something that can(or maybe even should) be fixed easily.
This doc test code compiles fine even though the code would not be accepted normally. Notice the semicolon in
struct Example{};
this semicolon is not allowed in the actual code but is accepted in the doc example.I would have expected a compile error when running the
cargo test
command.Instead it compiles and runs the doc example without problems.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: