mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 22:12:15 +00:00
LangItem-ify Coroutine trait in solvers
This commit is contained in:
parent
921645c737
commit
d3812ac95f
@ -244,7 +244,9 @@ language_item_table! {
|
||||
AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||
|
||||
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
|
||||
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Minimum(1);
|
||||
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Exact(1);
|
||||
CoroutineReturn, sym::coroutine_return, coroutine_return, Target::AssocTy, GenericRequirement::Exact(1);
|
||||
CoroutineYield, sym::coroutine_yield, coroutine_yield, Target::AssocTy, GenericRequirement::Exact(1);
|
||||
CoroutineResume, sym::coroutine_resume, coroutine_resume, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
||||
|
||||
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
||||
|
@ -635,7 +635,9 @@ symbols! {
|
||||
coroutine,
|
||||
coroutine_clone,
|
||||
coroutine_resume,
|
||||
coroutine_return,
|
||||
coroutine_state,
|
||||
coroutine_yield,
|
||||
coroutines,
|
||||
cosf128,
|
||||
cosf16,
|
||||
|
@ -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(
|
||||
|
@ -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),
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -76,6 +76,7 @@ pub trait Coroutine<R = ()> {
|
||||
/// values which are allowed to be returned each time a coroutine yields.
|
||||
/// For example an iterator-as-a-coroutine would likely have this type as
|
||||
/// `T`, the type being iterated over.
|
||||
#[cfg_attr(not(bootstrap), lang = "coroutine_yield")]
|
||||
type Yield;
|
||||
|
||||
/// The type of value this coroutine returns.
|
||||
@ -84,6 +85,7 @@ pub trait Coroutine<R = ()> {
|
||||
/// `return` statement or implicitly as the last expression of a coroutine
|
||||
/// literal. For example futures would use this as `Result<T, E>` as it
|
||||
/// represents a completed future.
|
||||
#[cfg_attr(not(bootstrap), lang = "coroutine_return")]
|
||||
type Return;
|
||||
|
||||
/// Resumes the execution of this coroutine.
|
||||
|
Loading…
Reference in New Issue
Block a user