Skip to content

Commit c681e47

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

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ For this rust code:
582582
```rust
583583
/// ```
584584
/// let x = 12;
585+
/// Ok(())
585586
/// ```
586587
pub trait Trait {}
587588
```
@@ -590,10 +591,10 @@ The generated output (formatted) will look like this:
590591

591592
```json
592593
{
593-
"format_version": 1,
594+
"format_version": 2,
594595
"doctests": [
595596
{
596-
"file": "foo.rs",
597+
"file": "src/lib.rs",
597598
"line": 1,
598599
"doctest_attributes": {
599600
"original": "",
@@ -609,9 +610,17 @@ The generated output (formatted) will look like this:
609610
"added_css_classes": [],
610611
"unknown": []
611612
},
612-
"original_code": "let x = 12;",
613-
"doctest_code": "#![allow(unused)]\nfn main() {\nlet x = 12;\n}",
614-
"name": "foo.rs - Trait (line 1)"
613+
"original_code": "#![allow(dead_code)]\nlet x = 12;\nOk(())",
614+
"doctest_code": {
615+
"crate_level": "#![allow(unused)]\n#![allow(dead_code)]\n\n",
616+
"code": "let x = 12;\nOk(())",
617+
"wrapper": {
618+
"before": "fn main() { fn _inner() -> core::result::Result<(), impl core::fmt::Debug> {\n",
619+
"after": "\n} _inner().unwrap() }",
620+
"returns_result": true
621+
}
622+
},
623+
"name": "src/lib.rs - (line 1)"
615624
}
616625
]
617626
}
@@ -624,6 +633,10 @@ The generated output (formatted) will look like this:
624633
* `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).
625634
* `original_code` is the code as written in the source code before rustdoc modifies it.
626635
* `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.
636+
* `crate_level` is the crate level code (like attributes or `extern crate`) that will be added at the top-level of the generated doctest.
637+
* `code` is "naked" doctest without anything from `crate_level` and `wrapper` content.
638+
* `wrapper` contains extra code that will be added before and after `code`.
639+
* `returns_result` is a boolean. If `true`, it means that the doctest returns a `Result` type.
627640
* `name` is the name generated by rustdoc which represents this doctest.
628641

629642
### 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)