about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2023-10-18 14:24:50 +0300
committerGitHub <noreply@github.com>2023-10-18 14:24:50 +0300
commit0653d7eebf81bfe699e3d3bf327c9953518a157e (patch)
tree66d04a737e3e8ca0fbb4fff0cec4964b0311aef2
parent6d7160ce97f4bbbd44991a7325077e08214e0ce2 (diff)
parenta8e7e791010a2ff1fca1b65dce48096419b99638 (diff)
downloadrust-0653d7eebf81bfe699e3d3bf327c9953518a157e.tar.gz
rust-0653d7eebf81bfe699e3d3bf327c9953518a157e.zip
Rollup merge of #116812 - rmehri01:missing_copy_implementations_non_exhaustive, r=petrochenkov
Disable missing_copy_implementations lint on non_exhaustive types

Fixes #116766
-rw-r--r--compiler/rustc_lint/src/builtin.rs5
-rw-r--r--tests/ui/lint/missing-copy-implementations-non-exhaustive.rs25
2 files changed, 30 insertions, 0 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs
index 3e44e168786..f6c7f4071dc 100644
--- a/compiler/rustc_lint/src/builtin.rs
+++ b/compiler/rustc_lint/src/builtin.rs
@@ -677,6 +677,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
         if type_implements_negative_copy_modulo_regions(cx.tcx, ty, param_env) {
             return;
         }
+        if def.is_variant_list_non_exhaustive()
+            || def.variants().iter().any(|variant| variant.is_field_list_non_exhaustive())
+        {
+            return;
+        }
 
         // We shouldn't recommend implementing `Copy` on stateful things,
         // such as iterators.
diff --git a/tests/ui/lint/missing-copy-implementations-non-exhaustive.rs b/tests/ui/lint/missing-copy-implementations-non-exhaustive.rs
new file mode 100644
index 00000000000..2d5e90720ef
--- /dev/null
+++ b/tests/ui/lint/missing-copy-implementations-non-exhaustive.rs
@@ -0,0 +1,25 @@
+// Test for issue #116766.
+// Ensure that we don't suggest impl'ing `Copy` for a type if it or at least one
+// of it's variants are marked as `non_exhaustive`.
+
+// check-pass
+
+#![deny(missing_copy_implementations)]
+
+#[non_exhaustive]
+pub enum MyEnum {
+    A,
+}
+
+#[non_exhaustive]
+pub struct MyStruct {
+    foo: usize,
+}
+
+pub enum MyEnum2 {
+    #[non_exhaustive]
+    A,
+    B,
+}
+
+fn main() {}