Skip to content

Commit

Permalink
Auto merge of #85421 - Smittyvb:rm_pushpop_unsafe, r=matthewjasper
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Jun 18, 2021
2 parents 1989b9a + 45c5554 commit 312b894
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 54 deletions.
2 changes: 0 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/thir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ pub struct Adt<'tcx> {
pub enum BlockSafety {
Safe,
ExplicitUnsafe(hir::HirId),
PushUnsafe,
PopUnsafe,
}

#[derive(Debug, HashStable)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir/src/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
22 changes: 4 additions & 18 deletions compiler/rustc_mir_build/src/build/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
}

Expand All @@ -217,29 +215,17 @@ 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
if self.tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, hir_id).0
!= 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 {
Expand Down
11 changes: 3 additions & 8 deletions compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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![],
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_mir_build/src/thir/cx/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand Down
19 changes: 5 additions & 14 deletions compiler/rustc_typeck/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 }
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/tools/clippy/clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
_ => {},
Expand Down

0 comments on commit 312b894

Please sign in to comment.