Skip to content

Commit f4a0d97

Browse files
Rollup merge of #85415 - LeSeulArtichaut:no-packed-borrow-unsafeck, r=RalfJung
Clean up remnants of BorrowOfPackedField cc #82525 which removed `BorrowOfPackedField` from unsafety-checking r? `@RalfJung`
2 parents 5f544bc + 62044b2 commit f4a0d97

File tree

2 files changed

+22
-43
lines changed

2 files changed

+22
-43
lines changed

compiler/rustc_middle/src/mir/query.rs

-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ pub enum UnsafetyViolationDetails {
3232
UseOfInlineAssembly,
3333
InitializingTypeWith,
3434
CastOfPointerToInt,
35-
BorrowOfPackedField,
3635
UseOfMutableStatic,
3736
UseOfExternStatic,
3837
DerefOfRawPointer,
@@ -64,11 +63,6 @@ impl UnsafetyViolationDetails {
6463
CastOfPointerToInt => {
6564
("cast of pointer to int", "casting pointers to integers in constants")
6665
}
67-
BorrowOfPackedField => (
68-
"borrow of packed field",
69-
"fields of packed structs might be misaligned: dereferencing a misaligned pointer \
70-
or even just creating a misaligned reference is undefined behavior",
71-
),
7266
UseOfMutableStatic => (
7367
"use of mutable static",
7468
"mutable statics can be mutated by multiple threads: aliasing violations or data \

compiler/rustc_mir_build/src/check_unsafety.rs

+22-37
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,30 @@ impl<'tcx> UnsafetyVisitor<'tcx> {
6464
SafetyContext::UnsafeFn if unsafe_op_in_unsafe_fn_allowed => {}
6565
SafetyContext::UnsafeFn => {
6666
// unsafe_op_in_unsafe_fn is disallowed
67-
if kind == BorrowOfPackedField {
68-
// FIXME handle borrows of packed fields
69-
} else {
70-
struct_span_err!(
71-
self.tcx.sess,
72-
span,
73-
E0133,
74-
"{} is unsafe and requires unsafe block",
75-
description,
76-
)
77-
.span_label(span, description)
78-
.note(note)
79-
.emit();
80-
}
67+
struct_span_err!(
68+
self.tcx.sess,
69+
span,
70+
E0133,
71+
"{} is unsafe and requires unsafe block",
72+
description,
73+
)
74+
.span_label(span, description)
75+
.note(note)
76+
.emit();
8177
}
8278
SafetyContext::Safe => {
83-
if kind == BorrowOfPackedField {
84-
// FIXME handle borrows of packed fields
85-
} else {
86-
let fn_sugg = if unsafe_op_in_unsafe_fn_allowed { " function or" } else { "" };
87-
struct_span_err!(
88-
self.tcx.sess,
89-
span,
90-
E0133,
91-
"{} is unsafe and requires unsafe{} block",
92-
description,
93-
fn_sugg,
94-
)
95-
.span_label(span, description)
96-
.note(note)
97-
.emit();
98-
}
79+
let fn_sugg = if unsafe_op_in_unsafe_fn_allowed { " function or" } else { "" };
80+
struct_span_err!(
81+
self.tcx.sess,
82+
span,
83+
E0133,
84+
"{} is unsafe and requires unsafe{} block",
85+
description,
86+
fn_sugg,
87+
)
88+
.span_label(span, description)
89+
.note(note)
90+
.emit();
9991
}
10092
}
10193
}
@@ -203,8 +195,6 @@ enum UnsafeOpKind {
203195
#[allow(dead_code)] // FIXME
204196
CastOfPointerToInt,
205197
#[allow(dead_code)] // FIXME
206-
BorrowOfPackedField,
207-
#[allow(dead_code)] // FIXME
208198
UseOfMutableStatic,
209199
#[allow(dead_code)] // FIXME
210200
UseOfExternStatic,
@@ -244,11 +234,6 @@ impl UnsafeOpKind {
244234
CastOfPointerToInt => {
245235
("cast of pointer to int", "casting pointers to integers in constants")
246236
}
247-
BorrowOfPackedField => (
248-
"borrow of packed field",
249-
"fields of packed structs might be misaligned: dereferencing a misaligned pointer \
250-
or even just creating a misaligned reference is undefined behavior",
251-
),
252237
UseOfMutableStatic => (
253238
"use of mutable static",
254239
"mutable statics can be mutated by multiple threads: aliasing violations or data \

0 commit comments

Comments
 (0)