@@ -10,7 +10,6 @@ pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
10
10
11
11
use crate :: traits:: { self , ObligationCause , PredicateObligations , TraitEngine } ;
12
12
13
- use hir:: def_id:: CRATE_DEF_ID ;
14
13
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
15
14
use rustc_data_structures:: sync:: Lrc ;
16
15
use rustc_data_structures:: undo_log:: Rollback ;
@@ -291,7 +290,12 @@ pub struct InferCtxt<'a, 'tcx> {
291
290
292
291
/// The `DefId` of the item in whose context we are performing inference or typeck.
293
292
/// It is used to check whether an opaque type use is a defining use.
294
- pub defining_use_anchor : LocalDefId ,
293
+ ///
294
+ /// If it is `None`, we can't resolve opaque types here and need to bubble up
295
+ /// the obligation. This frequently happens for
296
+ /// short lived InferCtxt within queries. The opaque type obligations are forwarded
297
+ /// to the outside until the end up in an `InferCtxt` for typeck or borrowck.
298
+ pub defining_use_anchor : Option < LocalDefId > ,
295
299
296
300
/// During type-checking/inference of a body, `in_progress_typeck_results`
297
301
/// contains a reference to the typeck results being built up, which are
@@ -547,7 +551,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
547
551
pub struct InferCtxtBuilder < ' tcx > {
548
552
tcx : TyCtxt < ' tcx > ,
549
553
fresh_typeck_results : Option < RefCell < ty:: TypeckResults < ' tcx > > > ,
550
- defining_use_anchor : LocalDefId ,
554
+ defining_use_anchor : Option < LocalDefId > ,
551
555
}
552
556
553
557
pub trait TyCtxtInferExt < ' tcx > {
@@ -556,11 +560,7 @@ pub trait TyCtxtInferExt<'tcx> {
556
560
557
561
impl < ' tcx > TyCtxtInferExt < ' tcx > for TyCtxt < ' tcx > {
558
562
fn infer_ctxt ( self ) -> InferCtxtBuilder < ' tcx > {
559
- InferCtxtBuilder {
560
- tcx : self ,
561
- defining_use_anchor : CRATE_DEF_ID ,
562
- fresh_typeck_results : None ,
563
- }
563
+ InferCtxtBuilder { tcx : self , defining_use_anchor : None , fresh_typeck_results : None }
564
564
}
565
565
}
566
566
@@ -580,7 +580,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
580
580
/// (via `with_fresh_in_progress_typeck_results`) and for the inference context used
581
581
/// in mir borrowck.
582
582
pub fn with_opaque_type_inference ( mut self , defining_use_anchor : LocalDefId ) -> Self {
583
- self . defining_use_anchor = defining_use_anchor;
583
+ self . defining_use_anchor = Some ( defining_use_anchor) ;
584
584
self
585
585
}
586
586
0 commit comments