Skip to content

Commit a815f75

Browse files
committed
Add error when using repr(align=x) instead of repr(align(x))
1 parent a997525 commit a815f75

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/libsyntax/attr.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,30 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr>
10451045
span_err!(diagnostic, item.span, E0589,
10461046
"invalid `repr(align)` attribute: {}", literal_error);
10471047
}
1048+
} else {
1049+
if let Some(meta_item) = item.meta_item() {
1050+
if meta_item.ident.name == "align" {
1051+
if let MetaItemKind::NameValue(ref value) = meta_item.node {
1052+
recognised = true;
1053+
let mut err = struct_span_err!(diagnostic, item.span, E0693,
1054+
"incorrect `repr(align)` attribute format");
1055+
match value.node {
1056+
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
1057+
err.span_suggestion(item.span,
1058+
"use parentheses instead",
1059+
format!("align({})", int));
1060+
}
1061+
ast::LitKind::Str(s, _) => {
1062+
err.span_suggestion(item.span,
1063+
"use parentheses instead",
1064+
format!("align({})", s));
1065+
}
1066+
_ => {}
1067+
}
1068+
err.emit();
1069+
}
1070+
}
1071+
}
10481072
}
10491073
if !recognised {
10501074
// Not a word we recognize

src/libsyntax/diagnostic_list.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,4 +324,5 @@ register_diagnostics! {
324324
E0589, // invalid `repr(align)` attribute
325325
E0629, // missing 'feature' (rustc_const_unstable)
326326
E0630, // rustc_const_unstable attribute must be paired with stable/unstable attribute
327+
E0693, // incorrect `repr(align)` attribute format
327328
}

0 commit comments

Comments
 (0)