@@ -39,6 +39,7 @@ use rustc_span::Span;
39
39
40
40
use std:: cell:: { Cell , RefCell } ;
41
41
use std:: fmt;
42
+ use std:: ops:: Drop ;
42
43
43
44
use self :: combine:: CombineFields ;
44
45
use self :: error_reporting:: TypeErrCtxt ;
@@ -342,6 +343,11 @@ pub struct InferCtxt<'tcx> {
342
343
/// there is no type that the user could *actually name* that
343
344
/// would satisfy it. This avoids crippling inference, basically.
344
345
pub intercrate : bool ,
346
+
347
+ /// Flag that is set when we enter canonicalization. Used for debugging to ensure
348
+ /// that we only collect region information for `BorrowckInferCtxt::reg_var_to_origin`
349
+ /// inside non-canonicalization contexts.
350
+ inside_canonicalization_ctxt : Cell < bool > ,
345
351
}
346
352
347
353
/// See the `error_reporting` module for more details.
@@ -633,6 +639,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
633
639
skip_leak_check : Cell :: new ( false ) ,
634
640
universe : Cell :: new ( ty:: UniverseIndex :: ROOT ) ,
635
641
intercrate,
642
+ inside_canonicalization_ctxt : Cell :: new ( false ) ,
636
643
}
637
644
}
638
645
}
@@ -1728,6 +1735,31 @@ impl<'tcx> InferCtxt<'tcx> {
1728
1735
}
1729
1736
}
1730
1737
}
1738
+
1739
+ pub fn inside_canonicalization_ctxt ( & self ) -> bool {
1740
+ self . inside_canonicalization_ctxt . get ( )
1741
+ }
1742
+
1743
+ pub fn set_canonicalization_ctxt ( & self ) -> CanonicalizationCtxtGuard < ' _ , ' tcx > {
1744
+ let prev_ctxt = self . inside_canonicalization_ctxt ( ) ;
1745
+ self . inside_canonicalization_ctxt . set ( true ) ;
1746
+ CanonicalizationCtxtGuard { prev_ctxt, infcx : self }
1747
+ }
1748
+
1749
+ fn set_canonicalization_ctxt_to ( & self , ctxt : bool ) {
1750
+ self . inside_canonicalization_ctxt . set ( ctxt) ;
1751
+ }
1752
+ }
1753
+
1754
+ pub struct CanonicalizationCtxtGuard < ' cx , ' tcx > {
1755
+ prev_ctxt : bool ,
1756
+ infcx : & ' cx InferCtxt < ' tcx > ,
1757
+ }
1758
+
1759
+ impl < ' cx , ' tcx > Drop for CanonicalizationCtxtGuard < ' cx , ' tcx > {
1760
+ fn drop ( & mut self ) {
1761
+ self . infcx . set_canonicalization_ctxt_to ( self . prev_ctxt )
1762
+ }
1731
1763
}
1732
1764
1733
1765
impl < ' tcx > TypeErrCtxt < ' _ , ' tcx > {
0 commit comments