Skip to content

Commit 54606f5

Browse files
committed
Merge and extend tests for missing_docs_in_private_items
1 parent 9b33cd6 commit 54606f5

17 files changed

+3029
-611
lines changed

clippy_lints/src/missing_doc.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::span_lint;
33
use clippy_utils::{is_doc_hidden, is_from_proc_macro};
4-
use rustc_ast::tokenstream::TokenTree;
54
use rustc_attr_parsing::AttributeKind;
65
use rustc_hir::def_id::LocalDefId;
76
use rustc_hir::{
@@ -145,8 +144,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
145144
| ItemKind::Use(..) => return,
146145

147146
ItemKind::Mod(ident, ..) => {
148-
self.module_depth += 1;
149147
if item.span.from_expansion() && item.span.eq_ctxt(ident.span) {
148+
self.module_depth += 1;
150149
self.require_visibility_at = cx.tcx.opt_local_parent(item.owner_id.def_id);
151150
self.macro_module_depth = self.module_depth;
152151
return;
@@ -177,6 +176,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
177176
"missing documentation for item",
178177
);
179178
}
179+
if matches!(item.kind, ItemKind::Mod(..)) {
180+
self.module_depth += 1;
181+
}
180182
}
181183

182184
fn check_item_post(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
@@ -285,13 +287,7 @@ fn is_doc_attr(attr: &Attribute) -> bool {
285287
if let [ident] = &*attr.path.segments
286288
&& ident.name == sym::doc =>
287289
{
288-
match &attr.args {
289-
AttrArgs::Eq { .. } => true,
290-
AttrArgs::Delimited(args) if let Some(TokenTree::Token(t, _)) = args.tokens.get(0) => {
291-
t.is_ident_named(sym::include)
292-
},
293-
_ => false,
294-
}
290+
matches!(attr.args, AttrArgs::Eq { .. })
295291
},
296292
_ => false,
297293
}

clippy_utils/src/check_proc_macro.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,14 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
259259
ItemKind::Trait(IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")),
260260
ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")),
261261
ItemKind::Impl(_) => (Pat::Str("impl"), Pat::Str("}")),
262-
_ => return (Pat::Str(""), Pat::Str("")),
262+
ItemKind::Mod(..) => (Pat::Str("mod"), Pat::Str("}")),
263+
ItemKind::Macro(_, def, _) => (
264+
Pat::Str(if def.macro_rules { "macro_rules" } else { "macro" }),
265+
Pat::Str(""),
266+
),
267+
ItemKind::TraitAlias(..) => (Pat::Str("trait"), Pat::Str(";")),
268+
ItemKind::GlobalAsm { .. } => return (Pat::Str("global_asm"), Pat::Str("")),
269+
ItemKind::Use(..) => return (Pat::Str(""), Pat::Str("")),
263270
};
264271
if item.vis_span.is_empty() {
265272
(start_pat, end_pat)

tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/ui-toml/missing_docs_allow_unused/missing_docs_allow_unused.stderr

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/ui-toml/missing_docs_in_private_items/default/clippy.toml

Whitespace-only changes.

0 commit comments

Comments
 (0)