Move ref to packed struct field check into projection arm

This commit is contained in:
Oliver Scherer 2018-11-03 15:21:44 +01:00
parent ec6573f33b
commit 693c55372e

View file

@ -166,6 +166,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
place: &Place<'tcx>,
context: PlaceContext<'tcx>,
location: Location) {
match place {
&Place::Projection(box Projection {
ref base, ref elem
}) => {
if context.is_borrow() {
if util::is_disaligned(self.tcx, self.mir, self.param_env, place) {
let source_info = self.source_info;
@ -176,18 +180,14 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
description: Symbol::intern("borrow of packed field").as_interned_str(),
details:
Symbol::intern("fields of packed structs might be misaligned: \
dereferencing a misaligned pointer or even just creating a \
misaligned reference is undefined behavior")
dereferencing a misaligned pointer or even just \
creating a misaligned reference is undefined \
behavior")
.as_interned_str(),
kind: UnsafetyViolationKind::BorrowPacked(lint_root)
}], &[]);
}
}
match place {
&Place::Projection(box Projection {
ref base, ref elem
}) => {
let old_source_info = self.source_info;
if let &Place::Local(local) = base {
if self.mir.local_decls[local].internal {