Allow specifying alignment for functions
This commit is contained in:
parent
138fd56cf9
commit
448d07683a
18 changed files with 137 additions and 83 deletions
|
@ -1127,17 +1127,41 @@ impl CheckAttrVisitor<'tcx> {
|
|||
let mut is_transparent = false;
|
||||
|
||||
for hint in &hints {
|
||||
if !hint.is_meta_item() {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
hint.span(),
|
||||
E0565,
|
||||
"meta item in `repr` must be an identifier"
|
||||
)
|
||||
.emit();
|
||||
continue;
|
||||
}
|
||||
|
||||
let (article, allowed_targets) = match hint.name_or_empty() {
|
||||
_ if !matches!(target, Target::Struct | Target::Enum | Target::Union) => {
|
||||
("a", "struct, enum, or union")
|
||||
}
|
||||
name @ sym::C | name @ sym::align => {
|
||||
is_c |= name == sym::C;
|
||||
sym::C => {
|
||||
is_c = true;
|
||||
match target {
|
||||
Target::Struct | Target::Union | Target::Enum => continue,
|
||||
_ => ("a", "struct, enum, or union"),
|
||||
}
|
||||
}
|
||||
sym::align => {
|
||||
if let (Target::Fn, true) = (target, !self.tcx.features().fn_align) {
|
||||
feature_err(
|
||||
&self.tcx.sess.parse_sess,
|
||||
sym::fn_align,
|
||||
hint.span(),
|
||||
"`repr(align)` attributes on functions are unstable",
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
|
||||
match target {
|
||||
Target::Struct | Target::Union | Target::Enum | Target::Fn => continue,
|
||||
_ => ("a", "struct, enum, function, or union"),
|
||||
}
|
||||
}
|
||||
sym::packed => {
|
||||
if target != Target::Struct && target != Target::Union {
|
||||
("a", "struct or union")
|
||||
|
@ -1194,7 +1218,17 @@ impl CheckAttrVisitor<'tcx> {
|
|||
continue;
|
||||
}
|
||||
}
|
||||
_ => continue,
|
||||
_ => {
|
||||
struct_span_err!(
|
||||
self.tcx.sess,
|
||||
hint.span(),
|
||||
E0552,
|
||||
"unrecognized representation hint"
|
||||
)
|
||||
.emit();
|
||||
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
struct_span_err!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue