Auto merge of #85421 - Smittyvb:rm_pushpop_unsafe, r=matthewjasper

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:
bors 2021-06-18 14:17:53 +00:00
commit 312b894cc1
10 changed files with 13 additions and 54 deletions

View file

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

View file

@ -1070,8 +1070,6 @@ impl<'a> State<'a> {
) { ) {
match blk.rules { match blk.rules {
hir::BlockCheckMode::UnsafeBlock(..) => self.word_space("unsafe"), 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 => (), hir::BlockCheckMode::DefaultBlock => (),
} }
self.maybe_print_comment(blk.span.lo()); 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)] #[derive(Copy, Clone, PartialEq, Eq, Debug, TyEncodable, TyDecodable, HashStable)]
pub enum Safety { pub enum Safety {
Safe, Safe,
/// Unsafe because of a PushUnsafeBlock
BuiltinUnsafe,
/// Unsafe because of an unsafe fn /// Unsafe because of an unsafe fn
FnUnsafe, FnUnsafe,
/// Unsafe because of an `unsafe` block /// Unsafe because of an `unsafe` block

View file

@ -115,8 +115,6 @@ pub struct Adt<'tcx> {
pub enum BlockSafety { pub enum BlockSafety {
Safe, Safe,
ExplicitUnsafe(hir::HirId), ExplicitUnsafe(hir::HirId),
PushUnsafe,
PopUnsafe,
} }
#[derive(Debug, HashStable)] #[derive(Debug, HashStable)]

View file

@ -321,7 +321,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
} }
false false
} }
Safety::BuiltinUnsafe => true,
Safety::ExplicitUnsafe(hir_id) => { Safety::ExplicitUnsafe(hir_id) => {
// mark unsafe block as used if there are any unsafe operations inside // mark unsafe block as used if there are any unsafe operations inside
if !violations.is_empty() { 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. // First we build all the statements in the block.
let mut let_scope_stack = Vec::with_capacity(8); let mut let_scope_stack = Vec::with_capacity(8);
let outer_source_scope = this.source_scope; let outer_source_scope = this.source_scope;
let outer_push_unsafe_count = this.push_unsafe_count; let outer_in_scope_unsafe = this.in_scope_unsafe;
let outer_unpushed_unsafe = this.unpushed_unsafe;
this.update_source_scope_for_safety_mode(span, safety_mode); this.update_source_scope_for_safety_mode(span, safety_mode);
let source_info = this.source_info(span); let source_info = this.source_info(span);
@ -206,8 +205,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
} }
// Restore the original source scope. // Restore the original source scope.
this.source_scope = outer_source_scope; this.source_scope = outer_source_scope;
this.push_unsafe_count = outer_push_unsafe_count; this.in_scope_unsafe = outer_in_scope_unsafe;
this.unpushed_unsafe = outer_unpushed_unsafe;
block.unit() block.unit()
} }
@ -217,8 +215,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let new_unsafety = match safety_mode { let new_unsafety = match safety_mode {
BlockSafety::Safe => None, BlockSafety::Safe => None,
BlockSafety::ExplicitUnsafe(hir_id) => { BlockSafety::ExplicitUnsafe(hir_id) => {
assert_eq!(self.push_unsafe_count, 0); match self.in_scope_unsafe {
match self.unpushed_unsafe {
Safety::Safe => {} Safety::Safe => {}
// no longer treat `unsafe fn`s as `unsafe` contexts (see RFC #2585) // no longer treat `unsafe fn`s as `unsafe` contexts (see RFC #2585)
Safety::FnUnsafe Safety::FnUnsafe
@ -226,20 +223,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
!= Level::Allow => {} != Level::Allow => {}
_ => return, _ => return,
} }
self.unpushed_unsafe = Safety::ExplicitUnsafe(hir_id); self.in_scope_unsafe = Safety::ExplicitUnsafe(hir_id);
Some(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 { if let Some(unsafety) = new_unsafety {

View file

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

View file

@ -27,8 +27,6 @@ impl<'tcx> Cx<'tcx> {
safety_mode: match block.rules { safety_mode: match block.rules {
hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe, hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe,
hir::BlockCheckMode::UnsafeBlock(..) => BlockSafety::ExplicitUnsafe(block.hir_id), 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 struct UnsafetyState {
pub def: hir::HirId, pub def: hir::HirId,
pub unsafety: hir::Unsafety, pub unsafety: hir::Unsafety,
pub unsafe_push_count: u32,
from_fn: bool, from_fn: bool,
} }
impl UnsafetyState { impl UnsafetyState {
pub fn function(unsafety: hir::Unsafety, def: hir::HirId) -> 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 { pub fn recurse(self, blk: &hir::Block<'_>) -> UnsafetyState {
@ -193,19 +192,11 @@ impl UnsafetyState {
hir::Unsafety::Unsafe if self.from_fn => self, hir::Unsafety::Unsafe if self.from_fn => self,
unsafety => { unsafety => {
let (unsafety, def, count) = match blk.rules { let (unsafety, def) = match blk.rules {
BlockCheckMode::PushUnsafeBlock(..) => { BlockCheckMode::UnsafeBlock(..) => (hir::Unsafety::Unsafe, blk.hir_id),
(unsafety, blk.hir_id, self.unsafe_push_count.checked_add(1).unwrap()) BlockCheckMode::DefaultBlock => (unsafety, self.def),
}
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),
}; };
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 { if let ExprKind::Block(block, _) = expr.kind {
match block.rules { match block.rules {
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => {
| BlockCheckMode::PushUnsafeBlock(UnsafeSource::UserProvided)
| BlockCheckMode::PopUnsafeBlock(UnsafeSource::UserProvided) => {
self.has_unsafe = true; self.has_unsafe = true;
}, },
_ => {}, _ => {},