Skip to content

Commit 129d0cd

Browse files
committed
Avoid needless_doctest_main on 'extern crate'
1 parent 2730d64 commit 129d0cd

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clippy_lints/src/doc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
390390
headers
391391
}
392392

393+
static LEAVE_MAIN_PATTERNS: &[&str] = &["static", "fn main() {}", "extern crate"];
394+
393395
fn check_code(cx: &LateContext<'_, '_>, text: &str, span: Span) {
394-
if text.contains("fn main() {") && !(text.contains("static") || text.contains("fn main() {}")) {
396+
if text.contains("fn main() {") && !LEAVE_MAIN_PATTERNS.iter().any(|p| text.contains(p)) {
395397
span_lint(cx, NEEDLESS_DOCTEST_MAIN, span, "needless `fn main` in doctest");
396398
}
397399
}

tests/ui/needless_doc_main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ fn bad_doctest() {}
2525
/// assert_eq!(42, ANSWER);
2626
/// }
2727
/// ```
28+
///
29+
/// Neither should this lint because of `extern crate`:
30+
/// ```
31+
/// #![feature(test)]
32+
/// extern crate test;
33+
/// fn main() {
34+
/// assert_eq(1u8, test::black_box(1));
35+
/// }
36+
/// ```
2837
fn no_false_positives() {}
2938

3039
fn main() {

0 commit comments

Comments
 (0)