mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Auto merge of #10950 - KisaragiEffective:ignore_main_in_notest_doc_block, r=xFrednet
[`needless_doctest_main`]: ignore `main()` in `no_test` code fences close #10491 *Please write a short comment explaining your change (or "none" for internal only changes)* changelog: [`needless_doctest_main`]: ignore `main()` in `no_test` code fence
This commit is contained in:
commit
1d0d686f10
2 changed files with 24 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);
|
||||||
}
|
}
|
||||||
|
|
20
tests/ui/doc/needless_doctest_main.rs
Normal file
20
tests/ui/doc/needless_doctest_main.rs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#![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() {}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in a new issue