Check for use of mutable/extern statics in THIR unsafeck
This commit is contained in:
parent
6b327aaa08
commit
0e1afc4501
26 changed files with 238 additions and 28 deletions
|
@ -169,14 +169,20 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => {
|
||||
self.requires_unsafe(expr.span, UseOfInlineAssembly);
|
||||
}
|
||||
ExprKind::Deref { arg } => {
|
||||
if self.thir[arg].ty.is_unsafe_ptr() {
|
||||
if let ExprKind::StaticRef { def_id, .. } = self.thir[arg].kind {
|
||||
if self.tcx.is_mutable_static(def_id) {
|
||||
self.requires_unsafe(expr.span, UseOfMutableStatic);
|
||||
} else if self.tcx.is_foreign_item(def_id) {
|
||||
self.requires_unsafe(expr.span, UseOfExternStatic);
|
||||
}
|
||||
} else if self.thir[arg].ty.is_unsafe_ptr() {
|
||||
self.requires_unsafe(expr.span, DerefOfRawPointer);
|
||||
}
|
||||
}
|
||||
ExprKind::InlineAsm { .. } | ExprKind::LlvmInlineAsm { .. } => {
|
||||
self.requires_unsafe(expr.span, UseOfInlineAssembly);
|
||||
}
|
||||
ExprKind::Adt {
|
||||
adt_def,
|
||||
variant_index: _,
|
||||
|
@ -242,9 +248,7 @@ enum UnsafeOpKind {
|
|||
UseOfInlineAssembly,
|
||||
InitializingTypeWith,
|
||||
CastOfPointerToInt,
|
||||
#[allow(dead_code)] // FIXME
|
||||
UseOfMutableStatic,
|
||||
#[allow(dead_code)] // FIXME
|
||||
UseOfExternStatic,
|
||||
DerefOfRawPointer,
|
||||
#[allow(dead_code)] // FIXME
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue