s/generator/coroutine/
This commit is contained in:
@@ -111,7 +111,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
if lang_items.gen_trait() == Some(def_id) {
|
||||
self.assemble_generator_candidates(obligation, &mut candidates);
|
||||
self.assemble_coroutine_candidates(obligation, &mut candidates);
|
||||
} else if lang_items.future_trait() == Some(def_id) {
|
||||
self.assemble_future_candidates(obligation, &mut candidates);
|
||||
}
|
||||
@@ -201,25 +201,25 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn assemble_generator_candidates(
|
||||
fn assemble_coroutine_candidates(
|
||||
&mut self,
|
||||
obligation: &PolyTraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) {
|
||||
// Okay to skip binder because the args on generator types never
|
||||
// Okay to skip binder because the args on coroutine types never
|
||||
// touch bound regions, they just capture the in-scope
|
||||
// type/region parameters.
|
||||
let self_ty = obligation.self_ty().skip_binder();
|
||||
match self_ty.kind() {
|
||||
// async constructs get lowered to a special kind of generator that
|
||||
// async constructs get lowered to a special kind of coroutine that
|
||||
// should *not* `impl Coroutine`.
|
||||
ty::Coroutine(did, ..) if !self.tcx().generator_is_async(*did) => {
|
||||
debug!(?self_ty, ?obligation, "assemble_generator_candidates",);
|
||||
ty::Coroutine(did, ..) if !self.tcx().coroutine_is_async(*did) => {
|
||||
debug!(?self_ty, ?obligation, "assemble_coroutine_candidates",);
|
||||
|
||||
candidates.vec.push(CoroutineCandidate);
|
||||
}
|
||||
ty::Infer(ty::TyVar(_)) => {
|
||||
debug!("assemble_generator_candidates: ambiguous self-type");
|
||||
debug!("assemble_coroutine_candidates: ambiguous self-type");
|
||||
candidates.ambiguous = true;
|
||||
}
|
||||
_ => {}
|
||||
@@ -233,9 +233,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
) {
|
||||
let self_ty = obligation.self_ty().skip_binder();
|
||||
if let ty::Coroutine(did, ..) = self_ty.kind() {
|
||||
// async constructs get lowered to a special kind of generator that
|
||||
// async constructs get lowered to a special kind of coroutine that
|
||||
// should directly `impl Future`.
|
||||
if self.tcx().generator_is_async(*did) {
|
||||
if self.tcx().coroutine_is_async(*did) {
|
||||
debug!(?self_ty, ?obligation, "assemble_future_candidates",);
|
||||
|
||||
candidates.vec.push(FutureCandidate);
|
||||
@@ -518,11 +518,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
{
|
||||
match movability {
|
||||
hir::Movability::Static => {
|
||||
// Immovable generators are never `Unpin`, so
|
||||
// Immovable coroutines are never `Unpin`, so
|
||||
// suppress the normal auto-impl candidate for it.
|
||||
}
|
||||
hir::Movability::Movable => {
|
||||
// Movable generators are always `Unpin`, so add an
|
||||
// Movable coroutines are always `Unpin`, so add an
|
||||
// unconditional builtin candidate.
|
||||
candidates.vec.push(BuiltinCandidate { has_nested: false });
|
||||
}
|
||||
|
||||
@@ -84,8 +84,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
}
|
||||
|
||||
CoroutineCandidate => {
|
||||
let vtable_generator = self.confirm_generator_candidate(obligation)?;
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, vtable_generator)
|
||||
let vtable_coroutine = self.confirm_coroutine_candidate(obligation)?;
|
||||
ImplSource::Builtin(BuiltinImplSource::Misc, vtable_coroutine)
|
||||
}
|
||||
|
||||
FutureCandidate => {
|
||||
@@ -711,23 +711,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
trait_obligations
|
||||
}
|
||||
|
||||
fn confirm_generator_candidate(
|
||||
fn confirm_coroutine_candidate(
|
||||
&mut self,
|
||||
obligation: &PolyTraitObligation<'tcx>,
|
||||
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||
// Okay to skip binder because the args on generator types never
|
||||
// Okay to skip binder because the args on coroutine types never
|
||||
// touch bound regions, they just capture the in-scope
|
||||
// type/region parameters.
|
||||
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
|
||||
let ty::Coroutine(generator_def_id, args, _) = *self_ty.kind() else {
|
||||
let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else {
|
||||
bug!("closure candidate for non-closure {:?}", obligation);
|
||||
};
|
||||
|
||||
debug!(?obligation, ?generator_def_id, ?args, "confirm_generator_candidate");
|
||||
debug!(?obligation, ?coroutine_def_id, ?args, "confirm_coroutine_candidate");
|
||||
|
||||
let gen_sig = args.as_generator().poly_sig();
|
||||
let gen_sig = args.as_coroutine().poly_sig();
|
||||
|
||||
// NOTE: The self-type is a generator type and hence is
|
||||
// NOTE: The self-type is a coroutine type and hence is
|
||||
// in fact unparameterized (or at least does not reference any
|
||||
// regions bound in the obligation).
|
||||
let self_ty = obligation
|
||||
@@ -736,7 +736,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
.no_bound_vars()
|
||||
.expect("unboxed closure type should not capture bound vars from the predicate");
|
||||
|
||||
let trait_ref = super::util::generator_trait_ref_and_outputs(
|
||||
let trait_ref = super::util::coroutine_trait_ref_and_outputs(
|
||||
self.tcx(),
|
||||
obligation.predicate.def_id(),
|
||||
self_ty,
|
||||
@@ -745,7 +745,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
.map_bound(|(trait_ref, ..)| trait_ref);
|
||||
|
||||
let nested = self.confirm_poly_trait_refs(obligation, trait_ref)?;
|
||||
debug!(?trait_ref, ?nested, "generator candidate obligations");
|
||||
debug!(?trait_ref, ?nested, "coroutine candidate obligations");
|
||||
|
||||
Ok(nested)
|
||||
}
|
||||
@@ -754,17 +754,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
&mut self,
|
||||
obligation: &PolyTraitObligation<'tcx>,
|
||||
) -> Result<Vec<PredicateObligation<'tcx>>, SelectionError<'tcx>> {
|
||||
// Okay to skip binder because the args on generator types never
|
||||
// Okay to skip binder because the args on coroutine types never
|
||||
// touch bound regions, they just capture the in-scope
|
||||
// type/region parameters.
|
||||
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
|
||||
let ty::Coroutine(generator_def_id, args, _) = *self_ty.kind() else {
|
||||
let ty::Coroutine(coroutine_def_id, args, _) = *self_ty.kind() else {
|
||||
bug!("closure candidate for non-closure {:?}", obligation);
|
||||
};
|
||||
|
||||
debug!(?obligation, ?generator_def_id, ?args, "confirm_future_candidate");
|
||||
debug!(?obligation, ?coroutine_def_id, ?args, "confirm_future_candidate");
|
||||
|
||||
let gen_sig = args.as_generator().poly_sig();
|
||||
let gen_sig = args.as_coroutine().poly_sig();
|
||||
|
||||
let trait_ref = super::util::future_trait_ref_and_outputs(
|
||||
self.tcx(),
|
||||
@@ -1235,12 +1235,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||
stack.push(args.as_closure().tupled_upvars_ty());
|
||||
}
|
||||
ty::Coroutine(_, args, _) => {
|
||||
let generator = args.as_generator();
|
||||
stack.extend([generator.tupled_upvars_ty(), generator.witness()]);
|
||||
let coroutine = args.as_coroutine();
|
||||
stack.extend([coroutine.tupled_upvars_ty(), coroutine.witness()]);
|
||||
}
|
||||
ty::CoroutineWitness(def_id, args) => {
|
||||
let tcx = self.tcx();
|
||||
stack.extend(tcx.generator_hidden_types(def_id).map(|bty| {
|
||||
stack.extend(tcx.coroutine_hidden_types(def_id).map(|bty| {
|
||||
let ty = bty.instantiate(tcx, args);
|
||||
debug_assert!(!ty.has_late_bound_regions());
|
||||
ty
|
||||
|
||||
@@ -2190,20 +2190,20 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||
}
|
||||
|
||||
ty::Coroutine(_, args, hir::Movability::Movable) => {
|
||||
if self.tcx().features().generator_clone {
|
||||
if self.tcx().features().coroutine_clone {
|
||||
let resolved_upvars =
|
||||
self.infcx.shallow_resolve(args.as_generator().tupled_upvars_ty());
|
||||
self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
|
||||
let resolved_witness =
|
||||
self.infcx.shallow_resolve(args.as_generator().witness());
|
||||
self.infcx.shallow_resolve(args.as_coroutine().witness());
|
||||
if resolved_upvars.is_ty_var() || resolved_witness.is_ty_var() {
|
||||
// Not yet resolved.
|
||||
Ambiguous
|
||||
} else {
|
||||
let all = args
|
||||
.as_generator()
|
||||
.as_coroutine()
|
||||
.upvar_tys()
|
||||
.iter()
|
||||
.chain([args.as_generator().witness()])
|
||||
.chain([args.as_coroutine().witness()])
|
||||
.collect::<Vec<_>>();
|
||||
Where(obligation.predicate.rebind(all))
|
||||
}
|
||||
@@ -2213,7 +2213,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||
}
|
||||
|
||||
ty::CoroutineWitness(def_id, ref args) => {
|
||||
let hidden_types = bind_generator_hidden_types_above(
|
||||
let hidden_types = bind_coroutine_hidden_types_above(
|
||||
self.infcx,
|
||||
def_id,
|
||||
args,
|
||||
@@ -2312,13 +2312,13 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||
}
|
||||
|
||||
ty::Coroutine(_, ref args, _) => {
|
||||
let ty = self.infcx.shallow_resolve(args.as_generator().tupled_upvars_ty());
|
||||
let witness = args.as_generator().witness();
|
||||
let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
|
||||
let witness = args.as_coroutine().witness();
|
||||
t.rebind([ty].into_iter().chain(iter::once(witness)).collect())
|
||||
}
|
||||
|
||||
ty::CoroutineWitness(def_id, ref args) => {
|
||||
bind_generator_hidden_types_above(self.infcx, def_id, args, t.bound_vars())
|
||||
bind_coroutine_hidden_types_above(self.infcx, def_id, args, t.bound_vars())
|
||||
}
|
||||
|
||||
// For `PhantomData<T>`, we pass `T`.
|
||||
@@ -3054,12 +3054,12 @@ pub enum ProjectionMatchesProjection {
|
||||
No,
|
||||
}
|
||||
|
||||
/// Replace all regions inside the generator interior with late bound regions.
|
||||
/// Replace all regions inside the coroutine interior with late bound regions.
|
||||
/// Note that each region slot in the types gets a new fresh late bound region, which means that
|
||||
/// none of the regions inside relate to any other, even if typeck had previously found constraints
|
||||
/// that would cause them to be related.
|
||||
#[instrument(level = "trace", skip(infcx), ret)]
|
||||
fn bind_generator_hidden_types_above<'tcx>(
|
||||
fn bind_coroutine_hidden_types_above<'tcx>(
|
||||
infcx: &InferCtxt<'tcx>,
|
||||
def_id: DefId,
|
||||
args: ty::GenericArgsRef<'tcx>,
|
||||
@@ -3074,7 +3074,7 @@ fn bind_generator_hidden_types_above<'tcx>(
|
||||
let mut counter = num_bound_variables;
|
||||
|
||||
let hidden_types: Vec<_> = tcx
|
||||
.generator_hidden_types(def_id)
|
||||
.coroutine_hidden_types(def_id)
|
||||
// Deduplicate tys to avoid repeated work.
|
||||
.filter(|bty| seen_tys.insert(*bty))
|
||||
.map(|mut bty| {
|
||||
|
||||
Reference in New Issue
Block a user