coro_kind -> coroutine_kind
This commit is contained in:
parent
96bb542a31
commit
2806c2df7b
23 changed files with 100 additions and 75 deletions
|
@ -1311,7 +1311,7 @@ pub struct Closure {
|
||||||
pub binder: ClosureBinder,
|
pub binder: ClosureBinder,
|
||||||
pub capture_clause: CaptureBy,
|
pub capture_clause: CaptureBy,
|
||||||
pub constness: Const,
|
pub constness: Const,
|
||||||
pub coro_kind: Option<CoroutineKind>,
|
pub coroutine_kind: Option<CoroutineKind>,
|
||||||
pub movability: Movability,
|
pub movability: Movability,
|
||||||
pub fn_decl: P<FnDecl>,
|
pub fn_decl: P<FnDecl>,
|
||||||
pub body: P<Expr>,
|
pub body: P<Expr>,
|
||||||
|
@ -2840,7 +2840,7 @@ pub struct FnHeader {
|
||||||
/// The `unsafe` keyword, if any
|
/// The `unsafe` keyword, if any
|
||||||
pub unsafety: Unsafe,
|
pub unsafety: Unsafe,
|
||||||
/// Whether this is `async`, `gen`, or nothing.
|
/// Whether this is `async`, `gen`, or nothing.
|
||||||
pub coro_kind: Option<CoroutineKind>,
|
pub coroutine_kind: Option<CoroutineKind>,
|
||||||
/// The `const` keyword, if any
|
/// The `const` keyword, if any
|
||||||
pub constness: Const,
|
pub constness: Const,
|
||||||
/// The `extern` keyword and corresponding ABI string, if any
|
/// The `extern` keyword and corresponding ABI string, if any
|
||||||
|
@ -2850,9 +2850,9 @@ pub struct FnHeader {
|
||||||
impl FnHeader {
|
impl FnHeader {
|
||||||
/// Does this function header have any qualifiers or is it empty?
|
/// Does this function header have any qualifiers or is it empty?
|
||||||
pub fn has_qualifiers(&self) -> bool {
|
pub fn has_qualifiers(&self) -> bool {
|
||||||
let Self { unsafety, coro_kind, constness, ext } = self;
|
let Self { unsafety, coroutine_kind, constness, ext } = self;
|
||||||
matches!(unsafety, Unsafe::Yes(_))
|
matches!(unsafety, Unsafe::Yes(_))
|
||||||
|| coro_kind.is_some()
|
|| coroutine_kind.is_some()
|
||||||
|| matches!(constness, Const::Yes(_))
|
|| matches!(constness, Const::Yes(_))
|
||||||
|| !matches!(ext, Extern::None)
|
|| !matches!(ext, Extern::None)
|
||||||
}
|
}
|
||||||
|
@ -2860,7 +2860,12 @@ impl FnHeader {
|
||||||
|
|
||||||
impl Default for FnHeader {
|
impl Default for FnHeader {
|
||||||
fn default() -> FnHeader {
|
fn default() -> FnHeader {
|
||||||
FnHeader { unsafety: Unsafe::No, coro_kind: None, constness: Const::No, ext: Extern::None }
|
FnHeader {
|
||||||
|
unsafety: Unsafe::No,
|
||||||
|
coroutine_kind: None,
|
||||||
|
constness: Const::No,
|
||||||
|
ext: Extern::None,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -121,8 +121,8 @@ pub trait MutVisitor: Sized {
|
||||||
noop_visit_fn_decl(d, self);
|
noop_visit_fn_decl(d, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_coro_kind(&mut self, a: &mut CoroutineKind) {
|
fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) {
|
||||||
noop_visit_coro_kind(a, self);
|
noop_visit_coroutine_kind(a, self);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_closure_binder(&mut self, b: &mut ClosureBinder) {
|
fn visit_closure_binder(&mut self, b: &mut ClosureBinder) {
|
||||||
|
@ -871,8 +871,8 @@ pub fn noop_visit_closure_binder<T: MutVisitor>(binder: &mut ClosureBinder, vis:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn noop_visit_coro_kind<T: MutVisitor>(coro_kind: &mut CoroutineKind, vis: &mut T) {
|
pub fn noop_visit_coroutine_kind<T: MutVisitor>(coroutine_kind: &mut CoroutineKind, vis: &mut T) {
|
||||||
match coro_kind {
|
match coroutine_kind {
|
||||||
CoroutineKind::Async { span, closure_id, return_impl_trait_id }
|
CoroutineKind::Async { span, closure_id, return_impl_trait_id }
|
||||||
| CoroutineKind::Gen { span, closure_id, return_impl_trait_id } => {
|
| CoroutineKind::Gen { span, closure_id, return_impl_trait_id } => {
|
||||||
vis.visit_span(span);
|
vis.visit_span(span);
|
||||||
|
@ -1171,9 +1171,9 @@ fn visit_const_item<T: MutVisitor>(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
|
pub fn noop_visit_fn_header<T: MutVisitor>(header: &mut FnHeader, vis: &mut T) {
|
||||||
let FnHeader { unsafety, coro_kind, constness, ext: _ } = header;
|
let FnHeader { unsafety, coroutine_kind, constness, ext: _ } = header;
|
||||||
visit_constness(constness, vis);
|
visit_constness(constness, vis);
|
||||||
coro_kind.as_mut().map(|coro_kind| vis.visit_coro_kind(coro_kind));
|
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
|
||||||
visit_unsafety(unsafety, vis);
|
visit_unsafety(unsafety, vis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1407,7 +1407,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
||||||
binder,
|
binder,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
constness,
|
constness,
|
||||||
coro_kind,
|
coroutine_kind,
|
||||||
movability: _,
|
movability: _,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
body,
|
body,
|
||||||
|
@ -1416,7 +1416,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
||||||
}) => {
|
}) => {
|
||||||
vis.visit_closure_binder(binder);
|
vis.visit_closure_binder(binder);
|
||||||
visit_constness(constness, vis);
|
visit_constness(constness, vis);
|
||||||
coro_kind.as_mut().map(|coro_kind| vis.visit_coro_kind(coro_kind));
|
coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind));
|
||||||
vis.visit_capture_by(capture_clause);
|
vis.visit_capture_by(capture_clause);
|
||||||
vis.visit_fn_decl(fn_decl);
|
vis.visit_fn_decl(fn_decl);
|
||||||
vis.visit_expr(body);
|
vis.visit_expr(body);
|
||||||
|
|
|
@ -861,7 +861,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
|
||||||
ExprKind::Closure(box Closure {
|
ExprKind::Closure(box Closure {
|
||||||
binder,
|
binder,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
coro_kind: _,
|
coroutine_kind: _,
|
||||||
constness: _,
|
constness: _,
|
||||||
movability: _,
|
movability: _,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
|
|
|
@ -195,13 +195,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
binder,
|
binder,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
constness,
|
constness,
|
||||||
coro_kind,
|
coroutine_kind,
|
||||||
movability,
|
movability,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
body,
|
body,
|
||||||
fn_decl_span,
|
fn_decl_span,
|
||||||
fn_arg_span,
|
fn_arg_span,
|
||||||
}) => match coro_kind {
|
}) => match coroutine_kind {
|
||||||
Some(
|
Some(
|
||||||
CoroutineKind::Async { closure_id, .. }
|
CoroutineKind::Async { closure_id, .. }
|
||||||
| CoroutineKind::Gen { closure_id, .. },
|
| CoroutineKind::Gen { closure_id, .. },
|
||||||
|
|
|
@ -206,19 +206,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
// `impl Future<Output = T>` here because lower_body
|
// `impl Future<Output = T>` here because lower_body
|
||||||
// only cares about the input argument patterns in the function
|
// only cares about the input argument patterns in the function
|
||||||
// declaration (decl), not the return types.
|
// declaration (decl), not the return types.
|
||||||
let coro_kind = header.coro_kind;
|
let coroutine_kind = header.coroutine_kind;
|
||||||
let body_id = this.lower_maybe_coroutine_body(
|
let body_id = this.lower_maybe_coroutine_body(
|
||||||
span,
|
span,
|
||||||
hir_id,
|
hir_id,
|
||||||
decl,
|
decl,
|
||||||
coro_kind,
|
coroutine_kind,
|
||||||
body.as_deref(),
|
body.as_deref(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let itctx = ImplTraitContext::Universal;
|
let itctx = ImplTraitContext::Universal;
|
||||||
let (generics, decl) =
|
let (generics, decl) =
|
||||||
this.lower_generics(generics, header.constness, id, &itctx, |this| {
|
this.lower_generics(generics, header.constness, id, &itctx, |this| {
|
||||||
this.lower_fn_decl(decl, id, *fn_sig_span, FnDeclKind::Fn, coro_kind)
|
this.lower_fn_decl(
|
||||||
|
decl,
|
||||||
|
id,
|
||||||
|
*fn_sig_span,
|
||||||
|
FnDeclKind::Fn,
|
||||||
|
coroutine_kind,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
let sig = hir::FnSig {
|
let sig = hir::FnSig {
|
||||||
decl,
|
decl,
|
||||||
|
@ -734,7 +740,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
sig,
|
sig,
|
||||||
i.id,
|
i.id,
|
||||||
FnDeclKind::Trait,
|
FnDeclKind::Trait,
|
||||||
sig.header.coro_kind,
|
sig.header.coroutine_kind,
|
||||||
);
|
);
|
||||||
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)), false)
|
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)), false)
|
||||||
}
|
}
|
||||||
|
@ -743,7 +749,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
i.span,
|
i.span,
|
||||||
hir_id,
|
hir_id,
|
||||||
&sig.decl,
|
&sig.decl,
|
||||||
sig.header.coro_kind,
|
sig.header.coroutine_kind,
|
||||||
Some(body),
|
Some(body),
|
||||||
);
|
);
|
||||||
let (generics, sig) = self.lower_method_sig(
|
let (generics, sig) = self.lower_method_sig(
|
||||||
|
@ -751,7 +757,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
sig,
|
sig,
|
||||||
i.id,
|
i.id,
|
||||||
FnDeclKind::Trait,
|
FnDeclKind::Trait,
|
||||||
sig.header.coro_kind,
|
sig.header.coroutine_kind,
|
||||||
);
|
);
|
||||||
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)), true)
|
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)), true)
|
||||||
}
|
}
|
||||||
|
@ -844,7 +850,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
i.span,
|
i.span,
|
||||||
hir_id,
|
hir_id,
|
||||||
&sig.decl,
|
&sig.decl,
|
||||||
sig.header.coro_kind,
|
sig.header.coroutine_kind,
|
||||||
body.as_deref(),
|
body.as_deref(),
|
||||||
);
|
);
|
||||||
let (generics, sig) = self.lower_method_sig(
|
let (generics, sig) = self.lower_method_sig(
|
||||||
|
@ -852,7 +858,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
sig,
|
sig,
|
||||||
i.id,
|
i.id,
|
||||||
if self.is_in_trait_impl { FnDeclKind::Impl } else { FnDeclKind::Inherent },
|
if self.is_in_trait_impl { FnDeclKind::Impl } else { FnDeclKind::Inherent },
|
||||||
sig.header.coro_kind,
|
sig.header.coroutine_kind,
|
||||||
);
|
);
|
||||||
|
|
||||||
(generics, hir::ImplItemKind::Fn(sig, body_id))
|
(generics, hir::ImplItemKind::Fn(sig, body_id))
|
||||||
|
@ -1023,13 +1029,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
span: Span,
|
span: Span,
|
||||||
fn_id: hir::HirId,
|
fn_id: hir::HirId,
|
||||||
decl: &FnDecl,
|
decl: &FnDecl,
|
||||||
coro_kind: Option<CoroutineKind>,
|
coroutine_kind: Option<CoroutineKind>,
|
||||||
body: Option<&Block>,
|
body: Option<&Block>,
|
||||||
) -> hir::BodyId {
|
) -> hir::BodyId {
|
||||||
let (Some(coro_kind), Some(body)) = (coro_kind, body) else {
|
let (Some(coroutine_kind), Some(body)) = (coroutine_kind, body) else {
|
||||||
return self.lower_fn_body_block(span, decl, body);
|
return self.lower_fn_body_block(span, decl, body);
|
||||||
};
|
};
|
||||||
let closure_id = match coro_kind {
|
let closure_id = match coroutine_kind {
|
||||||
CoroutineKind::Async { closure_id, .. } | CoroutineKind::Gen { closure_id, .. } => {
|
CoroutineKind::Async { closure_id, .. } | CoroutineKind::Gen { closure_id, .. } => {
|
||||||
closure_id
|
closure_id
|
||||||
}
|
}
|
||||||
|
@ -1200,7 +1206,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
|
|
||||||
this.expr_block(body)
|
this.expr_block(body)
|
||||||
};
|
};
|
||||||
let coroutine_expr = match coro_kind {
|
// FIXME(gen_blocks): Consider unifying the `make_*_expr` functions.
|
||||||
|
let coroutine_expr = match coroutine_kind {
|
||||||
CoroutineKind::Async { .. } => this.make_async_expr(
|
CoroutineKind::Async { .. } => this.make_async_expr(
|
||||||
CaptureBy::Value { move_kw: rustc_span::DUMMY_SP },
|
CaptureBy::Value { move_kw: rustc_span::DUMMY_SP },
|
||||||
closure_id,
|
closure_id,
|
||||||
|
@ -1233,19 +1240,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
sig: &FnSig,
|
sig: &FnSig,
|
||||||
id: NodeId,
|
id: NodeId,
|
||||||
kind: FnDeclKind,
|
kind: FnDeclKind,
|
||||||
coro_kind: Option<CoroutineKind>,
|
coroutine_kind: Option<CoroutineKind>,
|
||||||
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
|
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
|
||||||
let header = self.lower_fn_header(sig.header);
|
let header = self.lower_fn_header(sig.header);
|
||||||
let itctx = ImplTraitContext::Universal;
|
let itctx = ImplTraitContext::Universal;
|
||||||
let (generics, decl) =
|
let (generics, decl) =
|
||||||
self.lower_generics(generics, sig.header.constness, id, &itctx, |this| {
|
self.lower_generics(generics, sig.header.constness, id, &itctx, |this| {
|
||||||
this.lower_fn_decl(&sig.decl, id, sig.span, kind, coro_kind)
|
this.lower_fn_decl(&sig.decl, id, sig.span, kind, coroutine_kind)
|
||||||
});
|
});
|
||||||
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
|
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
|
fn lower_fn_header(&mut self, h: FnHeader) -> hir::FnHeader {
|
||||||
let asyncness = if let Some(CoroutineKind::Async { span, .. }) = h.coro_kind {
|
let asyncness = if let Some(CoroutineKind::Async { span, .. }) = h.coroutine_kind {
|
||||||
hir::IsAsync::Async(span)
|
hir::IsAsync::Async(span)
|
||||||
} else {
|
} else {
|
||||||
hir::IsAsync::NotAsync
|
hir::IsAsync::NotAsync
|
||||||
|
|
|
@ -1271,7 +1271,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
|
||||||
// Functions cannot both be `const async` or `const gen`
|
// Functions cannot both be `const async` or `const gen`
|
||||||
if let Some(&FnHeader {
|
if let Some(&FnHeader {
|
||||||
constness: Const::Yes(cspan),
|
constness: Const::Yes(cspan),
|
||||||
coro_kind:
|
coroutine_kind:
|
||||||
Some(
|
Some(
|
||||||
CoroutineKind::Async { span: aspan, .. }
|
CoroutineKind::Async { span: aspan, .. }
|
||||||
| CoroutineKind::Gen { span: aspan, .. },
|
| CoroutineKind::Gen { span: aspan, .. },
|
||||||
|
|
|
@ -1490,8 +1490,8 @@ impl<'a> State<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_coro_kind(&mut self, coro_kind: ast::CoroutineKind) {
|
fn print_coroutine_kind(&mut self, coroutine_kind: ast::CoroutineKind) {
|
||||||
match coro_kind {
|
match coroutine_kind {
|
||||||
ast::CoroutineKind::Gen { .. } => {
|
ast::CoroutineKind::Gen { .. } => {
|
||||||
self.word_nbsp("gen");
|
self.word_nbsp("gen");
|
||||||
}
|
}
|
||||||
|
@ -1690,7 +1690,7 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
fn print_fn_header_info(&mut self, header: ast::FnHeader) {
|
||||||
self.print_constness(header.constness);
|
self.print_constness(header.constness);
|
||||||
header.coro_kind.map(|coro_kind| self.print_coro_kind(coro_kind));
|
header.coroutine_kind.map(|coroutine_kind| self.print_coroutine_kind(coroutine_kind));
|
||||||
self.print_unsafety(header.unsafety);
|
self.print_unsafety(header.unsafety);
|
||||||
|
|
||||||
match header.ext {
|
match header.ext {
|
||||||
|
|
|
@ -413,7 +413,7 @@ impl<'a> State<'a> {
|
||||||
binder,
|
binder,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
constness,
|
constness,
|
||||||
coro_kind,
|
coroutine_kind,
|
||||||
movability,
|
movability,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
body,
|
body,
|
||||||
|
@ -423,7 +423,7 @@ impl<'a> State<'a> {
|
||||||
self.print_closure_binder(binder);
|
self.print_closure_binder(binder);
|
||||||
self.print_constness(*constness);
|
self.print_constness(*constness);
|
||||||
self.print_movability(*movability);
|
self.print_movability(*movability);
|
||||||
coro_kind.map(|coro_kind| self.print_coro_kind(coro_kind));
|
coroutine_kind.map(|coroutine_kind| self.print_coroutine_kind(coroutine_kind));
|
||||||
self.print_capture_clause(*capture_clause);
|
self.print_capture_clause(*capture_clause);
|
||||||
|
|
||||||
self.print_fn_params_and_ret(fn_decl, true);
|
self.print_fn_params_and_ret(fn_decl, true);
|
||||||
|
|
|
@ -541,11 +541,11 @@ fn check_test_signature(
|
||||||
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
|
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "unsafe" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ast::CoroutineKind::Async { span, .. }) = f.sig.header.coro_kind {
|
if let Some(ast::CoroutineKind::Async { span, .. }) = f.sig.header.coroutine_kind {
|
||||||
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "async" }));
|
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "async" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ast::CoroutineKind::Gen { span, .. }) = f.sig.header.coro_kind {
|
if let Some(ast::CoroutineKind::Gen { span, .. }) = f.sig.header.coroutine_kind {
|
||||||
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "gen" }));
|
return Err(sd.emit_err(errors::TestBadFn { span: i.span, cause: span, kind: "gen" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -547,7 +547,7 @@ impl<'a> ExtCtxt<'a> {
|
||||||
binder: ast::ClosureBinder::NotPresent,
|
binder: ast::ClosureBinder::NotPresent,
|
||||||
capture_clause: ast::CaptureBy::Ref,
|
capture_clause: ast::CaptureBy::Ref,
|
||||||
constness: ast::Const::No,
|
constness: ast::Const::No,
|
||||||
coro_kind: None,
|
coroutine_kind: None,
|
||||||
movability: ast::Movability::Movable,
|
movability: ast::Movability::Movable,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
body,
|
body,
|
||||||
|
|
|
@ -165,7 +165,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||||
if let Some(
|
if let Some(
|
||||||
ast::CoroutineKind::Async { closure_id, .. }
|
ast::CoroutineKind::Async { closure_id, .. }
|
||||||
| ast::CoroutineKind::Gen { closure_id, .. },
|
| ast::CoroutineKind::Gen { closure_id, .. },
|
||||||
) = sig.header.coro_kind
|
) = sig.header.coroutine_kind
|
||||||
{
|
{
|
||||||
self.check_id(closure_id);
|
self.check_id(closure_id);
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
|
||||||
// it does not have a corresponding AST node
|
// it does not have a corresponding AST node
|
||||||
match e.kind {
|
match e.kind {
|
||||||
ast::ExprKind::Closure(box ast::Closure {
|
ast::ExprKind::Closure(box ast::Closure {
|
||||||
coro_kind:
|
coroutine_kind:
|
||||||
Some(
|
Some(
|
||||||
ast::CoroutineKind::Async { closure_id, .. }
|
ast::CoroutineKind::Async { closure_id, .. }
|
||||||
| ast::CoroutineKind::Gen { closure_id, .. },
|
| ast::CoroutineKind::Gen { closure_id, .. },
|
||||||
|
|
|
@ -2285,7 +2285,7 @@ impl<'a> Parser<'a> {
|
||||||
binder,
|
binder,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
constness,
|
constness,
|
||||||
coro_kind: asyncness,
|
coroutine_kind: asyncness,
|
||||||
movability,
|
movability,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
body,
|
body,
|
||||||
|
|
|
@ -2561,7 +2561,7 @@ impl<'a> Parser<'a> {
|
||||||
return Ok(FnHeader {
|
return Ok(FnHeader {
|
||||||
constness: recover_constness,
|
constness: recover_constness,
|
||||||
unsafety: recover_unsafety,
|
unsafety: recover_unsafety,
|
||||||
coro_kind: recover_asyncness,
|
coroutine_kind: recover_asyncness,
|
||||||
ext,
|
ext,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2571,13 +2571,13 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let coro_kind = match asyncness {
|
let coroutine_kind = match asyncness {
|
||||||
Some(CoroutineKind::Async { .. }) => asyncness,
|
Some(CoroutineKind::Async { .. }) => asyncness,
|
||||||
Some(CoroutineKind::Gen { .. }) => unreachable!("asycness cannot be Gen"),
|
Some(CoroutineKind::Gen { .. }) => unreachable!("asycness cannot be Gen"),
|
||||||
None => genness,
|
None => genness,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(FnHeader { constness, unsafety, coro_kind, ext })
|
Ok(FnHeader { constness, unsafety, coroutine_kind, ext })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the parameter list and result type of a function declaration.
|
/// Parses the parameter list and result type of a function declaration.
|
||||||
|
|
|
@ -598,7 +598,7 @@ impl<'a> Parser<'a> {
|
||||||
tokens: None,
|
tokens: None,
|
||||||
};
|
};
|
||||||
let span_start = self.token.span;
|
let span_start = self.token.span;
|
||||||
let ast::FnHeader { ext, unsafety, constness, coro_kind } =
|
let ast::FnHeader { ext, unsafety, constness, coroutine_kind } =
|
||||||
self.parse_fn_front_matter(&inherited_vis, Case::Sensitive)?;
|
self.parse_fn_front_matter(&inherited_vis, Case::Sensitive)?;
|
||||||
if self.may_recover() && self.token.kind == TokenKind::Lt {
|
if self.may_recover() && self.token.kind == TokenKind::Lt {
|
||||||
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
|
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
|
||||||
|
@ -611,7 +611,7 @@ impl<'a> Parser<'a> {
|
||||||
// cover it.
|
// cover it.
|
||||||
self.sess.emit_err(FnPointerCannotBeConst { span: whole_span, qualifier: span });
|
self.sess.emit_err(FnPointerCannotBeConst { span: whole_span, qualifier: span });
|
||||||
}
|
}
|
||||||
if let Some(ast::CoroutineKind::Async { span, .. }) = coro_kind {
|
if let Some(ast::CoroutineKind::Async { span, .. }) = coroutine_kind {
|
||||||
self.sess.emit_err(FnPointerCannotBeAsync { span: whole_span, qualifier: span });
|
self.sess.emit_err(FnPointerCannotBeAsync { span: whole_span, qualifier: span });
|
||||||
}
|
}
|
||||||
// FIXME(gen_blocks): emit a similar error for `gen fn()`
|
// FIXME(gen_blocks): emit a similar error for `gen fn()`
|
||||||
|
|
|
@ -158,7 +158,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
if let FnKind::Fn(_, _, sig, _, generics, body) = fn_kind {
|
if let FnKind::Fn(_, _, sig, _, generics, body) = fn_kind {
|
||||||
if let Some(
|
if let Some(
|
||||||
CoroutineKind::Async { closure_id, .. } | CoroutineKind::Gen { closure_id, .. },
|
CoroutineKind::Async { closure_id, .. } | CoroutineKind::Gen { closure_id, .. },
|
||||||
) = sig.header.coro_kind
|
) = sig.header.coroutine_kind
|
||||||
{
|
{
|
||||||
self.visit_generics(generics);
|
self.visit_generics(generics);
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
|
||||||
// Async closures desugar to closures inside of closures, so
|
// Async closures desugar to closures inside of closures, so
|
||||||
// we must create two defs.
|
// we must create two defs.
|
||||||
let closure_def = self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span);
|
let closure_def = self.create_def(expr.id, kw::Empty, DefKind::Closure, expr.span);
|
||||||
match closure.coro_kind {
|
match closure.coroutine_kind {
|
||||||
Some(
|
Some(
|
||||||
CoroutineKind::Async { closure_id, .. }
|
CoroutineKind::Async { closure_id, .. }
|
||||||
| CoroutineKind::Gen { closure_id, .. },
|
| CoroutineKind::Gen { closure_id, .. },
|
||||||
|
|
|
@ -916,8 +916,10 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
&sig.decl.output,
|
&sig.decl.output,
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some((coro_node_id, _)) =
|
if let Some((coro_node_id, _)) = sig
|
||||||
sig.header.coro_kind.map(|coro_kind| coro_kind.return_id())
|
.header
|
||||||
|
.coroutine_kind
|
||||||
|
.map(|coroutine_kind| coroutine_kind.return_id())
|
||||||
{
|
{
|
||||||
this.record_lifetime_params_for_impl_trait(coro_node_id);
|
this.record_lifetime_params_for_impl_trait(coro_node_id);
|
||||||
}
|
}
|
||||||
|
@ -942,8 +944,10 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
this.visit_generics(generics);
|
this.visit_generics(generics);
|
||||||
|
|
||||||
let declaration = &sig.decl;
|
let declaration = &sig.decl;
|
||||||
let coro_node_id =
|
let coro_node_id = sig
|
||||||
sig.header.coro_kind.map(|coro_kind| coro_kind.return_id());
|
.header
|
||||||
|
.coroutine_kind
|
||||||
|
.map(|coroutine_kind| coroutine_kind.return_id());
|
||||||
|
|
||||||
this.with_lifetime_rib(
|
this.with_lifetime_rib(
|
||||||
LifetimeRibKind::AnonymousCreateParameter {
|
LifetimeRibKind::AnonymousCreateParameter {
|
||||||
|
@ -4294,7 +4298,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
//
|
//
|
||||||
// Similarly, `gen |x| ...` gets desugared to `|x| gen {...}`, so we handle that too.
|
// Similarly, `gen |x| ...` gets desugared to `|x| gen {...}`, so we handle that too.
|
||||||
ExprKind::Closure(box ast::Closure {
|
ExprKind::Closure(box ast::Closure {
|
||||||
coro_kind: Some(_),
|
coroutine_kind: Some(_),
|
||||||
ref fn_decl,
|
ref fn_decl,
|
||||||
ref body,
|
ref body,
|
||||||
..
|
..
|
||||||
|
|
|
@ -69,7 +69,7 @@ pub fn check(
|
||||||
if !ignore {
|
if !ignore {
|
||||||
get_test_spans(&item, &mut test_attr_spans);
|
get_test_spans(&item, &mut test_attr_spans);
|
||||||
}
|
}
|
||||||
let is_async = matches!(sig.header.coro_kind, Some(CoroutineKind::Async { .. }));
|
let is_async = matches!(sig.header.coroutine_kind, Some(CoroutineKind::Async { .. }));
|
||||||
let returns_nothing = match &sig.decl.output {
|
let returns_nothing = match &sig.decl.output {
|
||||||
FnRetTy::Default(..) => true,
|
FnRetTy::Default(..) => true,
|
||||||
FnRetTy::Ty(ty) if ty.kind.is_unit() => true,
|
FnRetTy::Ty(ty) if ty.kind.is_unit() => true,
|
||||||
|
|
|
@ -188,7 +188,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
||||||
Closure(box ast::Closure {
|
Closure(box ast::Closure {
|
||||||
binder: lb,
|
binder: lb,
|
||||||
capture_clause: lc,
|
capture_clause: lc,
|
||||||
coro_kind: la,
|
coroutine_kind: la,
|
||||||
movability: lm,
|
movability: lm,
|
||||||
fn_decl: lf,
|
fn_decl: lf,
|
||||||
body: le,
|
body: le,
|
||||||
|
@ -197,7 +197,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
|
||||||
Closure(box ast::Closure {
|
Closure(box ast::Closure {
|
||||||
binder: rb,
|
binder: rb,
|
||||||
capture_clause: rc,
|
capture_clause: rc,
|
||||||
coro_kind: ra,
|
coroutine_kind: ra,
|
||||||
movability: rm,
|
movability: rm,
|
||||||
fn_decl: rf,
|
fn_decl: rf,
|
||||||
body: re,
|
body: re,
|
||||||
|
@ -563,7 +563,7 @@ pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool {
|
||||||
eq_fn_decl(&l.decl, &r.decl) && eq_fn_header(&l.header, &r.header)
|
eq_fn_decl(&l.decl, &r.decl) && eq_fn_header(&l.header, &r.header)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eq_opt_coro_kind(l: Option<CoroutineKind>, r: Option<CoroutineKind>) -> bool {
|
fn eq_opt_coroutine_kind(l: Option<CoroutineKind>, r: Option<CoroutineKind>) -> bool {
|
||||||
match (l, r) {
|
match (l, r) {
|
||||||
(Some(CoroutineKind::Async { .. }), Some(CoroutineKind::Async { .. }))
|
(Some(CoroutineKind::Async { .. }), Some(CoroutineKind::Async { .. }))
|
||||||
| (Some(CoroutineKind::Gen { .. }), Some(CoroutineKind::Gen { .. })) => true,
|
| (Some(CoroutineKind::Gen { .. }), Some(CoroutineKind::Gen { .. })) => true,
|
||||||
|
@ -574,7 +574,7 @@ fn eq_opt_coro_kind(l: Option<CoroutineKind>, r: Option<CoroutineKind>) -> bool
|
||||||
|
|
||||||
pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
|
pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
|
||||||
matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No)
|
matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No)
|
||||||
&& eq_opt_coro_kind(l.coro_kind, r.coro_kind)
|
&& eq_opt_coroutine_kind(l.coroutine_kind, r.coroutine_kind)
|
||||||
&& matches!(l.constness, Const::No) == matches!(r.constness, Const::No)
|
&& matches!(l.constness, Const::No) == matches!(r.constness, Const::No)
|
||||||
&& eq_ext(&l.ext, &r.ext)
|
&& eq_ext(&l.ext, &r.ext)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub(crate) fn rewrite_closure(
|
||||||
binder: &ast::ClosureBinder,
|
binder: &ast::ClosureBinder,
|
||||||
constness: ast::Const,
|
constness: ast::Const,
|
||||||
capture: ast::CaptureBy,
|
capture: ast::CaptureBy,
|
||||||
coro_kind: &Option<ast::CoroutineKind>,
|
coroutine_kind: &Option<ast::CoroutineKind>,
|
||||||
movability: ast::Movability,
|
movability: ast::Movability,
|
||||||
fn_decl: &ast::FnDecl,
|
fn_decl: &ast::FnDecl,
|
||||||
body: &ast::Expr,
|
body: &ast::Expr,
|
||||||
|
@ -40,7 +40,16 @@ pub(crate) fn rewrite_closure(
|
||||||
debug!("rewrite_closure {:?}", body);
|
debug!("rewrite_closure {:?}", body);
|
||||||
|
|
||||||
let (prefix, extra_offset) = rewrite_closure_fn_decl(
|
let (prefix, extra_offset) = rewrite_closure_fn_decl(
|
||||||
binder, constness, capture, coro_kind, movability, fn_decl, body, span, context, shape,
|
binder,
|
||||||
|
constness,
|
||||||
|
capture,
|
||||||
|
coroutine_kind,
|
||||||
|
movability,
|
||||||
|
fn_decl,
|
||||||
|
body,
|
||||||
|
span,
|
||||||
|
context,
|
||||||
|
shape,
|
||||||
)?;
|
)?;
|
||||||
// 1 = space between `|...|` and body.
|
// 1 = space between `|...|` and body.
|
||||||
let body_shape = shape.offset_left(extra_offset)?;
|
let body_shape = shape.offset_left(extra_offset)?;
|
||||||
|
@ -233,7 +242,7 @@ fn rewrite_closure_fn_decl(
|
||||||
binder: &ast::ClosureBinder,
|
binder: &ast::ClosureBinder,
|
||||||
constness: ast::Const,
|
constness: ast::Const,
|
||||||
capture: ast::CaptureBy,
|
capture: ast::CaptureBy,
|
||||||
coro_kind: &Option<ast::CoroutineKind>,
|
coroutine_kind: &Option<ast::CoroutineKind>,
|
||||||
movability: ast::Movability,
|
movability: ast::Movability,
|
||||||
fn_decl: &ast::FnDecl,
|
fn_decl: &ast::FnDecl,
|
||||||
body: &ast::Expr,
|
body: &ast::Expr,
|
||||||
|
@ -263,7 +272,7 @@ fn rewrite_closure_fn_decl(
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
let coro = match coro_kind {
|
let coro = match coroutine_kind {
|
||||||
Some(ast::CoroutineKind::Async { .. }) => "async ",
|
Some(ast::CoroutineKind::Async { .. }) => "async ",
|
||||||
Some(ast::CoroutineKind::Gen { .. }) => "gen ",
|
Some(ast::CoroutineKind::Gen { .. }) => "gen ",
|
||||||
None => "",
|
None => "",
|
||||||
|
@ -343,7 +352,7 @@ pub(crate) fn rewrite_last_closure(
|
||||||
ref binder,
|
ref binder,
|
||||||
constness,
|
constness,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
ref coro_kind,
|
ref coroutine_kind,
|
||||||
movability,
|
movability,
|
||||||
ref fn_decl,
|
ref fn_decl,
|
||||||
ref body,
|
ref body,
|
||||||
|
@ -364,7 +373,7 @@ pub(crate) fn rewrite_last_closure(
|
||||||
binder,
|
binder,
|
||||||
constness,
|
constness,
|
||||||
capture_clause,
|
capture_clause,
|
||||||
coro_kind,
|
coroutine_kind,
|
||||||
movability,
|
movability,
|
||||||
fn_decl,
|
fn_decl,
|
||||||
body,
|
body,
|
||||||
|
|
|
@ -212,7 +212,7 @@ pub(crate) fn format_expr(
|
||||||
&cl.binder,
|
&cl.binder,
|
||||||
cl.constness,
|
cl.constness,
|
||||||
cl.capture_clause,
|
cl.capture_clause,
|
||||||
&cl.coro_kind,
|
&cl.coroutine_kind,
|
||||||
cl.movability,
|
cl.movability,
|
||||||
&cl.fn_decl,
|
&cl.fn_decl,
|
||||||
&cl.body,
|
&cl.body,
|
||||||
|
|
|
@ -287,7 +287,7 @@ pub(crate) struct FnSig<'a> {
|
||||||
decl: &'a ast::FnDecl,
|
decl: &'a ast::FnDecl,
|
||||||
generics: &'a ast::Generics,
|
generics: &'a ast::Generics,
|
||||||
ext: ast::Extern,
|
ext: ast::Extern,
|
||||||
coro_kind: Cow<'a, Option<ast::CoroutineKind>>,
|
coroutine_kind: Cow<'a, Option<ast::CoroutineKind>>,
|
||||||
constness: ast::Const,
|
constness: ast::Const,
|
||||||
defaultness: ast::Defaultness,
|
defaultness: ast::Defaultness,
|
||||||
unsafety: ast::Unsafe,
|
unsafety: ast::Unsafe,
|
||||||
|
@ -302,7 +302,7 @@ impl<'a> FnSig<'a> {
|
||||||
) -> FnSig<'a> {
|
) -> FnSig<'a> {
|
||||||
FnSig {
|
FnSig {
|
||||||
unsafety: method_sig.header.unsafety,
|
unsafety: method_sig.header.unsafety,
|
||||||
coro_kind: Cow::Borrowed(&method_sig.header.coro_kind),
|
coroutine_kind: Cow::Borrowed(&method_sig.header.coroutine_kind),
|
||||||
constness: method_sig.header.constness,
|
constness: method_sig.header.constness,
|
||||||
defaultness: ast::Defaultness::Final,
|
defaultness: ast::Defaultness::Final,
|
||||||
ext: method_sig.header.ext,
|
ext: method_sig.header.ext,
|
||||||
|
@ -328,7 +328,7 @@ impl<'a> FnSig<'a> {
|
||||||
generics,
|
generics,
|
||||||
ext: fn_sig.header.ext,
|
ext: fn_sig.header.ext,
|
||||||
constness: fn_sig.header.constness,
|
constness: fn_sig.header.constness,
|
||||||
coro_kind: Cow::Borrowed(&fn_sig.header.coro_kind),
|
coroutine_kind: Cow::Borrowed(&fn_sig.header.coroutine_kind),
|
||||||
defaultness,
|
defaultness,
|
||||||
unsafety: fn_sig.header.unsafety,
|
unsafety: fn_sig.header.unsafety,
|
||||||
visibility: vis,
|
visibility: vis,
|
||||||
|
@ -343,8 +343,8 @@ impl<'a> FnSig<'a> {
|
||||||
result.push_str(&*format_visibility(context, self.visibility));
|
result.push_str(&*format_visibility(context, self.visibility));
|
||||||
result.push_str(format_defaultness(self.defaultness));
|
result.push_str(format_defaultness(self.defaultness));
|
||||||
result.push_str(format_constness(self.constness));
|
result.push_str(format_constness(self.constness));
|
||||||
self.coro_kind
|
self.coroutine_kind
|
||||||
.map(|coro_kind| result.push_str(format_coro(&coro_kind)));
|
.map(|coroutine_kind| result.push_str(format_coro(&coroutine_kind)));
|
||||||
result.push_str(format_unsafety(self.unsafety));
|
result.push_str(format_unsafety(self.unsafety));
|
||||||
result.push_str(&format_extern(
|
result.push_str(&format_extern(
|
||||||
self.ext,
|
self.ext,
|
||||||
|
|
|
@ -75,8 +75,8 @@ pub(crate) fn format_visibility(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn format_coro(coro_kind: &ast::CoroutineKind) -> &'static str {
|
pub(crate) fn format_coro(coroutine_kind: &ast::CoroutineKind) -> &'static str {
|
||||||
match coro_kind {
|
match coroutine_kind {
|
||||||
ast::CoroutineKind::Async { .. } => "async ",
|
ast::CoroutineKind::Async { .. } => "async ",
|
||||||
ast::CoroutineKind::Gen { .. } => "gen ",
|
ast::CoroutineKind::Gen { .. } => "gen ",
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
|
||||||
binder: ClosureBinder::NotPresent,
|
binder: ClosureBinder::NotPresent,
|
||||||
capture_clause: CaptureBy::Value { move_kw: DUMMY_SP },
|
capture_clause: CaptureBy::Value { move_kw: DUMMY_SP },
|
||||||
constness: Const::No,
|
constness: Const::No,
|
||||||
coro_kind: None,
|
coroutine_kind: None,
|
||||||
movability: Movability::Movable,
|
movability: Movability::Movable,
|
||||||
fn_decl: decl.clone(),
|
fn_decl: decl.clone(),
|
||||||
body: e,
|
body: e,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue