]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/hir/check_attr.rs
Implement RFC 2645 (transparent enums and unions)
[rust.git] / src / librustc / hir / check_attr.rs
index b199eee6dad87a2285f099fac8a22274264fdedb..f7d1094b3a2d1407c14c471f85a7b0d37afa9760 100644 (file)
@@ -181,12 +181,9 @@ fn check_repr(&self, item: &hir::Item, target: Target) {
             let (article, allowed_targets) = match hint.name_or_empty() {
                 name @ sym::C | name @ sym::align => {
                     is_c |= name == sym::C;
-                    if target != Target::Struct &&
-                            target != Target::Union &&
-                            target != Target::Enum {
-                                ("a", "struct, enum or union")
-                    } else {
-                        continue
+                    match target {
+                        Target::Struct | Target::Union | Target::Enum => continue,
+                        _ => ("a", "struct, enum, or union"),
                     }
                 }
                 sym::packed => {
@@ -207,10 +204,9 @@ fn check_repr(&self, item: &hir::Item, target: Target) {
                 }
                 sym::transparent => {
                     is_transparent = true;
-                    if target != Target::Struct {
-                        ("a", "struct")
-                    } else {
-                        continue
+                    match target {
+                        Target::Struct | Target::Union | Target::Enum => continue,
+                        _ => ("a", "struct, enum, or union"),
                     }
                 }
                 sym::i8  | sym::u8  | sym::i16 | sym::u16 |
@@ -241,7 +237,7 @@ fn check_repr(&self, item: &hir::Item, target: Target) {
         if is_transparent && hints.len() > 1 {
             let hint_spans: Vec<_> = hint_spans.clone().collect();
             span_err!(self.tcx.sess, hint_spans, E0692,
-                      "transparent struct cannot have other repr hints");
+                      "transparent {} cannot have other repr hints", target);
         }
         // Warn on repr(u8, u16), repr(C, simd), and c-like-enum-repr(C, u8)
         if (int_reprs > 1)
@@ -277,7 +273,7 @@ fn check_stmt_attributes(&self, stmt: &hir::Stmt) {
                         attr.span,
                         stmt.span,
                         "attribute should not be applied to a statement",
-                        "not a struct, enum or union",
+                        "not a struct, enum, or union",
                     );
                 }
             }
@@ -298,7 +294,7 @@ fn check_expr_attributes(&self, expr: &hir::Expr) {
                     attr.span,
                     expr.span,
                     "attribute should not be applied to an expression",
-                    "not defining a struct, enum or union",
+                    "not defining a struct, enum, or union",
                 );
             }
         }