Skip to content

Commit e5602cb

Browse files
Add and use ObligationCtxt::new_in_snapshot
1 parent fee9e9b commit e5602cb

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

compiler/rustc_trait_selection/src/traits/engine.rs

+13
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_span::Span;
1717

1818
pub trait TraitEngineExt<'tcx> {
1919
fn new(tcx: TyCtxt<'tcx>) -> Box<Self>;
20+
fn new_in_snapshot(tcx: TyCtxt<'tcx>) -> Box<Self>;
2021
}
2122

2223
impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
@@ -27,6 +28,14 @@ impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
2728
Box::new(FulfillmentContext::new())
2829
}
2930
}
31+
32+
fn new_in_snapshot(tcx: TyCtxt<'tcx>) -> Box<Self> {
33+
if tcx.sess.opts.unstable_opts.chalk {
34+
Box::new(ChalkFulfillmentContext::new())
35+
} else {
36+
Box::new(FulfillmentContext::new_in_snapshot())
37+
}
38+
}
3039
}
3140

3241
/// Used if you want to have pleasant experience when dealing
@@ -41,6 +50,10 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
4150
Self { infcx, engine: RefCell::new(<dyn TraitEngine<'_>>::new(infcx.tcx)) }
4251
}
4352

53+
pub fn new_in_snapshot(infcx: &'a InferCtxt<'a, 'tcx>) -> Self {
54+
Self { infcx, engine: RefCell::new(<dyn TraitEngine<'_>>::new_in_snapshot(infcx.tcx)) }
55+
}
56+
4457
pub fn register_obligation(&self, obligation: PredicateObligation<'tcx>) {
4558
self.engine.borrow_mut().register_predicate_obligation(self.infcx, obligation);
4659
}

compiler/rustc_typeck/src/check/inherited.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ use rustc_hir::def_id::LocalDefId;
77
use rustc_hir::HirIdMap;
88
use rustc_infer::infer;
99
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
10-
use rustc_infer::traits::TraitEngineExt as _;
1110
use rustc_middle::ty::fold::TypeFoldable;
1211
use rustc_middle::ty::visit::TypeVisitable;
1312
use rustc_middle::ty::{self, Ty, TyCtxt};
1413
use rustc_span::def_id::LocalDefIdMap;
1514
use rustc_span::{self, Span};
1615
use rustc_trait_selection::infer::InferCtxtExt as _;
1716
use rustc_trait_selection::traits::{
18-
self, FulfillmentContext, ObligationCause, TraitEngine, TraitEngineExt as _,
17+
self, ObligationCause, ObligationCtxt, TraitEngine, TraitEngineExt as _,
1918
};
2019

2120
use std::cell::RefCell;
@@ -94,17 +93,14 @@ impl<'tcx> Inherited<'_, 'tcx> {
9493
return fn_sig;
9594
}
9695
infcx.probe(|_| {
97-
let traits::Normalized { value: normalized_fn_sig, obligations } =
98-
traits::normalize(
99-
&mut traits::SelectionContext::new(infcx),
100-
// FIXME(compiler-errors): This is probably not the right param-env...
101-
infcx.tcx.param_env(def_id),
102-
ObligationCause::dummy(),
103-
fn_sig,
104-
);
105-
let mut fulfillment_ctxt = FulfillmentContext::new_in_snapshot();
106-
fulfillment_ctxt.register_predicate_obligations(infcx, obligations);
107-
if fulfillment_ctxt.select_all_or_error(infcx).is_empty() {
96+
let ocx = ObligationCtxt::new_in_snapshot(infcx);
97+
let normalized_fn_sig = ocx.normalize(
98+
ObligationCause::dummy(),
99+
// FIXME(compiler-errors): This is probably not the right param-env...
100+
infcx.tcx.param_env(def_id),
101+
fn_sig,
102+
);
103+
if ocx.select_all_or_error().is_empty() {
108104
let normalized_fn_sig =
109105
infcx.resolve_vars_if_possible(normalized_fn_sig);
110106
if !normalized_fn_sig.needs_infer() {

0 commit comments

Comments
 (0)