1
Fork 0

Rollup merge of #110973 - bindsdev:packed-struct-ref-diagnostic-note, r=compiler-errors

improve error notes for packed struct reference diagnostic

Addresses #110199
This commit is contained in:
Matthias Krüger 2023-04-30 01:14:58 +02:00 committed by GitHub
commit 791d33c5eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 27 deletions

View file

@ -56,8 +56,11 @@ impl<'tcx> Visitor<'tcx> for PackedRefChecker<'_, 'tcx> {
"reference to packed field is unaligned"
)
.note(
"fields of packed structs are not properly aligned, and creating \
a misaligned reference is undefined behavior (even if that \
"packed structs are only aligned by one byte, and many modern architectures \
penalize unaligned field accesses"
)
.note(
"creating a misaligned reference is undefined behavior (even if that \
reference is never dereferenced)",
).help(
"copy the field contents to a local variable, or replace the \