Skip to content

Commit d24b229

Browse files
authored
Rollup merge of #106327 - gimbles:dbg, r=jyn514
Add tidy check for dbg Fixes #106169
2 parents 3361247 + cc28813 commit d24b229

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

library/std/src/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! This module contains a set of macros which are exported from the standard
44
//! library. Each macro is available for use when linking against the standard
55
//! library.
6+
// ignore-tidy-dbg
67

78
#[doc = include_str!("../../core/src/macros/panic.md")]
89
#[macro_export]

src/tools/tidy/src/style.rs

+17
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//!
1616
//! A number of these checks can be opted-out of with various directives of the form:
1717
//! `// ignore-tidy-CHECK-NAME`.
18+
// ignore-tidy-dbg
1819

1920
use crate::walk::{filter_dirs, walk};
2021
use regex::{Regex, RegexSet};
@@ -278,6 +279,7 @@ pub fn check(path: &Path, bad: &mut bool) {
278279
let mut skip_leading_newlines =
279280
contains_ignore_directive(can_contain, &contents, "leading-newlines");
280281
let mut skip_copyright = contains_ignore_directive(can_contain, &contents, "copyright");
282+
let mut skip_dbg = contains_ignore_directive(can_contain, &contents, "dbg");
281283
let mut leading_new_lines = false;
282284
let mut trailing_new_lines = 0;
283285
let mut lines = 0;
@@ -306,6 +308,21 @@ pub fn check(path: &Path, bad: &mut bool) {
306308
let mut err = |msg: &str| {
307309
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
308310
};
311+
312+
if trimmed.contains("dbg!")
313+
&& !trimmed.starts_with("//")
314+
&& !file
315+
.ancestors()
316+
.any(|a| a.ends_with("src/test") || a.ends_with("library/alloc/tests"))
317+
&& filename != "tests.rs"
318+
{
319+
suppressible_tidy_err!(
320+
err,
321+
skip_dbg,
322+
"`dbg!` macro is intended as a debugging tool. It should not be in version control."
323+
)
324+
}
325+
309326
if !under_rustfmt
310327
&& line.chars().count() > max_columns
311328
&& !long_line_is_ok(&extension, is_error_code, max_columns, line)

0 commit comments

Comments
 (0)