diff options
| author | Andre Bogus <bogusandre@gmail.com> | 2019-12-23 13:11:20 +0100 |
|---|---|---|
| committer | Andre Bogus <bogusandre@gmail.com> | 2019-12-24 13:42:37 +0100 |
| commit | 129d0cd0f465510cf4b8ee46ce3bdb51c5fa2286 (patch) | |
| tree | a00f18dc3cc203083eebad08578499142419cfbb | |
| parent | 2730d64d7799289e4f12bbf6769f592a2b64df74 (diff) | |
| download | rust-129d0cd0f465510cf4b8ee46ce3bdb51c5fa2286.tar.gz rust-129d0cd0f465510cf4b8ee46ce3bdb51c5fa2286.zip | |
Avoid needless_doctest_main on 'extern crate'
| -rw-r--r-- | clippy_lints/src/doc.rs | 4 | ||||
| -rw-r--r-- | tests/ui/needless_doc_main.rs | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/clippy_lints/src/doc.rs b/clippy_lints/src/doc.rs index 327c18e855d..a997fd8b6b8 100644 --- a/clippy_lints/src/doc.rs +++ b/clippy_lints/src/doc.rs @@ -390,8 +390,10 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize headers } +static LEAVE_MAIN_PATTERNS: &[&str] = &["static", "fn main() {}", "extern crate"]; + fn check_code(cx: &LateContext<'_, '_>, text: &str, span: Span) { - if text.contains("fn main() {") && !(text.contains("static") || text.contains("fn main() {}")) { + if text.contains("fn main() {") && !LEAVE_MAIN_PATTERNS.iter().any(|p| text.contains(p)) { span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest"); } } diff --git a/tests/ui/needless_doc_main.rs b/tests/ui/needless_doc_main.rs index d2a3857b554..813d2606153 100644 --- a/tests/ui/needless_doc_main.rs +++ b/tests/ui/needless_doc_main.rs @@ -25,6 +25,15 @@ fn bad_doctest() {} /// assert_eq!(42, ANSWER); /// } /// ``` +/// +/// Neither should this lint because of `extern crate`: +/// ``` +/// #![feature(test)] +/// extern crate test; +/// fn main() { +/// assert_eq(1u8, test::black_box(1)); +/// } +/// ``` fn no_false_positives() {} fn main() { |
