Remove some last remants of {push,pop}_unsafe!

These macros have already been removed, but there was still some code
handling these macros. That code is now removed.
This commit is contained in:
Smitty 2021-05-17 17:19:48 -04:00
parent 289ada5ed4
commit 45c55540a8
10 changed files with 13 additions and 54 deletions

View File

@ -1205,8 +1205,6 @@ pub struct ExprField<'hir> {
pub enum BlockCheckMode {
DefaultBlock,
UnsafeBlock(UnsafeSource),
PushUnsafeBlock(UnsafeSource),
PopUnsafeBlock(UnsafeSource),
}
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]

View File

@ -1070,8 +1070,6 @@ impl<'a> State<'a> {
) {
match blk.rules {
hir::BlockCheckMode::UnsafeBlock(..) => self.word_space("unsafe"),
hir::BlockCheckMode::PushUnsafeBlock(..) => self.word_space("push_unsafe"),
hir::BlockCheckMode::PopUnsafeBlock(..) => self.word_space("pop_unsafe"),
hir::BlockCheckMode::DefaultBlock => (),
}
self.maybe_print_comment(blk.span.lo());

View File

@ -494,8 +494,6 @@ impl<'tcx> Body<'tcx> {
#[derive(Copy, Clone, PartialEq, Eq, Debug, TyEncodable, TyDecodable, HashStable)]
pub enum Safety {
Safe,
/// Unsafe because of a PushUnsafeBlock
BuiltinUnsafe,
/// Unsafe because of an unsafe fn
FnUnsafe,
/// Unsafe because of an `unsafe` block

View File

@ -101,8 +101,6 @@ pub struct Block {
pub enum BlockSafety {
Safe,
ExplicitUnsafe(hir::HirId),
PushUnsafe,
PopUnsafe,
}
#[derive(Debug, HashStable)]

View File

@ -321,7 +321,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
}
false
}
Safety::BuiltinUnsafe => true,
Safety::ExplicitUnsafe(hir_id) => {
// mark unsafe block as used if there are any unsafe operations inside
if !violations.is_empty() {

View File

@ -74,8 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
// First we build all the statements in the block.
let mut let_scope_stack = Vec::with_capacity(8);
let outer_source_scope = this.source_scope;
let outer_push_unsafe_count = this.push_unsafe_count;
let outer_unpushed_unsafe = this.unpushed_unsafe;
let outer_in_scope_unsafe = this.in_scope_unsafe;
this.update_source_scope_for_safety_mode(span, safety_mode);
let source_info = this.source_info(span);
@ -206,8 +205,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
// Restore the original source scope.
this.source_scope = outer_source_scope;
this.push_unsafe_count = outer_push_unsafe_count;
this.unpushed_unsafe = outer_unpushed_unsafe;
this.in_scope_unsafe = outer_in_scope_unsafe;
block.unit()
}
@ -217,8 +215,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let new_unsafety = match safety_mode {
BlockSafety::Safe => None,
BlockSafety::ExplicitUnsafe(hir_id) => {
assert_eq!(self.push_unsafe_count, 0);
match self.unpushed_unsafe {
match self.in_scope_unsafe {
Safety::Safe => {}
// no longer treat `unsafe fn`s as `unsafe` contexts (see RFC #2585)
Safety::FnUnsafe
@ -226,20 +223,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
!= Level::Allow => {}
_ => return,
}
self.unpushed_unsafe = Safety::ExplicitUnsafe(hir_id);
self.in_scope_unsafe = Safety::ExplicitUnsafe(hir_id);
Some(Safety::ExplicitUnsafe(hir_id))
}
BlockSafety::PushUnsafe => {
self.push_unsafe_count += 1;
Some(Safety::BuiltinUnsafe)
}
BlockSafety::PopUnsafe => {
self.push_unsafe_count = self
.push_unsafe_count
.checked_sub(1)
.unwrap_or_else(|| span_bug!(span, "unsafe count underflow"));
if self.push_unsafe_count == 0 { Some(self.unpushed_unsafe) } else { None }
}
};
if let Some(unsafety) = new_unsafety {

View File

@ -367,12 +367,8 @@ struct Builder<'a, 'tcx> {
/// `{ STMTS; EXPR1 } + EXPR2`.
block_context: BlockContext,
/// The current unsafe block in scope, even if it is hidden by
/// a `PushUnsafeBlock`.
unpushed_unsafe: Safety,
/// The number of `push_unsafe_block` levels in scope.
push_unsafe_count: usize,
/// The current unsafe block in scope
in_scope_unsafe: Safety,
/// The vector of all scopes that we have created thus far;
/// we track this for debuginfo later.
@ -877,8 +873,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
source_scopes: IndexVec::new(),
source_scope: OUTERMOST_SOURCE_SCOPE,
guard_context: vec![],
push_unsafe_count: 0,
unpushed_unsafe: safety,
in_scope_unsafe: safety,
local_decls: IndexVec::from_elem_n(LocalDecl::new(return_ty, return_span), 1),
canonical_user_type_annotations: IndexVec::new(),
upvar_mutbls: vec![],

View File

@ -27,8 +27,6 @@ impl<'tcx> Cx<'tcx> {
safety_mode: match block.rules {
hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe,
hir::BlockCheckMode::UnsafeBlock(..) => BlockSafety::ExplicitUnsafe(block.hir_id),
hir::BlockCheckMode::PushUnsafeBlock(..) => BlockSafety::PushUnsafe,
hir::BlockCheckMode::PopUnsafeBlock(..) => BlockSafety::PopUnsafe,
},
}
}

View File

@ -174,13 +174,12 @@ impl Needs {
pub struct UnsafetyState {
pub def: hir::HirId,
pub unsafety: hir::Unsafety,
pub unsafe_push_count: u32,
from_fn: bool,
}
impl UnsafetyState {
pub fn function(unsafety: hir::Unsafety, def: hir::HirId) -> UnsafetyState {
UnsafetyState { def, unsafety, unsafe_push_count: 0, from_fn: true }
UnsafetyState { def, unsafety, from_fn: true }
}
pub fn recurse(self, blk: &hir::Block<'_>) -> UnsafetyState {
@ -193,19 +192,11 @@ impl UnsafetyState {
hir::Unsafety::Unsafe if self.from_fn => self,
unsafety => {
let (unsafety, def, count) = match blk.rules {
BlockCheckMode::PushUnsafeBlock(..) => {
(unsafety, blk.hir_id, self.unsafe_push_count.checked_add(1).unwrap())
}
BlockCheckMode::PopUnsafeBlock(..) => {
(unsafety, blk.hir_id, self.unsafe_push_count.checked_sub(1).unwrap())
}
BlockCheckMode::UnsafeBlock(..) => {
(hir::Unsafety::Unsafe, blk.hir_id, self.unsafe_push_count)
}
BlockCheckMode::DefaultBlock => (unsafety, self.def, self.unsafe_push_count),
let (unsafety, def) = match blk.rules {
BlockCheckMode::UnsafeBlock(..) => (hir::Unsafety::Unsafe, blk.hir_id),
BlockCheckMode::DefaultBlock => (unsafety, self.def),
};
UnsafetyState { def, unsafety, unsafe_push_count: count, from_fn: false }
UnsafetyState { def, unsafety, from_fn: false }
}
}
}

View File

@ -411,9 +411,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
if let ExprKind::Block(block, _) = expr.kind {
match block.rules {
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided)
| BlockCheckMode::PushUnsafeBlock(UnsafeSource::UserProvided)
| BlockCheckMode::PopUnsafeBlock(UnsafeSource::UserProvided) => {
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => {
self.has_unsafe = true;
},
_ => {},