LangItem-ify Coroutine trait in solvers
This commit is contained in:
parent
921645c737
commit
d3812ac95f
5 changed files with 20 additions and 10 deletions
|
@ -244,7 +244,9 @@ language_item_table! {
|
||||||
AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
|
AsyncIterator, sym::async_iterator, async_iterator_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||||
|
|
||||||
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
|
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;
|
CoroutineResume, sym::coroutine_resume, coroutine_resume, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
|
||||||
|
|
||||||
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
||||||
|
|
|
@ -635,7 +635,9 @@ symbols! {
|
||||||
coroutine,
|
coroutine,
|
||||||
coroutine_clone,
|
coroutine_clone,
|
||||||
coroutine_resume,
|
coroutine_resume,
|
||||||
|
coroutine_return,
|
||||||
coroutine_state,
|
coroutine_state,
|
||||||
|
coroutine_yield,
|
||||||
coroutines,
|
coroutines,
|
||||||
cosf128,
|
cosf128,
|
||||||
cosf16,
|
cosf16,
|
||||||
|
|
|
@ -17,7 +17,7 @@ use rustc_middle::ty::NormalizesTo;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use rustc_middle::ty::{TypeVisitableExt, Upcast};
|
use rustc_middle::ty::{TypeVisitableExt, Upcast};
|
||||||
use rustc_middle::{bug, span_bug};
|
use rustc_middle::{bug, span_bug};
|
||||||
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
|
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
|
||||||
|
|
||||||
mod anon_const;
|
mod anon_const;
|
||||||
mod inherent;
|
mod inherent;
|
||||||
|
@ -719,13 +719,16 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
|
||||||
|
|
||||||
let coroutine = args.as_coroutine();
|
let coroutine = args.as_coroutine();
|
||||||
|
|
||||||
let name = tcx.associated_item(goal.predicate.def_id()).name;
|
let lang_items = tcx.lang_items();
|
||||||
let term = if name == sym::Return {
|
let term = if Some(goal.predicate.def_id()) == lang_items.coroutine_return() {
|
||||||
coroutine.return_ty().into()
|
coroutine.return_ty().into()
|
||||||
} else if name == sym::Yield {
|
} else if Some(goal.predicate.def_id()) == lang_items.coroutine_yield() {
|
||||||
coroutine.yield_ty().into()
|
coroutine.yield_ty().into()
|
||||||
} else {
|
} 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(
|
Self::probe_and_consider_implied_clause(
|
||||||
|
|
|
@ -1373,15 +1373,16 @@ fn confirm_coroutine_candidate<'cx, 'tcx>(
|
||||||
coroutine_sig,
|
coroutine_sig,
|
||||||
);
|
);
|
||||||
|
|
||||||
let name = tcx.associated_item(obligation.predicate.def_id).name;
|
let lang_items = tcx.lang_items();
|
||||||
let ty = if name == sym::Return {
|
let ty = if Some(obligation.predicate.def_id) == lang_items.coroutine_return() {
|
||||||
return_ty
|
return_ty
|
||||||
} else if name == sym::Yield {
|
} else if Some(obligation.predicate.def_id) == lang_items.coroutine_yield() {
|
||||||
yield_ty
|
yield_ty
|
||||||
} else {
|
} else {
|
||||||
span_bug!(
|
span_bug!(
|
||||||
tcx.def_span(obligation.predicate.def_id),
|
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.
|
/// 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
|
/// For example an iterator-as-a-coroutine would likely have this type as
|
||||||
/// `T`, the type being iterated over.
|
/// `T`, the type being iterated over.
|
||||||
|
#[cfg_attr(not(bootstrap), lang = "coroutine_yield")]
|
||||||
type Yield;
|
type Yield;
|
||||||
|
|
||||||
/// The type of value this coroutine returns.
|
/// 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
|
/// `return` statement or implicitly as the last expression of a coroutine
|
||||||
/// literal. For example futures would use this as `Result<T, E>` as it
|
/// literal. For example futures would use this as `Result<T, E>` as it
|
||||||
/// represents a completed future.
|
/// represents a completed future.
|
||||||
|
#[cfg_attr(not(bootstrap), lang = "coroutine_return")]
|
||||||
type Return;
|
type Return;
|
||||||
|
|
||||||
/// Resumes the execution of this coroutine.
|
/// Resumes the execution of this coroutine.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue