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
Rollup merge of #141399 - GuillaumeGomez:extracted-doctest, r=aDotInTheVoid
[rustdoc] Give more information into extracted doctest information
Follow-up of #134531.
This update fragment the doctest code into its sub-parts to give more control to the end users on how they want to use it.
The new JSON looks like this:
```json
{
"format_version":2,
"doctests":[
{
"file":"$DIR/extract-doctests-result.rs",
"line":8,
"doctest_attributes":{
"original":"",
"should_panic":false,
"no_run":false,
"ignore":"None",
"rust":true,
"test_harness":false,
"compile_fail":false,
"standalone_crate":false,
"error_codes":[],
"edition":null,
"added_css_classes":[],
"unknown":[]
},
"original_code":"let x = 12;\nOk(())",
"doctest_code":{
"crate_level":"#![allow(unused)]\n",
"code":"let x = 12;\nOk(())",
"wrapper":{
"before":"fn main() { fn _inner() -> core::result::Result<(), impl core::fmt::Debug> {\n",
"after":"\n} _inner().unwrap() }",
"returns_result":true
}
},
"name":"$DIR/extract-doctests-result.rs - (line 8)"
}
]
}
```
for this doctest:
```rust
let x = 12;
Ok(())
```
With this, I think it matches what you need ``@ojeda?`` If so, once merged I'll update the patch I sent to RfL.
r? ``@aDotInTheVoid``
@@ -624,6 +634,10 @@ The generated output (formatted) will look like this:
624
634
*`doctest_attributes` contains computed information about the attributes used on the doctests. For more information about doctest attributes, take a look [here](write-documentation/documentation-tests.html#attributes).
625
635
*`original_code` is the code as written in the source code before rustdoc modifies it.
626
636
*`doctest_code` is the code modified by rustdoc that will be run. If there is a fatal syntax error, this field will not be present.
637
+
*`crate_level` is the crate level code (like attributes or `extern crate`) that will be added at the top-level of the generated doctest.
638
+
*`code` is "naked" doctest without anything from `crate_level` and `wrapper` content.
639
+
*`wrapper` contains extra code that will be added before and after `code`.
640
+
*`returns_result` is a boolean. If `true`, it means that the doctest returns a `Result` type.
627
641
*`name` is the name generated by rustdoc which represents this doctest.
0 commit comments