Skip to content

Commit 319df85

Browse files
authored
Rollup merge of #154048 - GuillaumeGomez:missing_doc_code_examples-improvement, r=lolbinarycat
Don't emit rustdoc `missing_doc_code_examples` lint on impl items @lolbinarycat realized in [this comment](#153964 (comment)) that we weren't testing some cases for the `missing_doc_code_examples` lint. Turns out that it was not handling this case well. =D So in short: `missing_doc_code_examples` lint should not be emitted on impl items and this PR fixes that. r? @lolbinarycat
2 parents 85b8c32 + 6d3b780 commit 319df85

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/librustdoc/passes/check_doc_test_visibility.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -
7979
| clean::ProvidedAssocConstItem(..)
8080
| clean::ImplAssocConstItem(..)
8181
| clean::RequiredAssocTypeItem(..)
82-
// check for trait impl
83-
| clean::ImplItem(box clean::Impl { trait_: Some(_), .. })
82+
| clean::ImplItem(_)
8483
)
8584
{
8685
return false;

tests/rustdoc-ui/lints/lint-missing-doc-code-example.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ impl Clone for Struct {
7878
}
7979
}
8080

81-
81+
impl Struct { // No doc or code example and it's fine!
82+
pub fn bar() {}
83+
//~^ ERROR missing code example in this documentation
84+
//~| ERROR missing documentation for an associated function
85+
}
8286

8387
/// doc
8488
///

tests/rustdoc-ui/lints/lint-missing-doc-code-example.stderr

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
error: missing documentation for an associated function
2+
--> $DIR/lint-missing-doc-code-example.rs:82:5
3+
|
4+
LL | pub fn bar() {}
5+
| ^^^^^^^^^^^^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/lint-missing-doc-code-example.rs:2:9
9+
|
10+
LL | #![deny(missing_docs)]
11+
| ^^^^^^^^^^^^
12+
113
error: missing code example in this documentation
214
--> $DIR/lint-missing-doc-code-example.rs:38:3
315
|
@@ -28,5 +40,11 @@ error: missing code example in this documentation
2840
LL | /// Doc
2941
| ^^^^^^^
3042

31-
error: aborting due to 4 previous errors
43+
error: missing code example in this documentation
44+
--> $DIR/lint-missing-doc-code-example.rs:82:5
45+
|
46+
LL | pub fn bar() {}
47+
| ^^^^^^^^^^^^^^^
48+
49+
error: aborting due to 6 previous errors
3250

0 commit comments

Comments
 (0)