Skip to content

Commit 1d400d1

Browse files
Take ocx by move for pending obligations
1 parent 4fc00ec commit 1d400d1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

compiler/rustc_hir_analysis/src/autoderef.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
189189
return None;
190190
}
191191

192-
Some((normalized_ty, ocx.pending_obligations()))
192+
Some((normalized_ty, ocx.into_pending_obligations()))
193193
}
194194

195195
/// Returns the final type we ended up with, which may be an inference

compiler/rustc_hir_typeck/src/coercion.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
165165
let ocx = ObligationCtxt::new(self);
166166
ocx.register_obligations(obligations);
167167
if ocx.select_where_possible().is_empty() {
168-
Ok(InferOk { value, obligations: ocx.pending_obligations() })
168+
Ok(InferOk { value, obligations: ocx.into_pending_obligations() })
169169
} else {
170170
Err(TypeError::Mismatch)
171171
}
@@ -633,7 +633,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
633633
if !ocx.select_where_possible().is_empty() {
634634
return Err(TypeError::Mismatch);
635635
}
636-
coercion.obligations.extend(ocx.pending_obligations());
636+
coercion.obligations.extend(ocx.into_pending_obligations());
637637
continue;
638638
}
639639
_ => {

compiler/rustc_trait_selection/src/traits/engine.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,15 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
195195
self.engine.borrow_mut().select_all_or_error(self.infcx)
196196
}
197197

198+
/// Returns the not-yet-processed and stalled obligations from the
199+
/// `ObligationCtxt`.
200+
///
201+
/// Takes ownership of the context as doing operations such as
202+
/// [`ObligationCtxt::eq`] afterwards will result in other obligations
203+
/// getting ignored. You can make a new `ObligationCtxt` if this
204+
/// needs to be done in a loop, for example.
198205
#[must_use]
199-
pub fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>> {
206+
pub fn into_pending_obligations(self) -> Vec<PredicateObligation<'tcx>> {
200207
self.engine.borrow().pending_obligations()
201208
}
202209

0 commit comments

Comments
 (0)