about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorSamuel Moelius <sam@moeli.us>2024-11-13 10:16:59 -0500
committerSamuel Moelius <sam@moeli.us>2024-11-15 17:37:10 -0500
commitd0f35777205090e24d5822e668cc280cab78e4ec (patch)
treef3ff1070975014212d9acf53a3edb7097094b939 /tests
parentf159a3eb1dfc3b81088fce364a09e8a79968adda (diff)
downloadrust-d0f35777205090e24d5822e668cc280cab78e4ec.tar.gz
rust-d0f35777205090e24d5822e668cc280cab78e4ec.zip
Properly handle `disallowed_types`
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-toml/replaceable_disallowed_types/clippy.toml3
-rw-r--r--tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed16
-rw-r--r--tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs16
-rw-r--r--tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr11
4 files changed, 46 insertions, 0 deletions
diff --git a/tests/ui-toml/replaceable_disallowed_types/clippy.toml b/tests/ui-toml/replaceable_disallowed_types/clippy.toml
new file mode 100644
index 00000000000..a08a2f00f50
--- /dev/null
+++ b/tests/ui-toml/replaceable_disallowed_types/clippy.toml
@@ -0,0 +1,3 @@
+disallowed-types = [
+    { path = "std::string::String", replacement = "wrapper::String" },
+]
diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed
new file mode 100644
index 00000000000..6546981bd81
--- /dev/null
+++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.fixed
@@ -0,0 +1,16 @@
+#![warn(clippy::disallowed_types)]
+
+#[allow(clippy::disallowed_types)]
+mod wrapper {
+    pub struct String(std::string::String);
+
+    impl From<&str> for String {
+        fn from(value: &str) -> Self {
+            Self(std::string::String::from(value))
+        }
+    }
+}
+
+fn main() {
+    let _ = wrapper::String::from("x");
+}
diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs
new file mode 100644
index 00000000000..d76f1af481d
--- /dev/null
+++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs
@@ -0,0 +1,16 @@
+#![warn(clippy::disallowed_types)]
+
+#[allow(clippy::disallowed_types)]
+mod wrapper {
+    pub struct String(std::string::String);
+
+    impl From<&str> for String {
+        fn from(value: &str) -> Self {
+            Self(std::string::String::from(value))
+        }
+    }
+}
+
+fn main() {
+    let _ = String::from("x");
+}
diff --git a/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr
new file mode 100644
index 00000000000..bb63e6970a1
--- /dev/null
+++ b/tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.stderr
@@ -0,0 +1,11 @@
+error: use of a disallowed type `std::string::String`
+  --> tests/ui-toml/replaceable_disallowed_types/replaceable_disallowed_types.rs:15:13
+   |
+LL |     let _ = String::from("x");
+   |             ^^^^^^ help: use: `wrapper::String`
+   |
+   = note: `-D clippy::disallowed-types` implied by `-D warnings`
+   = help: to override `-D warnings` add `#[allow(clippy::disallowed_types)]`
+
+error: aborting due to 1 previous error
+