mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 23:20:39 +00:00
Ignore main()
in no_test
code fences
This commit is contained in:
parent
eefc2a0ac4
commit
062b209904
2 changed files with 23 additions and 1 deletions
|
@ -571,6 +571,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
|
||||||
let mut in_link = None;
|
let mut in_link = None;
|
||||||
let mut in_heading = false;
|
let mut in_heading = false;
|
||||||
let mut is_rust = false;
|
let mut is_rust = false;
|
||||||
|
let mut no_test = false;
|
||||||
let mut edition = None;
|
let mut edition = None;
|
||||||
let mut ticks_unbalanced = false;
|
let mut ticks_unbalanced = false;
|
||||||
let mut text_to_check: Vec<(CowStr<'_>, Span)> = Vec::new();
|
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
|
||||||
if item == "ignore" {
|
if item == "ignore" {
|
||||||
is_rust = false;
|
is_rust = false;
|
||||||
break;
|
break;
|
||||||
|
} else if item == "no_test" {
|
||||||
|
no_test = true;
|
||||||
}
|
}
|
||||||
if let Some(stripped) = item.strip_prefix("edition") {
|
if let Some(stripped) = item.strip_prefix("edition") {
|
||||||
is_rust = true;
|
is_rust = true;
|
||||||
|
@ -648,7 +651,7 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
|
||||||
headers.errors |= in_heading && trimmed_text == "Errors";
|
headers.errors |= in_heading && trimmed_text == "Errors";
|
||||||
headers.panics |= in_heading && trimmed_text == "Panics";
|
headers.panics |= in_heading && trimmed_text == "Panics";
|
||||||
if in_code {
|
if in_code {
|
||||||
if is_rust {
|
if is_rust && !no_test {
|
||||||
let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition());
|
let edition = edition.unwrap_or_else(|| cx.tcx.sess.edition());
|
||||||
check_code(cx, &text, edition, span);
|
check_code(cx, &text, edition, span);
|
||||||
}
|
}
|
||||||
|
|
19
tests/ui/doc/needless_doctest_main.rs
Normal file
19
tests/ui/doc/needless_doctest_main.rs
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
#![warn(clippy::needless_doctest_main)]
|
||||||
|
//! issue 10491:
|
||||||
|
//! ```rust,no_test
|
||||||
|
//! use std::collections::HashMap;
|
||||||
|
//!
|
||||||
|
//! fn main() {
|
||||||
|
//! let mut m = HashMap::new();
|
||||||
|
//! m.insert(1u32, 2u32);
|
||||||
|
//! }
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
|
||||||
|
/// some description here
|
||||||
|
/// ```rust,no_test
|
||||||
|
/// fn main() {
|
||||||
|
/// foo()
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
fn foo() {}
|
Loading…
Reference in a new issue