Skip to content

Commit 312b894

Browse files
committed
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.
2 parents 1989b9a + 45c5554 commit 312b894

File tree

10 files changed

+13
-54
lines changed

10 files changed

+13
-54
lines changed

compiler/rustc_hir/src/hir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1205,8 +1205,6 @@ pub struct ExprField<'hir> {
12051205
pub enum BlockCheckMode {
12061206
DefaultBlock,
12071207
UnsafeBlock(UnsafeSource),
1208-
PushUnsafeBlock(UnsafeSource),
1209-
PopUnsafeBlock(UnsafeSource),
12101208
}
12111209

12121210
#[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)]

compiler/rustc_hir_pretty/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1070,8 +1070,6 @@ impl<'a> State<'a> {
10701070
) {
10711071
match blk.rules {
10721072
hir::BlockCheckMode::UnsafeBlock(..) => self.word_space("unsafe"),
1073-
hir::BlockCheckMode::PushUnsafeBlock(..) => self.word_space("push_unsafe"),
1074-
hir::BlockCheckMode::PopUnsafeBlock(..) => self.word_space("pop_unsafe"),
10751073
hir::BlockCheckMode::DefaultBlock => (),
10761074
}
10771075
self.maybe_print_comment(blk.span.lo());

compiler/rustc_middle/src/mir/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,6 @@ impl<'tcx> Body<'tcx> {
494494
#[derive(Copy, Clone, PartialEq, Eq, Debug, TyEncodable, TyDecodable, HashStable)]
495495
pub enum Safety {
496496
Safe,
497-
/// Unsafe because of a PushUnsafeBlock
498-
BuiltinUnsafe,
499497
/// Unsafe because of an unsafe fn
500498
FnUnsafe,
501499
/// Unsafe because of an `unsafe` block

compiler/rustc_middle/src/thir.rs

-2
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ pub struct Adt<'tcx> {
115115
pub enum BlockSafety {
116116
Safe,
117117
ExplicitUnsafe(hir::HirId),
118-
PushUnsafe,
119-
PopUnsafe,
120118
}
121119

122120
#[derive(Debug, HashStable)]

compiler/rustc_mir/src/transform/check_unsafety.rs

-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,6 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
321321
}
322322
false
323323
}
324-
Safety::BuiltinUnsafe => true,
325324
Safety::ExplicitUnsafe(hir_id) => {
326325
// mark unsafe block as used if there are any unsafe operations inside
327326
if !violations.is_empty() {

compiler/rustc_mir_build/src/build/block.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7474
// First we build all the statements in the block.
7575
let mut let_scope_stack = Vec::with_capacity(8);
7676
let outer_source_scope = this.source_scope;
77-
let outer_push_unsafe_count = this.push_unsafe_count;
78-
let outer_unpushed_unsafe = this.unpushed_unsafe;
77+
let outer_in_scope_unsafe = this.in_scope_unsafe;
7978
this.update_source_scope_for_safety_mode(span, safety_mode);
8079

8180
let source_info = this.source_info(span);
@@ -206,8 +205,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
206205
}
207206
// Restore the original source scope.
208207
this.source_scope = outer_source_scope;
209-
this.push_unsafe_count = outer_push_unsafe_count;
210-
this.unpushed_unsafe = outer_unpushed_unsafe;
208+
this.in_scope_unsafe = outer_in_scope_unsafe;
211209
block.unit()
212210
}
213211

@@ -217,29 +215,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
217215
let new_unsafety = match safety_mode {
218216
BlockSafety::Safe => None,
219217
BlockSafety::ExplicitUnsafe(hir_id) => {
220-
assert_eq!(self.push_unsafe_count, 0);
221-
match self.unpushed_unsafe {
218+
match self.in_scope_unsafe {
222219
Safety::Safe => {}
223220
// no longer treat `unsafe fn`s as `unsafe` contexts (see RFC #2585)
224221
Safety::FnUnsafe
225222
if self.tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, hir_id).0
226223
!= Level::Allow => {}
227224
_ => return,
228225
}
229-
self.unpushed_unsafe = Safety::ExplicitUnsafe(hir_id);
226+
self.in_scope_unsafe = Safety::ExplicitUnsafe(hir_id);
230227
Some(Safety::ExplicitUnsafe(hir_id))
231228
}
232-
BlockSafety::PushUnsafe => {
233-
self.push_unsafe_count += 1;
234-
Some(Safety::BuiltinUnsafe)
235-
}
236-
BlockSafety::PopUnsafe => {
237-
self.push_unsafe_count = self
238-
.push_unsafe_count
239-
.checked_sub(1)
240-
.unwrap_or_else(|| span_bug!(span, "unsafe count underflow"));
241-
if self.push_unsafe_count == 0 { Some(self.unpushed_unsafe) } else { None }
242-
}
243229
};
244230

245231
if let Some(unsafety) = new_unsafety {

compiler/rustc_mir_build/src/build/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,8 @@ struct Builder<'a, 'tcx> {
367367
/// `{ STMTS; EXPR1 } + EXPR2`.
368368
block_context: BlockContext,
369369

370-
/// The current unsafe block in scope, even if it is hidden by
371-
/// a `PushUnsafeBlock`.
372-
unpushed_unsafe: Safety,
373-
374-
/// The number of `push_unsafe_block` levels in scope.
375-
push_unsafe_count: usize,
370+
/// The current unsafe block in scope
371+
in_scope_unsafe: Safety,
376372

377373
/// The vector of all scopes that we have created thus far;
378374
/// we track this for debuginfo later.
@@ -877,8 +873,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
877873
source_scopes: IndexVec::new(),
878874
source_scope: OUTERMOST_SOURCE_SCOPE,
879875
guard_context: vec![],
880-
push_unsafe_count: 0,
881-
unpushed_unsafe: safety,
876+
in_scope_unsafe: safety,
882877
local_decls: IndexVec::from_elem_n(LocalDecl::new(return_ty, return_span), 1),
883878
canonical_user_type_annotations: IndexVec::new(),
884879
upvar_mutbls: vec![],

compiler/rustc_mir_build/src/thir/cx/block.rs

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ impl<'tcx> Cx<'tcx> {
2727
safety_mode: match block.rules {
2828
hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe,
2929
hir::BlockCheckMode::UnsafeBlock(..) => BlockSafety::ExplicitUnsafe(block.hir_id),
30-
hir::BlockCheckMode::PushUnsafeBlock(..) => BlockSafety::PushUnsafe,
31-
hir::BlockCheckMode::PopUnsafeBlock(..) => BlockSafety::PopUnsafe,
3230
},
3331
}
3432
}

compiler/rustc_typeck/src/check/mod.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,12 @@ impl Needs {
174174
pub struct UnsafetyState {
175175
pub def: hir::HirId,
176176
pub unsafety: hir::Unsafety,
177-
pub unsafe_push_count: u32,
178177
from_fn: bool,
179178
}
180179

181180
impl UnsafetyState {
182181
pub fn function(unsafety: hir::Unsafety, def: hir::HirId) -> UnsafetyState {
183-
UnsafetyState { def, unsafety, unsafe_push_count: 0, from_fn: true }
182+
UnsafetyState { def, unsafety, from_fn: true }
184183
}
185184

186185
pub fn recurse(self, blk: &hir::Block<'_>) -> UnsafetyState {
@@ -193,19 +192,11 @@ impl UnsafetyState {
193192
hir::Unsafety::Unsafe if self.from_fn => self,
194193

195194
unsafety => {
196-
let (unsafety, def, count) = match blk.rules {
197-
BlockCheckMode::PushUnsafeBlock(..) => {
198-
(unsafety, blk.hir_id, self.unsafe_push_count.checked_add(1).unwrap())
199-
}
200-
BlockCheckMode::PopUnsafeBlock(..) => {
201-
(unsafety, blk.hir_id, self.unsafe_push_count.checked_sub(1).unwrap())
202-
}
203-
BlockCheckMode::UnsafeBlock(..) => {
204-
(hir::Unsafety::Unsafe, blk.hir_id, self.unsafe_push_count)
205-
}
206-
BlockCheckMode::DefaultBlock => (unsafety, self.def, self.unsafe_push_count),
195+
let (unsafety, def) = match blk.rules {
196+
BlockCheckMode::UnsafeBlock(..) => (hir::Unsafety::Unsafe, blk.hir_id),
197+
BlockCheckMode::DefaultBlock => (unsafety, self.def),
207198
};
208-
UnsafetyState { def, unsafety, unsafe_push_count: count, from_fn: false }
199+
UnsafetyState { def, unsafety, from_fn: false }
209200
}
210201
}
211202
}

src/tools/clippy/clippy_lints/src/derive.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,7 @@ impl<'tcx> Visitor<'tcx> for UnsafeVisitor<'_, 'tcx> {
411411

412412
if let ExprKind::Block(block, _) = expr.kind {
413413
match block.rules {
414-
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided)
415-
| BlockCheckMode::PushUnsafeBlock(UnsafeSource::UserProvided)
416-
| BlockCheckMode::PopUnsafeBlock(UnsafeSource::UserProvided) => {
414+
BlockCheckMode::UnsafeBlock(UnsafeSource::UserProvided) => {
417415
self.has_unsafe = true;
418416
},
419417
_ => {},

0 commit comments

Comments
 (0)