Skip to content

Commit 9a826cc

Browse files
No pending_obligations in autoderef
1 parent 5f06bbe commit 9a826cc

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

compiler/rustc_infer/src/traits/engine.rs

-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ pub trait TraitEngine<'tcx>: 'tcx {
4141

4242
fn select_where_possible(&mut self, infcx: &InferCtxt<'tcx>) -> Vec<FulfillmentError<'tcx>>;
4343

44-
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>>;
45-
4644
fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships>;
4745
}
4846

compiler/rustc_trait_selection/src/autoderef.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use crate::traits::query::evaluate_obligation::InferCtxtExt;
33
use crate::traits::NormalizeExt;
44
use crate::traits::{self, TraitEngine, TraitEngineExt};
55
use rustc_hir as hir;
6-
use rustc_infer::infer::InferCtxt;
6+
use rustc_infer::infer::{InferCtxt, InferOk};
7+
use rustc_infer::traits::TraitEngineExt as _;
78
use rustc_middle::ty::TypeVisitable;
89
use rustc_middle::ty::{self, Ty, TyCtxt};
910
use rustc_session::Limit;
@@ -138,22 +139,24 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
138139
return None;
139140
}
140141

141-
let normalized_ty = self
142+
let InferOk { value: normalized_ty, obligations } = self
142143
.infcx
143144
.at(&cause, self.param_env)
144145
.normalize(tcx.mk_projection(tcx.lang_items().deref_target()?, trait_ref.substs));
145-
let mut fulfillcx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
146-
let normalized_ty =
147-
normalized_ty.into_value_registering_obligations(self.infcx, &mut *fulfillcx);
148-
let errors = fulfillcx.select_where_possible(&self.infcx);
146+
147+
// HACK(compiler-errors): We must *select* here so we *affect* inference...
148+
// This can probably be moved to method_autoderef_steps or something instead.
149+
let mut fulfill_cx = <dyn TraitEngine<'_>>::new_in_snapshot(tcx);
150+
fulfill_cx.register_predicate_obligations(&self.infcx, obligations.clone());
151+
let errors = fulfill_cx.select_where_possible(&self.infcx);
149152
if !errors.is_empty() {
150153
// This shouldn't happen, except for evaluate/fulfill mismatches,
151154
// but that's not a reason for an ICE (`predicate_may_hold` is conservative
152155
// by design).
153156
debug!("overloaded_deref_ty: encountered errors {:?} while fulfilling", errors);
154157
return None;
155158
}
156-
let obligations = fulfillcx.pending_obligations();
159+
157160
debug!("overloaded_deref_ty({:?}) = ({:?}, {:?})", ty, normalized_ty, obligations);
158161
self.state.obligations.extend(obligations);
159162

compiler/rustc_trait_selection/src/traits/chalk_fulfill.rs

-4
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
151151
errors
152152
}
153153

154-
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>> {
155-
self.obligations.iter().cloned().collect()
156-
}
157-
158154
fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships> {
159155
&mut self.relationships
160156
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,6 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentContext<'tcx> {
161161
self.select(selcx)
162162
}
163163

164-
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>> {
165-
self.predicates.map_pending_obligations(|o| o.obligation.clone())
166-
}
167-
168164
fn relationships(&mut self) -> &mut FxHashMap<ty::TyVid, ty::FoundRelationships> {
169165
&mut self.relationships
170166
}

0 commit comments

Comments
 (0)