Skip to content

Commit 3a014e2

Browse files
committed
use if matches! instead of match for simplicity
1 parent 36ad75b commit 3a014e2

File tree

1 file changed

+18
-19
lines changed
  • compiler/rustc_const_eval/src/check_consts

1 file changed

+18
-19
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -345,32 +345,31 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
345345
/// initializer. The check assumes that all already existing pointers and references point to
346346
/// non-escaping places.
347347
fn place_may_escape(&mut self, place: &Place<'_>) -> bool {
348-
let is_transient = match self.const_kind() {
348+
let is_transient = if matches!(self.const_kind(), hir::ConstContext::ConstFn) {
349349
// In a const fn all borrows are transient or point to the places given via
350350
// references in the arguments (so we already checked them with
351351
// TransientMutBorrow/MutBorrow as appropriate).
352352
// The borrow checker guarantees that no new non-transient borrows are created.
353353
// NOTE: Once we have heap allocations during CTFE we need to figure out
354354
// how to prevent `const fn` to create long-lived allocations that point
355355
// to mutable memory.
356-
hir::ConstContext::ConstFn => true,
357-
_ => {
358-
// For indirect places, we are not creating a new permanent borrow, it's just as
359-
// transient as the already existing one. For reborrowing references this is handled
360-
// at the top of `visit_rvalue`, but for raw pointers we handle it here.
361-
// Pointers/references to `static mut` and cases where the `*` is not the first
362-
// projection also end up here.
363-
// Locals with StorageDead do not live beyond the evaluation and can
364-
// thus safely be borrowed without being able to be leaked to the final
365-
// value of the constant.
366-
// Note: This is only sound if every local that has a `StorageDead` has a
367-
// `StorageDead` in every control flow path leading to a `return` terminator.
368-
// If anything slips through, there's no safety net -- safe code can create
369-
// references to variants of `!Freeze` enums as long as that variant is `Freeze`, so
370-
// interning can't protect us here. (There *is* a safety net for mutable references
371-
// though, interning will ICE if we miss something here.)
372-
place.is_indirect() || self.local_is_transient(place.local)
373-
}
356+
true
357+
} else {
358+
// For indirect places, we are not creating a new permanent borrow, it's just as
359+
// transient as the already existing one. For reborrowing references this is handled
360+
// at the top of `visit_rvalue`, but for raw pointers we handle it here.
361+
// Pointers/references to `static mut` and cases where the `*` is not the first
362+
// projection also end up here.
363+
// Locals with StorageDead do not live beyond the evaluation and can
364+
// thus safely be borrowed without being able to be leaked to the final
365+
// value of the constant.
366+
// Note: This is only sound if every local that has a `StorageDead` has a
367+
// `StorageDead` in every control flow path leading to a `return` terminator.
368+
// If anything slips through, there's no safety net -- safe code can create
369+
// references to variants of `!Freeze` enums as long as that variant is `Freeze`, so
370+
// interning can't protect us here. (There *is* a safety net for mutable references
371+
// though, interning will ICE if we miss something here.)
372+
place.is_indirect() || self.local_is_transient(place.local)
374373
};
375374
// Transient places cannot possibly escape because the place doesn't exist any more at the
376375
// end of evaluation.

0 commit comments

Comments
 (0)