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
I probably am just using doc-tests wrongly, but I have come across a "type not found" problem using modules in doc-tests that seems rather odd to me, because it compiles in normal code without complaining:
typeMyType = u8;// Without extra module.fnmy_func(_:MyType){}fnmain(){my_func(0);}
typeMyType = u8;// With extra module.mod my_mod {pub(super)fnmy_func(_:super::MyType){}}fnmain(){
my_mod::my_func(0);}
When using the same code (without main) in doc-tests with cargo test, only the first snippet passes the test:
//! ```rust//! type MyType = u8;//!//! mod my_mod { pub(super) fn my_func(_: super::MyType) {} }//!//! my_mod::my_func(0);//! ```
The second snippet fails with the following message:
error[E0412]: cannot find type `MyType` in module `super`
--> src\lib.rs:4:46
|
5 | mod my_mod { pub(super)fnmy_func(_:super::MyType){}}
| ^^^^^^ not found in `super`
I also tried to use crate::MyType instead of super::MyType but that did not work either.
It doesn't work because doctests wrap the entire example in fn main() { ... }. Functions themselves don't introduce a new namespace in the module hierarchy, so the super is referring to the module scope outside of the main function. #79260 is a similar issue.
I probably am just using doc-tests wrongly, but I have come across a "type not found" problem using modules in doc-tests that seems rather odd to me, because it compiles in normal code without complaining:
When using the same code (without
main
) in doc-tests withcargo test
, only the first snippet passes the test:The second snippet fails with the following message:
I also tried to use
crate::MyType
instead ofsuper::MyType
but that did not work either.Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: