]> git.lizzy.rs Git - rust.git/commitdiff
Support unions here and there
authormcarton <cartonmartin+git@gmail.com>
Sun, 28 Aug 2016 17:43:55 +0000 (19:43 +0200)
committermcarton <cartonmartin+git@gmail.com>
Wed, 31 Aug 2016 16:22:36 +0000 (18:22 +0200)
clippy_lints/src/derive.rs
clippy_lints/src/len_zero.rs
tests/compile-fail/derive.rs
tests/compile-fail/no_effect.rs

index a5f3b1c12f6c3ef5df04980c316640ad70958611..17d17a445afd53e09b4751e941a4678f054fe69c 100644 (file)
@@ -140,8 +140,10 @@ fn check_copy_clone<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, item: &Item, trait_ref
             return; // ty is not Copy
         }
 
-        // Some types are not Clone by default but could be cloned `by hand` if necessary
         match ty.sty {
+            TypeVariants::TyUnion(..) => return,
+
+            // Some types are not Clone by default but could be cloned “by hand” if necessary
             TypeVariants::TyEnum(def, substs) |
             TypeVariants::TyStruct(def, substs) => {
                 for variant in &def.variants {
index e8ca113fab1f1532babaab296169a6636784fc4d..d43e31c6a3db9a8903542ac62523da8502191c96 100644 (file)
@@ -209,7 +209,8 @@ fn has_is_empty_impl(cx: &LateContext, id: &DefId) -> bool {
         }
         ty::TyProjection(_) => ty.ty_to_def_id().map_or(false, |id| has_is_empty_impl(cx, &id)),
         ty::TyEnum(id, _) |
-        ty::TyStruct(id, _) => has_is_empty_impl(cx, &id.did),
+        ty::TyStruct(id, _) |
+        ty::TyUnion(id, _) => has_is_empty_impl(cx, &id.did),
         ty::TyArray(..) | ty::TyStr => true,
         _ => false,
     }
index 06f1388dc056916b978d6cb977d4bb965ebfcf63..cf4467f30a59271abe40ea019cf4efdf1890db6f 100644 (file)
@@ -1,6 +1,8 @@
 #![feature(plugin)]
 #![plugin(clippy)]
 
+#![feature(untagged_unions)]
+
 #![deny(warnings)]
 #![allow(dead_code)]
 
@@ -45,6 +47,20 @@ impl Clone for Qux {
     fn clone(&self) -> Self { Qux }
 }
 
+// looks like unions don't support deriving Clone for now
+#[derive(Copy)]
+union Union {
+    a: u8,
+}
+
+impl Clone for Union {
+    fn clone(&self) -> Self {
+        Union {
+            a: 42,
+        }
+    }
+}
+
 // See #666
 #[derive(Copy)]
 struct Lt<'a> {
index 76c7fa54c019687e8545dd5552afb0642105299c..6616f7bdc86c03a4ee2a0f95fdc2521056768068 100644 (file)
@@ -4,6 +4,7 @@
 #![deny(no_effect, unnecessary_operation)]
 #![allow(dead_code)]
 #![allow(path_statements)]
+#![feature(untagged_unions)]
 
 struct Unit;
 struct Tuple(i32);
@@ -15,6 +16,11 @@ enum Enum {
     Struct { field: i32 },
 }
 
+union Union {
+    a: u8,
+    b: f64,
+}
+
 fn get_number() -> i32 { 0 }
 fn get_struct() -> Struct { Struct { field: 0 } }
 
@@ -30,6 +36,7 @@ fn main() {
     Tuple(0); //~ERROR statement with no effect
     Struct { field: 0 }; //~ERROR statement with no effect
     Struct { ..s }; //~ERROR statement with no effect
+    Union { a: 0 }; //~ERROR statement with no effect
     Enum::Tuple(0); //~ERROR statement with no effect
     Enum::Struct { field: 0 }; //~ERROR statement with no effect
     5 + 6; //~ERROR statement with no effect