Auto merge of #3883 - daxpedda:missing_docs_in_private_items, r=phansch

Add `doc(include = ...)` detection to `missing_docs_in_private_items`

The whole `missing documentation in crate` part doesn't have any tests. If I should add test cases tell me.
This commit is contained in:
bors 2019-03-15 06:18:28 +00:00
commit e7806413c6
5 changed files with 39 additions and 2 deletions

View file

@ -6,11 +6,12 @@
//
use crate::utils::{in_macro, span_lint};
use if_chain::if_chain;
use rustc::hir;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use syntax::ast;
use syntax::ast::{self, MetaItem, MetaItemKind};
use syntax::attr;
use syntax::source_map::Span;
@ -52,6 +53,20 @@ impl MissingDoc {
*self.doc_hidden_stack.last().expect("empty doc_hidden_stack")
}
fn has_include(meta: Option<MetaItem>) -> bool {
if_chain! {
if let Some(meta) = meta;
if let MetaItemKind::List(list) = meta.node;
if let Some(meta) = list.get(0);
if let Some(name) = meta.name();
then {
name == "include"
} else {
false
}
}
}
fn check_missing_docs_attrs(
&self,
cx: &LateContext<'_, '_>,
@ -74,7 +89,9 @@ impl MissingDoc {
return;
}
let has_doc = attrs.iter().any(|a| a.is_value_str() && a.name() == "doc");
let has_doc = attrs
.iter()
.any(|a| a.name() == "doc" && (a.is_value_str() || Self::has_include(a.meta())));
if !has_doc {
span_lint(
cx,

View file

@ -0,0 +1,3 @@
#![warn(clippy::missing_docs_in_private_items)]
fn main() {}

View file

@ -0,0 +1,12 @@
error: missing documentation for crate
--> $DIR/missing-doc-crate-missing.rs:1:1
|
LL | / #![warn(clippy::missing_docs_in_private_items)]
LL | |
LL | | fn main() {}
| |____________^
|
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
error: aborting due to previous error

View file

@ -0,0 +1,5 @@
#![warn(clippy::missing_docs_in_private_items)]
#![feature(external_doc)]
#![doc(include = "../../README.md")]
fn main() {}

View file