diff options
| author | varkor <github@varkor.com> | 2018-04-29 18:42:43 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-04-29 18:42:43 +0100 |
| commit | a815f753bc441d8eeb0f664e27c5a3d5322900e1 (patch) | |
| tree | 1b33e382b04e486152acdf2be0586ed99a6e7644 /src | |
| parent | a9975254ee6510cd1360417d3d145b56fb70b2e7 (diff) | |
| download | rust-a815f753bc441d8eeb0f664e27c5a3d5322900e1.tar.gz rust-a815f753bc441d8eeb0f664e27c5a3d5322900e1.zip | |
Add error when using repr(align=x) instead of repr(align(x))
Diffstat (limited to 'src')
| -rw-r--r-- | src/libsyntax/attr.rs | 24 | ||||
| -rw-r--r-- | src/libsyntax/diagnostic_list.rs | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index c68a743303a..f0557277267 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -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 diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index bb7988e64bc..c9cac1b1142 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -324,4 +324,5 @@ register_diagnostics! { 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 } |
