Skip to content

Commit 0c5fe37

Browse files
committed
remove inside_canonicalization_ctxt flag
we never reach the code checking for this flag while the flag is enabled, so it does not change the behavior of the code.
1 parent 6bb1f79 commit 0c5fe37

File tree

5 files changed

+13
-45
lines changed

5 files changed

+13
-45
lines changed

compiler/rustc_borrowck/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,11 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
498498
let next_region = self.infcx.next_region_var(origin);
499499
let vid = next_region.as_var();
500500

501-
if cfg!(debug_assertions) && !self.inside_canonicalization_ctxt() {
501+
if cfg!(debug_assertions) {
502502
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
503503
let ctxt = get_ctxt_fn();
504504
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
505-
var_to_origin.insert(vid, ctxt);
505+
assert_eq!(var_to_origin.insert(vid, ctxt), None);
506506
}
507507

508508
next_region
@@ -520,11 +520,11 @@ impl<'cx, 'tcx> BorrowckInferCtxt<'cx, 'tcx> {
520520
let next_region = self.infcx.next_nll_region_var(origin);
521521
let vid = next_region.as_var();
522522

523-
if cfg!(debug_assertions) && !self.inside_canonicalization_ctxt() {
523+
if cfg!(debug_assertions) {
524524
debug!("inserting vid {:?} with origin {:?} into var_to_origin", vid, origin);
525525
let ctxt = get_ctxt_fn();
526526
let mut var_to_origin = self.reg_var_to_origin.borrow_mut();
527-
var_to_origin.insert(vid, ctxt);
527+
assert_eq!(var_to_origin.insert(vid, ctxt), None);
528528
}
529529

530530
next_region

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,13 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
131131
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
132132
};
133133

134-
if cfg!(debug_assertions) && !self.type_checker.infcx.inside_canonicalization_ctxt() {
134+
if cfg!(debug_assertions) {
135135
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
136-
var_to_origin.insert(reg.as_var(), RegionCtxt::Placeholder(reg_info));
136+
let new = RegionCtxt::Placeholder(reg_info);
137+
let prev = var_to_origin.insert(reg.as_var(), new);
138+
if let Some(prev) = prev {
139+
assert_eq!(new, prev);
140+
}
137141
}
138142

139143
reg
@@ -146,9 +150,10 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
146150
universe,
147151
);
148152

149-
if cfg!(debug_assertions) && !self.type_checker.infcx.inside_canonicalization_ctxt() {
153+
if cfg!(debug_assertions) {
150154
let mut var_to_origin = self.type_checker.infcx.reg_var_to_origin.borrow_mut();
151-
var_to_origin.insert(reg.as_var(), RegionCtxt::Existential(None));
155+
let prev = var_to_origin.insert(reg.as_var(), RegionCtxt::Existential(None));
156+
assert_eq!(prev, None);
152157
}
153158

154159
reg

compiler/rustc_infer/src/infer/at.rs

-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ use super::*;
3030
use rustc_middle::ty::relate::{Relate, TypeRelation};
3131
use rustc_middle::ty::{Const, ImplSubject};
3232

33-
use std::cell::Cell;
34-
3533
/// Whether we should define opaque types or just treat them opaquely.
3634
///
3735
/// Currently only used to prevent predicate matching from matching anything
@@ -84,7 +82,6 @@ impl<'tcx> InferCtxt<'tcx> {
8482
in_snapshot: self.in_snapshot.clone(),
8583
universe: self.universe.clone(),
8684
intercrate: self.intercrate,
87-
inside_canonicalization_ctxt: Cell::new(self.inside_canonicalization_ctxt()),
8885
}
8986
}
9087
}

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

-2
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,6 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
561561
where
562562
V: TypeFoldable<TyCtxt<'tcx>>,
563563
{
564-
let _inside_canonical_ctxt_guard = infcx.set_canonicalization_ctxt();
565-
566564
let needs_canonical_flags = if canonicalize_region_mode.any() {
567565
TypeFlags::HAS_INFER |
568566
TypeFlags::HAS_FREE_REGIONS | // `HAS_RE_PLACEHOLDER` implies `HAS_FREE_REGIONS`

compiler/rustc_infer/src/infer/mod.rs

-32
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ use rustc_span::Span;
3939

4040
use std::cell::{Cell, RefCell};
4141
use std::fmt;
42-
use std::ops::Drop;
4342

4443
use self::combine::CombineFields;
4544
use self::error_reporting::TypeErrCtxt;
@@ -342,11 +341,6 @@ pub struct InferCtxt<'tcx> {
342341
/// there is no type that the user could *actually name* that
343342
/// would satisfy it. This avoids crippling inference, basically.
344343
pub intercrate: bool,
345-
346-
/// Flag that is set when we enter canonicalization. Used for debugging to ensure
347-
/// that we only collect region information for `BorrowckInferCtxt::reg_var_to_origin`
348-
/// inside non-canonicalization contexts.
349-
inside_canonicalization_ctxt: Cell<bool>,
350344
}
351345

352346
/// See the `error_reporting` module for more details.
@@ -638,7 +632,6 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
638632
skip_leak_check: Cell::new(false),
639633
universe: Cell::new(ty::UniverseIndex::ROOT),
640634
intercrate,
641-
inside_canonicalization_ctxt: Cell::new(false),
642635
}
643636
}
644637
}
@@ -1636,31 +1629,6 @@ impl<'tcx> InferCtxt<'tcx> {
16361629
}
16371630
}
16381631
}
1639-
1640-
pub fn inside_canonicalization_ctxt(&self) -> bool {
1641-
self.inside_canonicalization_ctxt.get()
1642-
}
1643-
1644-
pub fn set_canonicalization_ctxt(&self) -> CanonicalizationCtxtGuard<'_, 'tcx> {
1645-
let prev_ctxt = self.inside_canonicalization_ctxt();
1646-
self.inside_canonicalization_ctxt.set(true);
1647-
CanonicalizationCtxtGuard { prev_ctxt, infcx: self }
1648-
}
1649-
1650-
fn set_canonicalization_ctxt_to(&self, ctxt: bool) {
1651-
self.inside_canonicalization_ctxt.set(ctxt);
1652-
}
1653-
}
1654-
1655-
pub struct CanonicalizationCtxtGuard<'cx, 'tcx> {
1656-
prev_ctxt: bool,
1657-
infcx: &'cx InferCtxt<'tcx>,
1658-
}
1659-
1660-
impl<'cx, 'tcx> Drop for CanonicalizationCtxtGuard<'cx, 'tcx> {
1661-
fn drop(&mut self) {
1662-
self.infcx.set_canonicalization_ctxt_to(self.prev_ctxt)
1663-
}
16641632
}
16651633

16661634
impl<'tcx> TypeErrCtxt<'_, 'tcx> {

0 commit comments

Comments
 (0)