Skip to content

Module doc examples #76671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustdoc/passes/doc_test_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub fn should_have_doc_example(item_kind: &clean::ItemEnum) -> bool {
| clean::ImportItem(_)
| clean::PrimitiveItem(_)
| clean::KeywordItem(_)
| clean::ModuleItem(_)
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/coverage/doc-examples-json.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":2,"with_examples":1}}
{"$DIR/doc-examples-json.rs":{"total":3,"with_docs":2,"total_examples":1,"with_examples":1}}
4 changes: 2 additions & 2 deletions src/test/rustdoc-ui/coverage/doc-examples.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
+-------------------------------------+------------+------------+------------+------------+
| File | Documented | Percentage | Examples | Percentage |
+-------------------------------------+------------+------------+------------+------------+
| ...tdoc-ui/coverage/doc-examples.rs | 4 | 100.0% | 2 | 50.0% |
| ...tdoc-ui/coverage/doc-examples.rs | 4 | 100.0% | 2 | 66.7% |
+-------------------------------------+------------+------------+------------+------------+
| Total | 4 | 100.0% | 2 | 50.0% |
| Total | 4 | 100.0% | 2 | 66.7% |
+-------------------------------------+------------+------------+------------+------------+
2 changes: 1 addition & 1 deletion src/test/rustdoc-ui/coverage/json.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":15,"with_examples":6}}
{"$DIR/json.rs":{"total":17,"with_docs":12,"total_examples":13,"with_examples":6}}
3 changes: 1 addition & 2 deletions src/test/rustdoc-ui/doc-without-codeblock.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#![deny(missing_doc_code_examples)] //~ ERROR missing code example in this documentation
#![deny(missing_doc_code_examples)]

/// Some docs.
//~^ ERROR missing code example in this documentation
pub struct Foo;

/// And then, the princess died.
//~^ ERROR missing code example in this documentation
pub mod foo {
/// Or maybe not because she saved herself!
//~^ ERROR missing code example in this documentation
Expand Down
28 changes: 5 additions & 23 deletions src/test/rustdoc-ui/doc-without-codeblock.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:1:1
--> $DIR/doc-without-codeblock.rs:3:1
|
LL | / #![deny(missing_doc_code_examples)]
LL | |
LL | | /// Some docs.
LL | |
... |
LL | | pub fn bar() {}
LL | | }
| |_^
LL | /// Some docs.
| ^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/doc-without-codeblock.rs:1:9
Expand All @@ -17,22 +11,10 @@ LL | #![deny(missing_doc_code_examples)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:3:1
|
LL | /// Some docs.
| ^^^^^^^^^^^^^^

error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:7:1
|
LL | /// And then, the princess died.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: missing code example in this documentation
--> $DIR/doc-without-codeblock.rs:10:5
--> $DIR/doc-without-codeblock.rs:9:5
|
LL | /// Or maybe not because she saved herself!
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors
error: aborting due to 2 previous errors

6 changes: 3 additions & 3 deletions src/test/rustdoc-ui/lint-missing-doc-code-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ fn test() {
}

#[allow(missing_docs)]
mod module1 { //~ ERROR
mod module1 {
}

#[allow(missing_doc_code_examples)]
/// doc
/// doc (no code example and it's fine!)
mod module2 {

#[allow(missing_doc_code_examples)]
/// doc
pub fn test() {}
}
Expand Down
9 changes: 1 addition & 8 deletions src/test/rustdoc-ui/lint-missing-doc-code-example.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,11 @@ error: missing code example in this documentation
LL | /// Doc
| ^^^^^^^

error: missing code example in this documentation
--> $DIR/lint-missing-doc-code-example.rs:19:1
|
LL | / mod module1 {
LL | | }
| |_^

error: missing code example in this documentation
--> $DIR/lint-missing-doc-code-example.rs:37:3
|
LL | /// doc
| ^^^^^^^

error: aborting due to 5 previous errors
error: aborting due to 4 previous errors