From 62044b2fab83d6a99a2f0f74b2a88ef4722be597 Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Mon, 17 May 2021 19:32:14 +0200 Subject: [PATCH] Remove remnants of BorrowOfPackedField --- compiler/rustc_middle/src/mir/query.rs | 6 -- .../rustc_mir_build/src/check_unsafety.rs | 59 +++++++------------ 2 files changed, 22 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_middle/src/mir/query.rs b/compiler/rustc_middle/src/mir/query.rs index a80aa6ad3d8..0edb79fdbc8 100644 --- a/compiler/rustc_middle/src/mir/query.rs +++ b/compiler/rustc_middle/src/mir/query.rs @@ -32,7 +32,6 @@ pub enum UnsafetyViolationDetails { UseOfInlineAssembly, InitializingTypeWith, CastOfPointerToInt, - BorrowOfPackedField, UseOfMutableStatic, UseOfExternStatic, DerefOfRawPointer, @@ -64,11 +63,6 @@ pub fn description_and_note(&self) -> (&'static str, &'static str) { CastOfPointerToInt => { ("cast of pointer to int", "casting pointers to integers in constants") } - BorrowOfPackedField => ( - "borrow of packed field", - "fields of packed structs might be misaligned: dereferencing a misaligned pointer \ - or even just creating a misaligned reference is undefined behavior", - ), UseOfMutableStatic => ( "use of mutable static", "mutable statics can be mutated by multiple threads: aliasing violations or data \ diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 83288fa541e..32799cbf4c7 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -64,38 +64,30 @@ fn requires_unsafe(&mut self, span: Span, kind: UnsafeOpKind) { SafetyContext::UnsafeFn if unsafe_op_in_unsafe_fn_allowed => {} SafetyContext::UnsafeFn => { // unsafe_op_in_unsafe_fn is disallowed - if kind == BorrowOfPackedField { - // FIXME handle borrows of packed fields - } else { - struct_span_err!( - self.tcx.sess, - span, - E0133, - "{} is unsafe and requires unsafe block", - description, - ) - .span_label(span, description) - .note(note) - .emit(); - } + struct_span_err!( + self.tcx.sess, + span, + E0133, + "{} is unsafe and requires unsafe block", + description, + ) + .span_label(span, description) + .note(note) + .emit(); } SafetyContext::Safe => { - if kind == BorrowOfPackedField { - // FIXME handle borrows of packed fields - } else { - let fn_sugg = if unsafe_op_in_unsafe_fn_allowed { " function or" } else { "" }; - struct_span_err!( - self.tcx.sess, - span, - E0133, - "{} is unsafe and requires unsafe{} block", - description, - fn_sugg, - ) - .span_label(span, description) - .note(note) - .emit(); - } + let fn_sugg = if unsafe_op_in_unsafe_fn_allowed { " function or" } else { "" }; + struct_span_err!( + self.tcx.sess, + span, + E0133, + "{} is unsafe and requires unsafe{} block", + description, + fn_sugg, + ) + .span_label(span, description) + .note(note) + .emit(); } } } @@ -203,8 +195,6 @@ enum UnsafeOpKind { #[allow(dead_code)] // FIXME CastOfPointerToInt, #[allow(dead_code)] // FIXME - BorrowOfPackedField, - #[allow(dead_code)] // FIXME UseOfMutableStatic, #[allow(dead_code)] // FIXME UseOfExternStatic, @@ -244,11 +234,6 @@ pub fn description_and_note(&self) -> (&'static str, &'static str) { CastOfPointerToInt => { ("cast of pointer to int", "casting pointers to integers in constants") } - BorrowOfPackedField => ( - "borrow of packed field", - "fields of packed structs might be misaligned: dereferencing a misaligned pointer \ - or even just creating a misaligned reference is undefined behavior", - ), UseOfMutableStatic => ( "use of mutable static", "mutable statics can be mutated by multiple threads: aliasing violations or data \