1
Fork 0

LangItem-ify Coroutine trait in solvers

This commit is contained in:
Michael Goulet 2024-06-12 18:15:33 -04:00
parent 921645c737
commit d3812ac95f
5 changed files with 20 additions and 10 deletions

View file

@ -17,7 +17,7 @@ use rustc_middle::ty::NormalizesTo;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{TypeVisitableExt, Upcast};
use rustc_middle::{bug, span_bug};
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
mod anon_const;
mod inherent;
@ -719,13 +719,16 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
let coroutine = args.as_coroutine();
let name = tcx.associated_item(goal.predicate.def_id()).name;
let term = if name == sym::Return {
let lang_items = tcx.lang_items();
let term = if Some(goal.predicate.def_id()) == lang_items.coroutine_return() {
coroutine.return_ty().into()
} else if name == sym::Yield {
} else if Some(goal.predicate.def_id()) == lang_items.coroutine_yield() {
coroutine.yield_ty().into()
} else {
bug!("unexpected associated item `<{self_ty} as Coroutine>::{name}`")
bug!(
"unexpected associated item `<{self_ty} as Coroutine>::{}`",
tcx.item_name(goal.predicate.def_id())
)
};
Self::probe_and_consider_implied_clause(

View file

@ -1373,15 +1373,16 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
coroutine_sig,
);
let name = tcx.associated_item(obligation.predicate.def_id).name;
let ty = if name == sym::Return {
let lang_items = tcx.lang_items();
let ty = if Some(obligation.predicate.def_id) == lang_items.coroutine_return() {
return_ty
} else if name == sym::Yield {
} else if Some(obligation.predicate.def_id) == lang_items.coroutine_yield() {
yield_ty
} else {
span_bug!(
tcx.def_span(obligation.predicate.def_id),
"unexpected associated type: `Coroutine::{name}`"
"unexpected associated type: `Coroutine::{}`",
tcx.item_name(obligation.predicate.def_id),
);
};