about summary refs log tree commit diff
diff options
context:
space:
mode:
authorgimbles <yusharora@protonmail.com>2022-12-31 15:32:09 +0530
committergimbles <yusharora@protonmail.com>2022-12-31 15:32:09 +0530
commitcc2881391a1f1e01faa2f7ff21a172a15fbbaacd (patch)
tree4c08e5620cd838f9f4f7a15d231ec912c14b2739
parent247e44e61d934e1927db0ff557fe17f131a2379c (diff)
downloadrust-cc2881391a1f1e01faa2f7ff21a172a15fbbaacd.tar.gz
rust-cc2881391a1f1e01faa2f7ff21a172a15fbbaacd.zip
Add tidy check for dbg
-rw-r--r--library/std/src/macros.rs1
-rw-r--r--src/tools/tidy/src/style.rs17
2 files changed, 18 insertions, 0 deletions
diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs
index 6e4ba1404e5..fcc5cfafd80 100644
--- a/library/std/src/macros.rs
+++ b/library/std/src/macros.rs
@@ -3,6 +3,7 @@
 //! This module contains a set of macros which are exported from the standard
 //! library. Each macro is available for use when linking against the standard
 //! library.
+// ignore-tidy-dbg
 
 #[doc = include_str!("../../core/src/macros/panic.md")]
 #[macro_export]
diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs
index f91e38262f6..f409a86db26 100644
--- a/src/tools/tidy/src/style.rs
+++ b/src/tools/tidy/src/style.rs
@@ -15,6 +15,7 @@
 //!
 //! A number of these checks can be opted-out of with various directives of the form:
 //! `// ignore-tidy-CHECK-NAME`.
+// ignore-tidy-dbg
 
 use crate::walk::{filter_dirs, walk};
 use regex::{Regex, RegexSet};
@@ -278,6 +279,7 @@ pub fn check(path: &Path, bad: &mut bool) {
         let mut skip_leading_newlines =
             contains_ignore_directive(can_contain, &contents, "leading-newlines");
         let mut skip_copyright = contains_ignore_directive(can_contain, &contents, "copyright");
+        let mut skip_dbg = contains_ignore_directive(can_contain, &contents, "dbg");
         let mut leading_new_lines = false;
         let mut trailing_new_lines = 0;
         let mut lines = 0;
@@ -306,6 +308,21 @@ pub fn check(path: &Path, bad: &mut bool) {
             let mut err = |msg: &str| {
                 tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
             };
+
+            if trimmed.contains("dbg!")
+                && !trimmed.starts_with("//")
+                && !file
+                    .ancestors()
+                    .any(|a| a.ends_with("src/test") || a.ends_with("library/alloc/tests"))
+                && filename != "tests.rs"
+            {
+                suppressible_tidy_err!(
+                    err,
+                    skip_dbg,
+                    "`dbg!` macro is intended as a debugging tool. It should not be in version control."
+                )
+            }
+
             if !under_rustfmt
                 && line.chars().count() > max_columns
                 && !long_line_is_ok(&extension, is_error_code, max_columns, line)