Skip to content

Commit f1ceb07

Browse files
Update extracted-doctest feature documentation
1 parent 89e3510 commit f1ceb07

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/doc/rustdoc/src/unstable-features.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,9 @@ For this rust code:
581581

582582
```rust
583583
/// ```
584+
/// #![allow(dead_code)]
584585
/// let x = 12;
586+
/// Ok(())
585587
/// ```
586588
pub trait Trait {}
587589
```
@@ -590,10 +592,10 @@ The generated output (formatted) will look like this:
590592

591593
```json
592594
{
593-
"format_version": 1,
595+
"format_version": 2,
594596
"doctests": [
595597
{
596-
"file": "foo.rs",
598+
"file": "src/lib.rs",
597599
"line": 1,
598600
"doctest_attributes": {
599601
"original": "",
@@ -609,9 +611,17 @@ The generated output (formatted) will look like this:
609611
"added_css_classes": [],
610612
"unknown": []
611613
},
612-
"original_code": "let x = 12;",
613-
"doctest_code": "#![allow(unused)]\nfn main() {\nlet x = 12;\n}",
614-
"name": "foo.rs - Trait (line 1)"
614+
"original_code": "#![allow(dead_code)]\nlet x = 12;\nOk(())",
615+
"doctest_code": {
616+
"crate_level": "#![allow(unused)]\n#![allow(dead_code)]\n\n",
617+
"code": "let x = 12;\nOk(())",
618+
"wrapper": {
619+
"before": "fn main() { fn _inner() -> core::result::Result<(), impl core::fmt::Debug> {\n",
620+
"after": "\n} _inner().unwrap() }",
621+
"returns_result": true
622+
}
623+
},
624+
"name": "src/lib.rs - (line 1)"
615625
}
616626
]
617627
}
@@ -624,6 +634,10 @@ The generated output (formatted) will look like this:
624634
* `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).
625635
* `original_code` is the code as written in the source code before rustdoc modifies it.
626636
* `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.
627641
* `name` is the name generated by rustdoc which represents this doctest.
628642

629643
### html

src/librustdoc/doctest/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ fn get_extracted_doctests(code: &str) -> ExtractedDocTests {
478478
LangString::default(),
479479
code.to_string(),
480480
DUMMY_SP,
481+
Vec::new(),
481482
),
482483
&opts,
483484
Edition::Edition2018,

0 commit comments

Comments
 (0)