]> git.lizzy.rs Git - rust.git/commitdiff
Add error when using repr(align=x) instead of repr(align(x))
authorvarkor <github@varkor.com>
Sun, 29 Apr 2018 17:42:43 +0000 (18:42 +0100)
committervarkor <github@varkor.com>
Sun, 29 Apr 2018 17:42:43 +0000 (18:42 +0100)
src/libsyntax/attr.rs
src/libsyntax/diagnostic_list.rs

index c68a743303a277b315536756208488aba62837ee..f0557277267a519a5f10d5f2415a549e3e8e608f 100644 (file)
@@ -1045,6 +1045,30 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
                         span_err!(diagnostic, item.span, E0589,
                                   "invalid `repr(align)` attribute: {}", literal_error);
                     }
+                } else {
+                    if let Some(meta_item) = item.meta_item() {
+                        if meta_item.ident.name == "align" {
+                            if let MetaItemKind::NameValue(ref value) = meta_item.node {
+                                recognised = true;
+                                let mut err = struct_span_err!(diagnostic, item.span, E0693,
+                                    "incorrect `repr(align)` attribute format");
+                                match value.node {
+                                    ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
+                                        err.span_suggestion(item.span,
+                                                            "use parentheses instead",
+                                                            format!("align({})", int));
+                                    }
+                                    ast::LitKind::Str(s, _) => {
+                                        err.span_suggestion(item.span,
+                                                            "use parentheses instead",
+                                                            format!("align({})", s));
+                                    }
+                                    _ => {}
+                                }
+                                err.emit();
+                            }
+                        }
+                    }
                 }
                 if !recognised {
                     // Not a word we recognize
index bb7988e64bce9b9f7a9e0a272151a27e16a607a4..c9cac1b11427ad5eb01ecdaef9720b93a06d5045 100644 (file)
@@ -324,4 +324,5 @@ fn main() {}
     E0589, // invalid `repr(align)` attribute
     E0629, // missing 'feature' (rustc_const_unstable)
     E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
+    E0693, // incorrect `repr(align)` attribute format
 }