parent
504328a31a
commit
200c4d0410
5 changed files with 21 additions and 19 deletions
|
@ -2025,5 +2025,4 @@ register_diagnostics! {
|
||||||
E0490, // a value of type `..` is borrowed for too long
|
E0490, // a value of type `..` is borrowed for too long
|
||||||
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
|
E0495, // cannot infer an appropriate lifetime due to conflicting requirements
|
||||||
E0566, // conflicting representation hints
|
E0566, // conflicting representation hints
|
||||||
E0587, // conflicting packed and align representation hints
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,8 +76,6 @@ impl<'a> CheckAttrVisitor<'a> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut conflicting_reprs = 0;
|
let mut conflicting_reprs = 0;
|
||||||
let mut found_packed = false;
|
|
||||||
let mut found_align = false;
|
|
||||||
|
|
||||||
for word in words {
|
for word in words {
|
||||||
|
|
||||||
|
@ -106,7 +104,6 @@ impl<'a> CheckAttrVisitor<'a> {
|
||||||
("attribute should be applied to struct or union",
|
("attribute should be applied to struct or union",
|
||||||
"a struct or union")
|
"a struct or union")
|
||||||
} else {
|
} else {
|
||||||
found_packed = true;
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,7 +117,6 @@ impl<'a> CheckAttrVisitor<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"align" => {
|
"align" => {
|
||||||
found_align = true;
|
|
||||||
if target != Target::Struct &&
|
if target != Target::Struct &&
|
||||||
target != Target::Union {
|
target != Target::Union {
|
||||||
("attribute should be applied to struct or union",
|
("attribute should be applied to struct or union",
|
||||||
|
@ -150,10 +146,6 @@ impl<'a> CheckAttrVisitor<'a> {
|
||||||
span_warn!(self.sess, attr.span, E0566,
|
span_warn!(self.sess, attr.span, E0566,
|
||||||
"conflicting representation hints");
|
"conflicting representation hints");
|
||||||
}
|
}
|
||||||
if found_align && found_packed {
|
|
||||||
struct_span_err!(self.sess, attr.span, E0587,
|
|
||||||
"conflicting packed and align representation hints").emit();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1063,11 +1063,7 @@ fn check_struct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
check_simd(tcx, span, def_id);
|
check_simd(tcx, span, def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// if struct is packed and not aligned, check fields for alignment.
|
check_packed(tcx, span, def_id);
|
||||||
// Checks for combining packed and align attrs on single struct are done elsewhere.
|
|
||||||
if tcx.adt_def(def_id).repr.packed() && tcx.adt_def(def_id).repr.align == 0 {
|
|
||||||
check_packed(tcx, span, def_id);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
|
@ -1478,9 +1474,15 @@ pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId) {
|
fn check_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId) {
|
||||||
if check_packed_inner(tcx, def_id, &mut Vec::new()) {
|
if tcx.adt_def(def_id).repr.packed() {
|
||||||
struct_span_err!(tcx.sess, sp, E0588,
|
if tcx.adt_def(def_id).repr.align > 0 {
|
||||||
"packed struct cannot transitively contain a `[repr(align)]` struct").emit();
|
struct_span_err!(tcx.sess, sp, E0587,
|
||||||
|
"struct has conflicting packed and align representation hints").emit();
|
||||||
|
}
|
||||||
|
else if check_packed_inner(tcx, def_id, &mut Vec::new()) {
|
||||||
|
struct_span_err!(tcx.sess, sp, E0588,
|
||||||
|
"packed struct cannot transitively contain a `[repr(align)]` struct").emit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4663,6 +4663,7 @@ register_diagnostics! {
|
||||||
// but `{}` was found in the type `{}`
|
// but `{}` was found in the type `{}`
|
||||||
E0567, // auto traits can not have type parameters
|
E0567, // auto traits can not have type parameters
|
||||||
E0568, // auto-traits can not have predicates,
|
E0568, // auto-traits can not have predicates,
|
||||||
|
E0587, // struct has conflicting packed and align representation hints
|
||||||
E0588, // packed struct cannot transitively contain a `[repr(align)]` struct
|
E0588, // packed struct cannot transitively contain a `[repr(align)]` struct
|
||||||
E0592, // duplicate definitions with name `{}`
|
E0592, // duplicate definitions with name `{}`
|
||||||
// E0613, // Removed (merged with E0609)
|
// E0613, // Removed (merged with E0609)
|
||||||
|
|
|
@ -27,7 +27,15 @@ enum D { D }
|
||||||
#[repr(C, packed)]
|
#[repr(C, packed)]
|
||||||
struct E(i32);
|
struct E(i32);
|
||||||
|
|
||||||
#[repr(packed, align(8))] //~ ERROR conflicting packed and align representation hints
|
#[repr(packed, align(8))]
|
||||||
struct F(i32);
|
struct F(i32); //~ ERROR struct has conflicting packed and align representation hints
|
||||||
|
|
||||||
|
#[repr(packed)]
|
||||||
|
#[repr(align(8))]
|
||||||
|
struct G(i32); //~ ERROR struct has conflicting packed and align representation hints
|
||||||
|
|
||||||
|
#[repr(align(8))]
|
||||||
|
#[repr(packed)]
|
||||||
|
struct H(i32); //~ ERROR struct has conflicting packed and align representation hints
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue