about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlex Macleod <alex@macleod.io>2022-10-05 13:44:01 +0000
committerAlex Macleod <alex@macleod.io>2022-10-05 13:44:06 +0000
commit86c86c37429e95aee45846262bb50239a69be546 (patch)
tree8cb0c81c1608eb25296f6d7862ccdab93f4e3fd5 /src
parent425e1ea73d1e67c38c1d12e160d5fd20b64ffa5d (diff)
downloadrust-86c86c37429e95aee45846262bb50239a69be546.tar.gz
rust-86c86c37429e95aee45846262bb50239a69be546.zip
Add `disallowed_macros` lint
Diffstat (limited to 'src')
-rw-r--r--src/docs.rs1
-rw-r--r--src/docs/disallowed_macros.txt36
2 files changed, 37 insertions, 0 deletions
diff --git a/src/docs.rs b/src/docs.rs
index 1b727e1a100..3bf488ab477 100644
--- a/src/docs.rs
+++ b/src/docs.rs
@@ -106,6 +106,7 @@ docs! {
     "derive_hash_xor_eq",
     "derive_ord_xor_partial_ord",
     "derive_partial_eq_without_eq",
+    "disallowed_macros",
     "disallowed_methods",
     "disallowed_names",
     "disallowed_script_idents",
diff --git a/src/docs/disallowed_macros.txt b/src/docs/disallowed_macros.txt
new file mode 100644
index 00000000000..96fa15afabf
--- /dev/null
+++ b/src/docs/disallowed_macros.txt
@@ -0,0 +1,36 @@
+### What it does
+Denies the configured macros in clippy.toml
+
+Note: Even though this lint is warn-by-default, it will only trigger if
+macros are defined in the clippy.toml file.
+
+### Why is this bad?
+Some macros are undesirable in certain contexts, and it's beneficial to
+lint for them as needed.
+
+### Example
+An example clippy.toml configuration:
+```
+disallowed-macros = [
+    # Can use a string as the path of the disallowed macro.
+    "std::print",
+    # Can also use an inline table with a `path` key.
+    { path = "std::println" },
+    # When using an inline table, can add a `reason` for why the macro
+    # is disallowed.
+    { path = "serde::Serialize", reason = "no serializing" },
+]
+```
+```
+use serde::Serialize;
+
+// Example code where clippy issues a warning
+println!("warns");
+
+// The diagnostic will contain the message "no serializing"
+#[derive(Serialize)]
+struct Data {
+    name: String,
+    value: usize,
+}
+```
\ No newline at end of file