mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
fix: rename generator to coroutine
Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html)
This commit is contained in:
parent
a356172f92
commit
f937673ce2
22 changed files with 100 additions and 100 deletions
|
@ -37,7 +37,7 @@ pub struct Body {
|
|||
pub pats: Arena<Pat>,
|
||||
pub bindings: Arena<Binding>,
|
||||
pub labels: Arena<Label>,
|
||||
/// Id of the closure/generator that owns the corresponding binding. If a binding is owned by the
|
||||
/// Id of the closure/coroutine that owns the corresponding binding. If a binding is owned by the
|
||||
/// top level expression, it will not be listed in here.
|
||||
pub binding_owners: FxHashMap<BindingId, ExprId>,
|
||||
/// The patterns for the function's parameters. While the parameter types are
|
||||
|
|
|
@ -81,7 +81,7 @@ pub(super) fn lower(
|
|||
expander,
|
||||
current_try_block_label: None,
|
||||
is_lowering_assignee_expr: false,
|
||||
is_lowering_generator: false,
|
||||
is_lowering_coroutine: false,
|
||||
label_ribs: Vec::new(),
|
||||
current_binding_owner: None,
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ struct ExprCollector<'a> {
|
|||
source_map: BodySourceMap,
|
||||
|
||||
is_lowering_assignee_expr: bool,
|
||||
is_lowering_generator: bool,
|
||||
is_lowering_coroutine: bool,
|
||||
|
||||
current_try_block_label: Option<LabelId>,
|
||||
// points to the expression that a try expression will target (replaces current_try_block_label)
|
||||
|
@ -417,7 +417,7 @@ impl ExprCollector<'_> {
|
|||
self.alloc_expr(Expr::Return { expr }, syntax_ptr)
|
||||
}
|
||||
ast::Expr::YieldExpr(e) => {
|
||||
self.is_lowering_generator = true;
|
||||
self.is_lowering_coroutine = true;
|
||||
let expr = e.expr().map(|e| self.collect_expr(e));
|
||||
self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
|
||||
}
|
||||
|
@ -525,18 +525,18 @@ impl ExprCollector<'_> {
|
|||
.and_then(|r| r.ty())
|
||||
.map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
|
||||
|
||||
let prev_is_lowering_generator = mem::take(&mut this.is_lowering_generator);
|
||||
let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
|
||||
let prev_try_block_label = this.current_try_block_label.take();
|
||||
|
||||
let body = this.collect_expr_opt(e.body());
|
||||
|
||||
let closure_kind = if this.is_lowering_generator {
|
||||
let closure_kind = if this.is_lowering_coroutine {
|
||||
let movability = if e.static_token().is_some() {
|
||||
Movability::Static
|
||||
} else {
|
||||
Movability::Movable
|
||||
};
|
||||
ClosureKind::Generator(movability)
|
||||
ClosureKind::Coroutine(movability)
|
||||
} else if e.async_token().is_some() {
|
||||
ClosureKind::Async
|
||||
} else {
|
||||
|
@ -544,7 +544,7 @@ impl ExprCollector<'_> {
|
|||
};
|
||||
let capture_by =
|
||||
if e.move_token().is_some() { CaptureBy::Value } else { CaptureBy::Ref };
|
||||
this.is_lowering_generator = prev_is_lowering_generator;
|
||||
this.is_lowering_coroutine = prev_is_lowering_coroutine;
|
||||
this.current_binding_owner = prev_binding_owner;
|
||||
this.current_try_block_label = prev_try_block_label;
|
||||
this.body.exprs[result_expr_id] = Expr::Closure {
|
||||
|
|
|
@ -384,7 +384,7 @@ impl Printer<'_> {
|
|||
}
|
||||
Expr::Closure { args, arg_types, ret_type, body, closure_kind, capture_by } => {
|
||||
match closure_kind {
|
||||
ClosureKind::Generator(Movability::Static) => {
|
||||
ClosureKind::Coroutine(Movability::Static) => {
|
||||
w!(self, "static ");
|
||||
}
|
||||
ClosureKind::Async => {
|
||||
|
|
|
@ -300,7 +300,7 @@ pub struct InlineAsm {
|
|||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ClosureKind {
|
||||
Closure,
|
||||
Generator(Movability),
|
||||
Coroutine(Movability),
|
||||
Async,
|
||||
}
|
||||
|
||||
|
|
|
@ -334,8 +334,8 @@ language_item_table! {
|
|||
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
|
||||
|
||||
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
|
||||
GeneratorState, sym::generator_state, gen_state, Target::Enum, GenericRequirement::None;
|
||||
Generator, sym::generator, gen_trait, Target::Trait, GenericRequirement::Minimum(1);
|
||||
CoroutineState, sym::coroutine_state, coroutine_state, Target::Enum, GenericRequirement::None;
|
||||
Coroutine, sym::coroutine, coroutine_trait, Target::Trait, GenericRequirement::Minimum(1);
|
||||
Unpin, sym::unpin, unpin_trait, Target::Trait, GenericRequirement::None;
|
||||
Pin, sym::pin, pin_type, Target::Struct, GenericRequirement::None;
|
||||
|
||||
|
|
|
@ -227,21 +227,21 @@ impl TyBuilder<()> {
|
|||
TyBuilder::new((), params, parent_subst)
|
||||
}
|
||||
|
||||
/// Creates a `TyBuilder` to build `Substitution` for a generator defined in `parent`.
|
||||
/// Creates a `TyBuilder` to build `Substitution` for a coroutine defined in `parent`.
|
||||
///
|
||||
/// A generator's substitution consists of:
|
||||
/// - resume type of generator
|
||||
/// - yield type of generator ([`Generator::Yield`](std::ops::Generator::Yield))
|
||||
/// - return type of generator ([`Generator::Return`](std::ops::Generator::Return))
|
||||
/// A coroutine's substitution consists of:
|
||||
/// - resume type of coroutine
|
||||
/// - yield type of coroutine ([`Coroutine::Yield`](std::ops::Coroutine::Yield))
|
||||
/// - return type of coroutine ([`Coroutine::Return`](std::ops::Coroutine::Return))
|
||||
/// - generic parameters in scope on `parent`
|
||||
/// in this order.
|
||||
///
|
||||
/// This method prepopulates the builder with placeholder substitution of `parent`, so you
|
||||
/// should only push exactly 3 `GenericArg`s before building.
|
||||
pub fn subst_for_generator(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
|
||||
pub fn subst_for_coroutine(db: &dyn HirDatabase, parent: DefWithBodyId) -> TyBuilder<()> {
|
||||
let parent_subst =
|
||||
parent.as_generic_def_id().map(|p| generics(db.upcast(), p).placeholder_subst(db));
|
||||
// These represent resume type, yield type, and return type of generator.
|
||||
// These represent resume type, yield type, and return type of coroutine.
|
||||
let params = std::iter::repeat(ParamKind::Type).take(3).collect();
|
||||
TyBuilder::new((), params, parent_subst)
|
||||
}
|
||||
|
|
|
@ -428,12 +428,12 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
&self,
|
||||
id: chalk_ir::GeneratorId<Interner>,
|
||||
) -> Arc<chalk_solve::rust_ir::GeneratorDatum<Interner>> {
|
||||
let (parent, expr) = self.db.lookup_intern_generator(id.into());
|
||||
let (parent, expr) = self.db.lookup_intern_coroutine(id.into());
|
||||
|
||||
// We fill substitution with unknown type, because we only need to know whether the generic
|
||||
// params are types or consts to build `Binders` and those being filled up are for
|
||||
// `resume_type`, `yield_type`, and `return_type` of the generator in question.
|
||||
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
|
||||
// `resume_type`, `yield_type`, and `return_type` of the coroutine in question.
|
||||
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
|
||||
|
||||
let input_output = rust_ir::GeneratorInputOutputDatum {
|
||||
resume_type: TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))
|
||||
|
@ -453,10 +453,10 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
|
||||
let movability = match self.db.body(parent)[expr] {
|
||||
hir_def::hir::Expr::Closure {
|
||||
closure_kind: hir_def::hir::ClosureKind::Generator(movability),
|
||||
closure_kind: hir_def::hir::ClosureKind::Coroutine(movability),
|
||||
..
|
||||
} => movability,
|
||||
_ => unreachable!("non generator expression interned as generator"),
|
||||
_ => unreachable!("non coroutine expression interned as coroutine"),
|
||||
};
|
||||
let movability = match movability {
|
||||
Movability::Static => rust_ir::Movability::Static,
|
||||
|
@ -473,9 +473,9 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
|
|||
let inner_types =
|
||||
rust_ir::GeneratorWitnessExistential { types: wrap_empty_binders(vec![]) };
|
||||
|
||||
let (parent, _) = self.db.lookup_intern_generator(id.into());
|
||||
let (parent, _) = self.db.lookup_intern_coroutine(id.into());
|
||||
// See the comment in `generator_datum()` for unknown types.
|
||||
let subst = TyBuilder::subst_for_generator(self.db, parent).fill_with_unknown().build();
|
||||
let subst = TyBuilder::subst_for_coroutine(self.db, parent).fill_with_unknown().build();
|
||||
let it = subst
|
||||
.iter(Interner)
|
||||
.map(|it| it.constant(Interner).map(|c| c.data(Interner).ty.clone()));
|
||||
|
@ -617,7 +617,7 @@ fn well_known_trait_from_lang_item(item: LangItem) -> Option<WellKnownTrait> {
|
|||
LangItem::Fn => WellKnownTrait::Fn,
|
||||
LangItem::FnMut => WellKnownTrait::FnMut,
|
||||
LangItem::FnOnce => WellKnownTrait::FnOnce,
|
||||
LangItem::Generator => WellKnownTrait::Generator,
|
||||
LangItem::Coroutine => WellKnownTrait::Generator,
|
||||
LangItem::Sized => WellKnownTrait::Sized,
|
||||
LangItem::Unpin => WellKnownTrait::Unpin,
|
||||
LangItem::Unsize => WellKnownTrait::Unsize,
|
||||
|
@ -639,7 +639,7 @@ fn lang_item_from_well_known_trait(trait_: WellKnownTrait) -> LangItem {
|
|||
WellKnownTrait::Fn => LangItem::Fn,
|
||||
WellKnownTrait::FnMut => LangItem::FnMut,
|
||||
WellKnownTrait::FnOnce => LangItem::FnOnce,
|
||||
WellKnownTrait::Generator => LangItem::Generator,
|
||||
WellKnownTrait::Generator => LangItem::Coroutine,
|
||||
WellKnownTrait::Sized => LangItem::Sized,
|
||||
WellKnownTrait::Tuple => LangItem::Tuple,
|
||||
WellKnownTrait::Unpin => LangItem::Unpin,
|
||||
|
|
|
@ -199,7 +199,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
|||
#[salsa::interned]
|
||||
fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
|
||||
#[salsa::interned]
|
||||
fn intern_generator(&self, id: (DefWithBodyId, ExprId)) -> InternedGeneratorId;
|
||||
fn intern_coroutine(&self, id: (DefWithBodyId, ExprId)) -> InternedCoroutineId;
|
||||
|
||||
#[salsa::invoke(chalk_db::associated_ty_data_query)]
|
||||
fn associated_ty_data(
|
||||
|
@ -335,8 +335,8 @@ pub struct InternedClosureId(salsa::InternId);
|
|||
impl_intern_key!(InternedClosureId);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct InternedGeneratorId(salsa::InternId);
|
||||
impl_intern_key!(InternedGeneratorId);
|
||||
pub struct InternedCoroutineId(salsa::InternId);
|
||||
impl_intern_key!(InternedCoroutineId);
|
||||
|
||||
/// This exists just for Chalk, because Chalk just has a single `FnDefId` where
|
||||
/// we have different IDs for struct and enum variant constructors.
|
||||
|
|
|
@ -276,7 +276,7 @@ impl DisplayTarget {
|
|||
pub enum DisplaySourceCodeError {
|
||||
PathNotFound,
|
||||
UnknownType,
|
||||
Generator,
|
||||
Coroutine,
|
||||
OpaqueType,
|
||||
}
|
||||
|
||||
|
@ -659,8 +659,8 @@ fn render_const_scalar(
|
|||
}
|
||||
TyKind::Never => f.write_str("!"),
|
||||
TyKind::Closure(_, _) => f.write_str("<closure>"),
|
||||
TyKind::Generator(_, _) => f.write_str("<generator>"),
|
||||
TyKind::GeneratorWitness(_, _) => f.write_str("<generator-witness>"),
|
||||
TyKind::Generator(_, _) => f.write_str("<coroutine>"),
|
||||
TyKind::GeneratorWitness(_, _) => f.write_str("<coroutine-witness>"),
|
||||
// The below arms are unreachable, since const eval will bail out before here.
|
||||
TyKind::Foreign(_) => f.write_str("<extern-type>"),
|
||||
TyKind::Error
|
||||
|
@ -1208,7 +1208,7 @@ impl HirDisplay for Ty {
|
|||
TyKind::Generator(_, subst) => {
|
||||
if f.display_target.is_source_code() {
|
||||
return Err(HirDisplayError::DisplaySourceCodeError(
|
||||
DisplaySourceCodeError::Generator,
|
||||
DisplaySourceCodeError::Coroutine,
|
||||
));
|
||||
}
|
||||
let subst = subst.as_slice(Interner);
|
||||
|
@ -1229,10 +1229,10 @@ impl HirDisplay for Ty {
|
|||
ret_ty.hir_fmt(f)?;
|
||||
} else {
|
||||
// This *should* be unreachable, but fallback just in case.
|
||||
write!(f, "{{generator}}")?;
|
||||
write!(f, "{{coroutine}}")?;
|
||||
}
|
||||
}
|
||||
TyKind::GeneratorWitness(..) => write!(f, "{{generator witness}}")?,
|
||||
TyKind::GeneratorWitness(..) => write!(f, "{{coroutine witness}}")?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -534,7 +534,7 @@ pub(crate) struct InferenceContext<'a> {
|
|||
/// expressions. If `None`, this is in a context where return is
|
||||
/// inappropriate, such as a const expression.
|
||||
return_coercion: Option<CoerceMany>,
|
||||
/// The resume type and the yield type, respectively, of the generator being inferred.
|
||||
/// The resume type and the yield type, respectively, of the coroutine being inferred.
|
||||
resume_yield_tys: Option<(Ty, Ty)>,
|
||||
diverges: Diverges,
|
||||
breakables: Vec<BreakableContext>,
|
||||
|
|
|
@ -34,7 +34,7 @@ use crate::{
|
|||
use super::{Expectation, InferenceContext};
|
||||
|
||||
impl InferenceContext<'_> {
|
||||
// This function handles both closures and generators.
|
||||
// This function handles both closures and coroutines.
|
||||
pub(super) fn deduce_closure_type_from_expectations(
|
||||
&mut self,
|
||||
closure_expr: ExprId,
|
||||
|
@ -50,7 +50,7 @@ impl InferenceContext<'_> {
|
|||
// Deduction from where-clauses in scope, as well as fn-pointer coercion are handled here.
|
||||
let _ = self.coerce(Some(closure_expr), closure_ty, &expected_ty);
|
||||
|
||||
// Generators are not Fn* so return early.
|
||||
// Coroutines are not Fn* so return early.
|
||||
if matches!(closure_ty.kind(Interner), TyKind::Generator(..)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -233,7 +233,7 @@ impl InferenceContext<'_> {
|
|||
.intern(Interner);
|
||||
|
||||
let (id, ty, resume_yield_tys) = match closure_kind {
|
||||
ClosureKind::Generator(_) => {
|
||||
ClosureKind::Coroutine(_) => {
|
||||
// FIXME: report error when there are more than 1 parameter.
|
||||
let resume_ty = match sig_tys.first() {
|
||||
// When `sig_tys.len() == 1` the first type is the return type, not the
|
||||
|
@ -243,16 +243,16 @@ impl InferenceContext<'_> {
|
|||
};
|
||||
let yield_ty = self.table.new_type_var();
|
||||
|
||||
let subst = TyBuilder::subst_for_generator(self.db, self.owner)
|
||||
let subst = TyBuilder::subst_for_coroutine(self.db, self.owner)
|
||||
.push(resume_ty.clone())
|
||||
.push(yield_ty.clone())
|
||||
.push(ret_ty.clone())
|
||||
.build();
|
||||
|
||||
let generator_id = self.db.intern_generator((self.owner, tgt_expr)).into();
|
||||
let generator_ty = TyKind::Generator(generator_id, subst).intern(Interner);
|
||||
let coroutine_id = self.db.intern_coroutine((self.owner, tgt_expr)).into();
|
||||
let coroutine_ty = TyKind::Generator(coroutine_id, subst).intern(Interner);
|
||||
|
||||
(None, generator_ty, Some((resume_ty, yield_ty)))
|
||||
(None, coroutine_ty, Some((resume_ty, yield_ty)))
|
||||
}
|
||||
ClosureKind::Closure | ClosureKind::Async => {
|
||||
let closure_id = self.db.intern_closure((self.owner, tgt_expr)).into();
|
||||
|
@ -503,7 +503,7 @@ impl InferenceContext<'_> {
|
|||
}
|
||||
resume_ty
|
||||
} else {
|
||||
// FIXME: report error (yield expr in non-generator)
|
||||
// FIXME: report error (yield expr in non-coroutine)
|
||||
self.result.standard_types.unknown.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,14 +103,14 @@ impl From<crate::db::InternedClosureId> for chalk_ir::ClosureId<Interner> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedGeneratorId {
|
||||
impl From<chalk_ir::GeneratorId<Interner>> for crate::db::InternedCoroutineId {
|
||||
fn from(id: chalk_ir::GeneratorId<Interner>) -> Self {
|
||||
Self::from_intern_id(id.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<crate::db::InternedGeneratorId> for chalk_ir::GeneratorId<Interner> {
|
||||
fn from(id: crate::db::InternedGeneratorId) -> Self {
|
||||
impl From<crate::db::InternedCoroutineId> for chalk_ir::GeneratorId<Interner> {
|
||||
fn from(id: crate::db::InternedCoroutineId) -> Self {
|
||||
chalk_ir::GeneratorId(id.as_intern_id())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -333,7 +333,7 @@ pub enum AggregateKind {
|
|||
Adt(VariantId, Substitution),
|
||||
Union(UnionId, FieldId),
|
||||
Closure(Ty),
|
||||
//Generator(LocalDefId, SubstsRef, Movability),
|
||||
//Coroutine(LocalDefId, SubstsRef, Movability),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
|
||||
|
@ -453,8 +453,8 @@ pub enum TerminatorKind {
|
|||
/// `dest = move _0`. It might additionally do other things, like have side-effects in the
|
||||
/// aliasing model.
|
||||
///
|
||||
/// If the body is a generator body, this has slightly different semantics; it instead causes a
|
||||
/// `GeneratorState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned
|
||||
/// If the body is a coroutine body, this has slightly different semantics; it instead causes a
|
||||
/// `CoroutineState::Returned(_0)` to be created (as if by an `Aggregate` rvalue) and assigned
|
||||
/// to the return place.
|
||||
Return,
|
||||
|
||||
|
@ -566,14 +566,14 @@ pub enum TerminatorKind {
|
|||
|
||||
/// Marks a suspend point.
|
||||
///
|
||||
/// Like `Return` terminators in generator bodies, this computes `value` and then a
|
||||
/// `GeneratorState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to
|
||||
/// Like `Return` terminators in coroutine bodies, this computes `value` and then a
|
||||
/// `CoroutineState::Yielded(value)` as if by `Aggregate` rvalue. That value is then assigned to
|
||||
/// the return place of the function calling this one, and execution continues in the calling
|
||||
/// function. When next invoked with the same first argument, execution of this function
|
||||
/// continues at the `resume` basic block, with the second argument written to the `resume_arg`
|
||||
/// place. If the generator is dropped before then, the `drop` basic block is invoked.
|
||||
/// place. If the coroutine is dropped before then, the `drop` basic block is invoked.
|
||||
///
|
||||
/// Not permitted in bodies that are not generator bodies, or after generator lowering.
|
||||
/// Not permitted in bodies that are not coroutine bodies, or after coroutine lowering.
|
||||
///
|
||||
/// **Needs clarification**: What about the evaluation order of the `resume_arg` and `value`?
|
||||
Yield {
|
||||
|
@ -583,21 +583,21 @@ pub enum TerminatorKind {
|
|||
resume: BasicBlockId,
|
||||
/// The place to store the resume argument in.
|
||||
resume_arg: Place,
|
||||
/// Cleanup to be done if the generator is dropped at this suspend point.
|
||||
/// Cleanup to be done if the coroutine is dropped at this suspend point.
|
||||
drop: Option<BasicBlockId>,
|
||||
},
|
||||
|
||||
/// Indicates the end of dropping a generator.
|
||||
/// Indicates the end of dropping a coroutine.
|
||||
///
|
||||
/// Semantically just a `return` (from the generators drop glue). Only permitted in the same situations
|
||||
/// Semantically just a `return` (from the coroutines drop glue). Only permitted in the same situations
|
||||
/// as `yield`.
|
||||
///
|
||||
/// **Needs clarification**: Is that even correct? The generator drop code is always confusing
|
||||
/// **Needs clarification**: Is that even correct? The coroutine drop code is always confusing
|
||||
/// to me, because it's not even really in the current body.
|
||||
///
|
||||
/// **Needs clarification**: Are there type system constraints on these terminators? Should
|
||||
/// there be a "block type" like `cleanup` blocks for them?
|
||||
GeneratorDrop,
|
||||
CoroutineDrop,
|
||||
|
||||
/// A block where control flow only ever takes one real path, but borrowck needs to be more
|
||||
/// conservative.
|
||||
|
@ -989,8 +989,8 @@ pub enum Rvalue {
|
|||
/// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo`
|
||||
/// has a destructor.
|
||||
///
|
||||
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After
|
||||
/// generator lowering, `Generator` aggregate kinds are disallowed too.
|
||||
/// Disallowed after deaggregation for all aggregate kinds except `Array` and `Coroutine`. After
|
||||
/// coroutine lowering, `Coroutine` aggregate kinds are disallowed too.
|
||||
Aggregate(AggregateKind, Box<[Operand]>),
|
||||
|
||||
/// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
|
||||
|
@ -1140,7 +1140,7 @@ impl MirBody {
|
|||
| TerminatorKind::FalseUnwind { .. }
|
||||
| TerminatorKind::Goto { .. }
|
||||
| TerminatorKind::UnwindResume
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::Abort
|
||||
| TerminatorKind::Return
|
||||
| TerminatorKind::Unreachable => (),
|
||||
|
|
|
@ -159,7 +159,7 @@ fn moved_out_of_ref(db: &dyn HirDatabase, body: &MirBody) -> Vec<MovedOutOfRef>
|
|||
| TerminatorKind::FalseUnwind { .. }
|
||||
| TerminatorKind::Goto { .. }
|
||||
| TerminatorKind::UnwindResume
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::Abort
|
||||
| TerminatorKind::Return
|
||||
| TerminatorKind::Unreachable
|
||||
|
@ -314,7 +314,7 @@ fn ever_initialized_map(
|
|||
TerminatorKind::DropAndReplace { .. }
|
||||
| TerminatorKind::Assert { .. }
|
||||
| TerminatorKind::Yield { .. }
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::FalseEdge { .. }
|
||||
| TerminatorKind::FalseUnwind { .. } => {
|
||||
never!("We don't emit these MIR terminators yet");
|
||||
|
@ -439,7 +439,7 @@ fn mutability_of_locals(
|
|||
| TerminatorKind::Unreachable
|
||||
| TerminatorKind::FalseEdge { .. }
|
||||
| TerminatorKind::FalseUnwind { .. }
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::Drop { .. }
|
||||
| TerminatorKind::DropAndReplace { .. }
|
||||
| TerminatorKind::Assert { .. }
|
||||
|
|
|
@ -275,7 +275,7 @@ impl Filler<'_> {
|
|||
| TerminatorKind::DropAndReplace { .. }
|
||||
| TerminatorKind::Assert { .. }
|
||||
| TerminatorKind::Yield { .. }
|
||||
| TerminatorKind::GeneratorDrop
|
||||
| TerminatorKind::CoroutineDrop
|
||||
| TerminatorKind::FalseEdge { .. }
|
||||
| TerminatorKind::FalseUnwind { .. } => (),
|
||||
}
|
||||
|
|
|
@ -328,7 +328,7 @@ fn foo() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn generator_yield_return_coerce() {
|
||||
fn coroutine_yield_return_coerce() {
|
||||
check_no_mismatches(
|
||||
r#"
|
||||
fn test() {
|
||||
|
|
|
@ -1949,11 +1949,11 @@ fn closure_return_inferred() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn generator_types_inferred() {
|
||||
fn coroutine_types_inferred() {
|
||||
check_infer(
|
||||
r#"
|
||||
//- minicore: generator, deref
|
||||
use core::ops::{Generator, GeneratorState};
|
||||
//- minicore: coroutine, deref
|
||||
use core::ops::{Coroutine, CoroutineState};
|
||||
use core::pin::Pin;
|
||||
|
||||
fn f(v: i64) {}
|
||||
|
@ -1966,8 +1966,8 @@ fn test() {
|
|||
};
|
||||
|
||||
match Pin::new(&mut g).resume(0usize) {
|
||||
GeneratorState::Yielded(y) => { f(y); }
|
||||
GeneratorState::Complete(r) => {}
|
||||
CoroutineState::Yielded(y) => { f(y); }
|
||||
CoroutineState::Complete(r) => {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
@ -1992,17 +1992,17 @@ fn test() {
|
|||
225..360 'match ... }': ()
|
||||
231..239 'Pin::new': fn new<&mut |usize| yields i64 -> &str>(&mut |usize| yields i64 -> &str) -> Pin<&mut |usize| yields i64 -> &str>
|
||||
231..247 'Pin::n...mut g)': Pin<&mut |usize| yields i64 -> &str>
|
||||
231..262 'Pin::n...usize)': GeneratorState<i64, &str>
|
||||
231..262 'Pin::n...usize)': CoroutineState<i64, &str>
|
||||
240..246 '&mut g': &mut |usize| yields i64 -> &str
|
||||
245..246 'g': |usize| yields i64 -> &str
|
||||
255..261 '0usize': usize
|
||||
273..299 'Genera...ded(y)': GeneratorState<i64, &str>
|
||||
273..299 'Corout...ded(y)': CoroutineState<i64, &str>
|
||||
297..298 'y': i64
|
||||
303..312 '{ f(y); }': ()
|
||||
305..306 'f': fn f(i64)
|
||||
305..309 'f(y)': ()
|
||||
307..308 'y': i64
|
||||
321..348 'Genera...ete(r)': GeneratorState<i64, &str>
|
||||
321..348 'Corout...ete(r)': CoroutineState<i64, &str>
|
||||
346..347 'r': &str
|
||||
352..354 '{}': ()
|
||||
"#]],
|
||||
|
@ -2010,11 +2010,11 @@ fn test() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn generator_resume_yield_return_unit() {
|
||||
fn coroutine_resume_yield_return_unit() {
|
||||
check_no_mismatches(
|
||||
r#"
|
||||
//- minicore: generator, deref
|
||||
use core::ops::{Generator, GeneratorState};
|
||||
//- minicore: coroutine, deref
|
||||
use core::ops::{Coroutine, CoroutineState};
|
||||
use core::pin::Pin;
|
||||
fn test() {
|
||||
let mut g = || {
|
||||
|
@ -2022,8 +2022,8 @@ fn test() {
|
|||
};
|
||||
|
||||
match Pin::new(&mut g).resume(()) {
|
||||
GeneratorState::Yielded(()) => {}
|
||||
GeneratorState::Complete(()) => {}
|
||||
CoroutineState::Yielded(()) => {}
|
||||
CoroutineState::Complete(()) => {}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
|
|
|
@ -285,21 +285,21 @@ impl Variant {
|
|||
check_assist(
|
||||
generate_enum_is_method,
|
||||
r#"
|
||||
enum GeneratorState {
|
||||
enum CoroutineState {
|
||||
Yielded,
|
||||
Complete$0,
|
||||
Major,
|
||||
}"#,
|
||||
r#"enum GeneratorState {
|
||||
r#"enum CoroutineState {
|
||||
Yielded,
|
||||
Complete,
|
||||
Major,
|
||||
}
|
||||
|
||||
impl GeneratorState {
|
||||
/// Returns `true` if the generator state is [`Complete`].
|
||||
impl CoroutineState {
|
||||
/// Returns `true` if the coroutine state is [`Complete`].
|
||||
///
|
||||
/// [`Complete`]: GeneratorState::Complete
|
||||
/// [`Complete`]: CoroutineState::Complete
|
||||
#[must_use]
|
||||
fn is_complete(&self) -> bool {
|
||||
matches!(self, Self::Complete)
|
||||
|
|
|
@ -120,7 +120,7 @@ impl RootDatabase {
|
|||
hir::db::InternImplTraitIdQuery
|
||||
hir::db::InternTypeOrConstParamIdQuery
|
||||
hir::db::InternClosureQuery
|
||||
hir::db::InternGeneratorQuery
|
||||
hir::db::InternCoroutineQuery
|
||||
hir::db::AssociatedTyDataQuery
|
||||
hir::db::TraitDatumQuery
|
||||
hir::db::StructDatumQuery
|
||||
|
|
|
@ -283,7 +283,7 @@ impl RootDatabase {
|
|||
// hir_db::InternImplTraitIdQuery
|
||||
// hir_db::InternTypeOrConstParamIdQuery
|
||||
// hir_db::InternClosureQuery
|
||||
// hir_db::InternGeneratorQuery
|
||||
// hir_db::InternCoroutineQuery
|
||||
hir_db::AssociatedTyDataQuery
|
||||
hir_db::TraitDatumQuery
|
||||
hir_db::StructDatumQuery
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
//! fn:
|
||||
//! from: sized
|
||||
//! future: pin
|
||||
//! generator: pin
|
||||
//! coroutine: pin
|
||||
//! hash:
|
||||
//! include:
|
||||
//! index: sized
|
||||
|
@ -798,26 +798,26 @@ pub mod ops {
|
|||
// endregion:builtin_impls
|
||||
// endregion:add
|
||||
|
||||
// region:generator
|
||||
mod generator {
|
||||
// region:coroutine
|
||||
mod coroutine {
|
||||
use crate::pin::Pin;
|
||||
|
||||
#[lang = "generator"]
|
||||
pub trait Generator<R = ()> {
|
||||
#[lang = "coroutine"]
|
||||
pub trait Coroutine<R = ()> {
|
||||
type Yield;
|
||||
#[lang = "generator_return"]
|
||||
#[lang = "coroutine_return"]
|
||||
type Return;
|
||||
fn resume(self: Pin<&mut Self>, arg: R) -> GeneratorState<Self::Yield, Self::Return>;
|
||||
fn resume(self: Pin<&mut Self>, arg: R) -> CoroutineState<Self::Yield, Self::Return>;
|
||||
}
|
||||
|
||||
#[lang = "generator_state"]
|
||||
pub enum GeneratorState<Y, R> {
|
||||
#[lang = "coroutine_state"]
|
||||
pub enum CoroutineState<Y, R> {
|
||||
Yielded(Y),
|
||||
Complete(R),
|
||||
}
|
||||
}
|
||||
pub use self::generator::{Generator, GeneratorState};
|
||||
// endregion:generator
|
||||
pub use self::coroutine::{Coroutine, CoroutineState};
|
||||
// endregion:coroutine
|
||||
}
|
||||
|
||||
// region:eq
|
||||
|
|
Loading…
Reference in a new issue