@@ -34,7 +34,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
34
34
use rustc_middle:: infer:: unify_key:: { ConstVidKey , EffectVidKey } ;
35
35
use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
36
36
use rustc_middle:: mir:: ConstraintCategory ;
37
- use rustc_middle:: traits:: { select, DefiningAnchor } ;
37
+ use rustc_middle:: traits:: select;
38
38
use rustc_middle:: ty:: error:: { ExpectedFound , TypeError } ;
39
39
use rustc_middle:: ty:: fold:: BoundVarReplacerDelegate ;
40
40
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
@@ -234,17 +234,8 @@ impl<'tcx> InferCtxtInner<'tcx> {
234
234
pub struct InferCtxt < ' tcx > {
235
235
pub tcx : TyCtxt < ' tcx > ,
236
236
237
- /// The `DefId` of the item in whose context we are performing inference or typeck.
238
- /// It is used to check whether an opaque type use is a defining use.
239
- ///
240
- /// If it is `DefiningAnchor::Bubble`, we can't resolve opaque types here and need to bubble up
241
- /// the obligation. This frequently happens for
242
- /// short lived InferCtxt within queries. The opaque type obligations are forwarded
243
- /// to the outside until the end up in an `InferCtxt` for typeck or borrowck.
244
- ///
245
- /// Its default value is `DefiningAnchor::Error`, this way it is easier to catch errors that
246
- /// might come up during inference or typeck.
247
- pub defining_use_anchor : DefiningAnchor ,
237
+ /// The `DefIds` of the opaque types that may have their hidden types constrained.
238
+ pub defining_opaque_types : & ' tcx ty:: List < LocalDefId > ,
248
239
249
240
/// Whether this inference context should care about region obligations in
250
241
/// the root universe. Most notably, this is used during hir typeck as region
@@ -391,6 +382,10 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
391
382
fn probe_ct_var ( & self , vid : ConstVid ) -> Option < ty:: Const < ' tcx > > {
392
383
self . probe_const_var ( vid) . ok ( )
393
384
}
385
+
386
+ fn defining_opaque_types ( & self ) -> & ' tcx ty:: List < LocalDefId > {
387
+ self . defining_opaque_types
388
+ }
394
389
}
395
390
396
391
/// See the `error_reporting` module for more details.
@@ -605,7 +600,7 @@ impl fmt::Display for FixupError {
605
600
/// Used to configure inference contexts before their creation.
606
601
pub struct InferCtxtBuilder < ' tcx > {
607
602
tcx : TyCtxt < ' tcx > ,
608
- defining_use_anchor : DefiningAnchor ,
603
+ defining_opaque_types : & ' tcx ty :: List < LocalDefId > ,
609
604
considering_regions : bool ,
610
605
skip_leak_check : bool ,
611
606
/// Whether we are in coherence mode.
@@ -620,7 +615,7 @@ impl<'tcx> TyCtxt<'tcx> {
620
615
fn infer_ctxt ( self ) -> InferCtxtBuilder < ' tcx > {
621
616
InferCtxtBuilder {
622
617
tcx : self ,
623
- defining_use_anchor : DefiningAnchor :: Error ,
618
+ defining_opaque_types : ty :: List :: empty ( ) ,
624
619
considering_regions : true ,
625
620
skip_leak_check : false ,
626
621
intercrate : false ,
@@ -636,8 +631,16 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
636
631
/// It is only meant to be called in two places, for typeck
637
632
/// (via `Inherited::build`) and for the inference context used
638
633
/// in mir borrowck.
639
- pub fn with_opaque_type_inference ( mut self , defining_use_anchor : DefiningAnchor ) -> Self {
640
- self . defining_use_anchor = defining_use_anchor;
634
+ pub fn with_opaque_type_inference ( mut self , defining_anchor : LocalDefId ) -> Self {
635
+ self . defining_opaque_types = self . tcx . opaque_types_defined_by ( defining_anchor) ;
636
+ self
637
+ }
638
+
639
+ pub fn with_defining_opaque_types (
640
+ mut self ,
641
+ defining_opaque_types : & ' tcx ty:: List < LocalDefId > ,
642
+ ) -> Self {
643
+ self . defining_opaque_types = defining_opaque_types;
641
644
self
642
645
}
643
646
@@ -669,30 +672,30 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
669
672
/// the bound values in `C` to their instantiated values in `V`
670
673
/// (in other words, `S(C) = V`).
671
674
pub fn build_with_canonical < T > (
672
- & mut self ,
675
+ self ,
673
676
span : Span ,
674
677
canonical : & Canonical < ' tcx , T > ,
675
678
) -> ( InferCtxt < ' tcx > , T , CanonicalVarValues < ' tcx > )
676
679
where
677
680
T : TypeFoldable < TyCtxt < ' tcx > > ,
678
681
{
679
- let infcx = self . build ( ) ;
682
+ let infcx = self . with_defining_opaque_types ( canonical . defining_opaque_types ) . build ( ) ;
680
683
let ( value, args) = infcx. instantiate_canonical_with_fresh_inference_vars ( span, canonical) ;
681
684
( infcx, value, args)
682
685
}
683
686
684
687
pub fn build ( & mut self ) -> InferCtxt < ' tcx > {
685
688
let InferCtxtBuilder {
686
689
tcx,
687
- defining_use_anchor ,
690
+ defining_opaque_types ,
688
691
considering_regions,
689
692
skip_leak_check,
690
693
intercrate,
691
694
next_trait_solver,
692
695
} = * self ;
693
696
InferCtxt {
694
697
tcx,
695
- defining_use_anchor ,
698
+ defining_opaque_types ,
696
699
considering_regions,
697
700
skip_leak_check,
698
701
inner : RefCell :: new ( InferCtxtInner :: new ( ) ) ,
@@ -1208,13 +1211,11 @@ impl<'tcx> InferCtxt<'tcx> {
1208
1211
1209
1212
#[ instrument( level = "debug" , skip( self ) , ret) ]
1210
1213
pub fn take_opaque_types ( & self ) -> opaque_types:: OpaqueTypeMap < ' tcx > {
1211
- debug_assert_ne ! ( self . defining_use_anchor, DefiningAnchor :: Error ) ;
1212
1214
std:: mem:: take ( & mut self . inner . borrow_mut ( ) . opaque_type_storage . opaque_types )
1213
1215
}
1214
1216
1215
1217
#[ instrument( level = "debug" , skip( self ) , ret) ]
1216
1218
pub fn clone_opaque_types ( & self ) -> opaque_types:: OpaqueTypeMap < ' tcx > {
1217
- debug_assert_ne ! ( self . defining_use_anchor, DefiningAnchor :: Error ) ;
1218
1219
self . inner . borrow ( ) . opaque_type_storage . opaque_types . clone ( )
1219
1220
}
1220
1221
0 commit comments