Skip to content

Commit 062b209

Browse files
Ignore main() in no_test code fences
1 parent eefc2a0 commit 062b209

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

clippy_lints/src/doc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
571571
let mut in_link = None;
572572
let mut in_heading = false;
573573
let mut is_rust = false;
574+
let mut no_test = false;
574575
let mut edition = None;
575576
let mut ticks_unbalanced = false;
576577
let mut text_to_check: Vec<(CowStr<'_>, Span)> = Vec::new();
@@ -584,6 +585,8 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
584585
if item == "ignore" {
585586
is_rust = false;
586587
break;
588+
} else if item == "no_test" {
589+
no_test = true;
587590
}
588591
if let Some(stripped) = item.strip_prefix("edition") {
589592
is_rust = true;
@@ -648,7 +651,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
648651
headers.errors |= in_heading && trimmed_text == "Errors";
649652
headers.panics |= in_heading && trimmed_text == "Panics";
650653
if in_code {
651-
if is_rust {
654+
if is_rust && !no_test {
652655
let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition());
653656
check_code(cx, &text, edition, span);
654657
}

tests/ui/doc/needless_doctest_main.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![warn(clippy::needless_doctest_main)]
2+
//! issue 10491:
3+
//! ```rust,no_test
4+
//! use std::collections::HashMap;
5+
//!
6+
//! fn main() {
7+
//! let mut m = HashMap::new();
8+
//! m.insert(1u32, 2u32);
9+
//! }
10+
//! ```
11+
//!
12+
13+
/// some description here
14+
/// ```rust,no_test
15+
/// fn main() {
16+
/// foo()
17+
/// }
18+
/// ```
19+
fn foo() {}

0 commit comments

Comments
 (0)