Skip to content

Commit

Permalink
Take ocx by move for pending obligations
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 3, 2024
1 parent d9eb523 commit 9286151
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
return None;
}

Some((normalized_ty, ocx.pending_obligations()))
Some((normalized_ty, ocx.into_pending_obligations()))
}

/// Returns the final type we ended up with, which may be an inference
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
let ocx = ObligationCtxt::new(self);
ocx.register_obligations(obligations);
if ocx.select_where_possible().is_empty() {
Ok(InferOk { value, obligations: ocx.pending_obligations() })
Ok(InferOk { value, obligations: ocx.into_pending_obligations() })
} else {
Err(TypeError::Mismatch)
}
Expand Down Expand Up @@ -633,7 +633,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
if !ocx.select_where_possible().is_empty() {
return Err(TypeError::Mismatch);
}
coercion.obligations.extend(ocx.pending_obligations());
coercion.obligations.extend(ocx.into_pending_obligations());
continue;
}
_ => {
Expand Down
9 changes: 8 additions & 1 deletion compiler/rustc_trait_selection/src/traits/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,15 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
self.engine.borrow_mut().select_all_or_error(self.infcx)
}

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

Expand Down

0 comments on commit 9286151

Please sign in to comment.