Skip to content

Commit 693c553

Browse files
committed
Move ref to packed struct field check into projection arm
1 parent ec6573f commit 693c553

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/librustc_mir/transform/check_unsafety.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -166,28 +166,28 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
166166
place: &Place<'tcx>,
167167
context: PlaceContext<'tcx>,
168168
location: Location) {
169-
if context.is_borrow() {
170-
if util::is_disaligned(self.tcx, self.mir, self.param_env, place) {
171-
let source_info = self.source_info;
172-
let lint_root =
173-
self.source_scope_local_data[source_info.scope].lint_root;
174-
self.register_violations(&[UnsafetyViolation {
175-
source_info,
176-
description: Symbol::intern("borrow of packed field").as_interned_str(),
177-
details:
178-
Symbol::intern("fields of packed structs might be misaligned: \
179-
dereferencing a misaligned pointer or even just creating a \
180-
misaligned reference is undefined behavior")
181-
.as_interned_str(),
182-
kind: UnsafetyViolationKind::BorrowPacked(lint_root)
183-
}], &[]);
184-
}
185-
}
186-
187169
match place {
188170
&Place::Projection(box Projection {
189171
ref base, ref elem
190172
}) => {
173+
if context.is_borrow() {
174+
if util::is_disaligned(self.tcx, self.mir, self.param_env, place) {
175+
let source_info = self.source_info;
176+
let lint_root =
177+
self.source_scope_local_data[source_info.scope].lint_root;
178+
self.register_violations(&[UnsafetyViolation {
179+
source_info,
180+
description: Symbol::intern("borrow of packed field").as_interned_str(),
181+
details:
182+
Symbol::intern("fields of packed structs might be misaligned: \
183+
dereferencing a misaligned pointer or even just \
184+
creating a misaligned reference is undefined \
185+
behavior")
186+
.as_interned_str(),
187+
kind: UnsafetyViolationKind::BorrowPacked(lint_root)
188+
}], &[]);
189+
}
190+
}
191191
let old_source_info = self.source_info;
192192
if let &Place::Local(local) = base {
193193
if self.mir.local_decls[local].internal {

0 commit comments

Comments
 (0)