Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,19 +611,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
typeck_results.rvalue_scopes = rvalue_scopes;
}

/// Unify the inference variables corresponding to coroutine witnesses, and save all the
/// predicates that were stalled on those inference variables.
///
/// This process allows to conservatively save all predicates that do depend on the coroutine
/// interior types, for later processing by `check_coroutine_obligations`.
///
/// We must not attempt to select obligations after this method has run, or risk query cycle
/// ICE.
/// Drain all obligations that are stalled on coroutines defined in this body.
#[instrument(level = "debug", skip(self))]
pub(crate) fn resolve_coroutine_interiors(&self) {
// Try selecting all obligations that are not blocked on inference variables.
// Once we start unifying coroutine witnesses, trying to select obligations on them will
// trigger query cycle ICEs, as doing so requires MIR.
pub(crate) fn drain_stalled_coroutine_obligations(&self) {
// Make as much inference progress as possible before
// draining the stalled coroutine obligations as this may
// change obligations from being stalled on infer vars to
// being stalled on a coroutine.
self.select_obligations_where_possible(|_| {});

let ty::TypingMode::Analysis { defining_opaque_types_and_generators } = self.typing_mode()
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_hir_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,15 @@ fn typeck_with_inspect<'tcx>(

debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations());

// This must be the last thing before `report_ambiguity_errors`.
fcx.resolve_coroutine_interiors();

debug!(pending_obligations = ?fcx.fulfillment_cx.borrow().pending_obligations());

// We need to handle opaque types before emitting ambiguity errors as applying
// defining uses may guide type inference.
if fcx.next_trait_solver() {
fcx.handle_opaque_type_uses_next();
}

fcx.select_obligations_where_possible(|_| {});
// This must be the last thing before `report_ambiguity_errors` below except `select_obligations_where_possible`.
// So don't put anything after this.
fcx.drain_stalled_coroutine_obligations();
if fcx.infcx.tainted_by_errors().is_none() {
fcx.report_ambiguity_errors();
}
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/coroutine/handle_opaques_before_coroutines.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// test for https://github.com/rust-lang/trait-system-refactor-initiative/issues/239
//@edition: 2024
//@ check-pass
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

fn foo<'a>() -> impl Send {
if false {
foo();
}
async {}
}

fn main() {}
Loading