Skip to content

Commit

Permalink
coro_kind -> coroutine_kind
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Dec 5, 2023
1 parent f202125 commit 8d98feb
Show file tree
Hide file tree
Showing 23 changed files with 90 additions and 75 deletions.
15 changes: 10 additions & 5 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ pub struct Closure {
pub binder: ClosureBinder,
pub capture_clause: CaptureBy,
pub constness: Const,
pub coro_kind: Option<CoroutineKind>,
pub coroutine_kind: Option<CoroutineKind>,
pub movability: Movability,
pub fn_decl: P<FnDecl>,
pub body: P<Expr>,
Expand Down Expand Up @@ -2840,7 +2840,7 @@ pub struct FnHeader {
/// The `unsafe` keyword, if any
pub unsafety: Unsafe,
/// Whether this is `async`, `gen`, or nothing.
pub coro_kind: Option<CoroutineKind>,
pub coroutine_kind: Option<CoroutineKind>,
/// The `const` keyword, if any
pub constness: Const,
/// The `extern` keyword and corresponding ABI string, if any
Expand All @@ -2850,17 +2850,22 @@ pub struct FnHeader {
impl FnHeader {
/// Does this function header have any qualifiers or is it empty?
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(_))
|| coro_kind.is_some()
|| coroutine_kind.is_some()
|| matches!(constness, Const::Yes(_))
|| !matches!(ext, Extern::None)
}
}

impl Default for 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,
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub trait MutVisitor: Sized {
noop_visit_fn_decl(d, self);
}

fn visit_coro_kind(&mut self, a: &mut CoroutineKind) {
noop_visit_coro_kind(a, self);
fn visit_coroutine_kind(&mut self, a: &mut CoroutineKind) {
noop_visit_coroutine_kind(a, self);
}

fn visit_closure_binder(&mut self, b: &mut ClosureBinder) {
Expand Down Expand Up @@ -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) {
match coro_kind {
pub fn noop_visit_coroutine_kind<T: MutVisitor>(coroutine_kind: &mut CoroutineKind, vis: &mut T) {
match coroutine_kind {
CoroutineKind::Async { span, closure_id, return_impl_trait_id }
| CoroutineKind::Gen { span, closure_id, return_impl_trait_id } => {
vis.visit_span(span);
Expand Down Expand Up @@ -1171,9 +1171,9 @@ fn visit_const_item<T: MutVisitor>(
}

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);
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);
}

Expand Down Expand Up @@ -1407,7 +1407,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
binder,
capture_clause,
constness,
coro_kind,
coroutine_kind,
movability: _,
fn_decl,
body,
Expand All @@ -1416,7 +1416,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
}) => {
vis.visit_closure_binder(binder);
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_fn_decl(fn_decl);
vis.visit_expr(body);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) {
ExprKind::Closure(box Closure {
binder,
capture_clause,
coro_kind: _,
coroutine_kind: _,
constness: _,
movability: _,
fn_decl,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
binder,
capture_clause,
constness,
coro_kind,
coroutine_kind,
movability,
fn_decl,
body,
fn_decl_span,
fn_arg_span,
}) => match coro_kind {
}) => match coroutine_kind {
Some(
CoroutineKind::Async { closure_id, .. }
| CoroutineKind::Gen { closure_id, .. },
Expand Down
36 changes: 21 additions & 15 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
// `impl Future<Output = T>` here because lower_body
// only cares about the input argument patterns in the function
// 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(
span,
hir_id,
decl,
coro_kind,
coroutine_kind,
body.as_deref(),
);

let itctx = ImplTraitContext::Universal;
let (generics, decl) =
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 {
decl,
Expand Down Expand Up @@ -735,7 +741,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
sig,
i.id,
FnDeclKind::Trait,
sig.header.coro_kind,
sig.header.coroutine_kind,
);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Required(names)), false)
}
Expand All @@ -744,15 +750,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
i.span,
hir_id,
&sig.decl,
sig.header.coro_kind,
sig.header.coroutine_kind,
Some(body),
);
let (generics, sig) = self.lower_method_sig(
generics,
sig,
i.id,
FnDeclKind::Trait,
sig.header.coro_kind,
sig.header.coroutine_kind,
);
(generics, hir::TraitItemKind::Fn(sig, hir::TraitFn::Provided(body_id)), true)
}
Expand Down Expand Up @@ -845,15 +851,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
i.span,
hir_id,
&sig.decl,
sig.header.coro_kind,
sig.header.coroutine_kind,
body.as_deref(),
);
let (generics, sig) = self.lower_method_sig(
generics,
sig,
i.id,
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))
Expand Down Expand Up @@ -1024,13 +1030,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
span: Span,
fn_id: hir::HirId,
decl: &FnDecl,
coro_kind: Option<CoroutineKind>,
coroutine_kind: Option<CoroutineKind>,
body: Option<&Block>,
) -> 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);
};
let closure_id = match coro_kind {
let closure_id = match coroutine_kind {
CoroutineKind::Async { closure_id, .. } | CoroutineKind::Gen { closure_id, .. } => {
closure_id
}
Expand Down Expand Up @@ -1201,7 +1207,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

this.expr_block(body)
};
let coroutine_expr = match coro_kind {
let coroutine_expr = match coroutine_kind {
CoroutineKind::Async { .. } => this.make_async_expr(
CaptureBy::Value { move_kw: rustc_span::DUMMY_SP },
closure_id,
Expand Down Expand Up @@ -1234,19 +1240,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
sig: &FnSig,
id: NodeId,
kind: FnDeclKind,
coro_kind: Option<CoroutineKind>,
coroutine_kind: Option<CoroutineKind>,
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
let header = self.lower_fn_header(sig.header);
let itctx = ImplTraitContext::Universal;
let (generics, decl) =
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) })
}

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)
} else {
hir::IsAsync::NotAsync
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
// Functions cannot both be `const async` or `const gen`
if let Some(&FnHeader {
constness: Const::Yes(cspan),
coro_kind:
coroutine_kind:
Some(
CoroutineKind::Async { span: aspan, .. }
| CoroutineKind::Gen { span: aspan, .. },
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,8 +1490,8 @@ impl<'a> State<'a> {
}
}

fn print_coro_kind(&mut self, coro_kind: ast::CoroutineKind) {
match coro_kind {
fn print_coroutine_kind(&mut self, coroutine_kind: ast::CoroutineKind) {
match coroutine_kind {
ast::CoroutineKind::Gen { .. } => {
self.word_nbsp("gen");
}
Expand Down Expand Up @@ -1690,7 +1690,7 @@ impl<'a> State<'a> {

fn print_fn_header_info(&mut self, header: ast::FnHeader) {
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);

match header.ext {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ impl<'a> State<'a> {
binder,
capture_clause,
constness,
coro_kind,
coroutine_kind,
movability,
fn_decl,
body,
Expand All @@ -423,7 +423,7 @@ impl<'a> State<'a> {
self.print_closure_binder(binder);
self.print_constness(*constness);
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_fn_params_and_ret(fn_decl, true);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,11 @@ fn check_test_signature(
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" }));
}

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" }));
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ impl<'a> ExtCtxt<'a> {
binder: ast::ClosureBinder::NotPresent,
capture_clause: ast::CaptureBy::Ref,
constness: ast::Const::No,
coro_kind: None,
coroutine_kind: None,
movability: ast::Movability::Movable,
fn_decl,
body,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/early.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
if let Some(
ast::CoroutineKind::Async { closure_id, .. }
| ast::CoroutineKind::Gen { closure_id, .. },
) = sig.header.coro_kind
) = sig.header.coroutine_kind
{
self.check_id(closure_id);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<'a, T: EarlyLintPass> ast_visit::Visitor<'a> for EarlyContextAndPass<'a, T>
// it does not have a corresponding AST node
match e.kind {
ast::ExprKind::Closure(box ast::Closure {
coro_kind:
coroutine_kind:
Some(
ast::CoroutineKind::Async { closure_id, .. }
| ast::CoroutineKind::Gen { closure_id, .. },
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,7 @@ impl<'a> Parser<'a> {
binder,
capture_clause,
constness,
coro_kind: asyncness,
coroutine_kind: asyncness,
movability,
fn_decl,
body,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2559,7 +2559,7 @@ impl<'a> Parser<'a> {
return Ok(FnHeader {
constness: recover_constness,
unsafety: recover_unsafety,
coro_kind: recover_asyncness,
coroutine_kind: recover_asyncness,
ext,
});
}
Expand All @@ -2569,13 +2569,13 @@ impl<'a> Parser<'a> {
}
}

let coro_kind = match asyncness {
let coroutine_kind = match asyncness {
Some(CoroutineKind::Async { .. }) => asyncness,
Some(CoroutineKind::Gen { .. }) => unreachable!("asycness cannot be Gen"),
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.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl<'a> Parser<'a> {
tokens: None,
};
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)?;
if self.may_recover() && self.token.kind == TokenKind::Lt {
self.recover_fn_ptr_with_generics(lo, &mut params, param_insertion_point)?;
Expand All @@ -609,7 +609,7 @@ impl<'a> Parser<'a> {
// cover it.
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 });
}
// FIXME(gen_blocks): emit a similar error for `gen fn()`
Expand Down
Loading

0 comments on commit 8d98feb

Please sign in to comment.