1
Fork 0

Rename AsyncCoroutineKind to CoroutineSource

similar to how we have `MatchSource`, it explains where the desugaring came from.
This commit is contained in:
Oli Scherer 2023-10-23 17:02:40 +00:00
parent eb03d40a9c
commit af8a998b1e
19 changed files with 59 additions and 59 deletions

View file

@ -188,7 +188,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
e.id, e.id,
None, None,
e.span, e.span,
hir::AsyncCoroutineKind::Block, hir::CoroutineSource::Block,
|this| this.with_new_scopes(|this| this.lower_block_expr(block)), |this| this.with_new_scopes(|this| this.lower_block_expr(block)),
), ),
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr), ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
@ -598,7 +598,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
closure_node_id: NodeId, closure_node_id: NodeId,
ret_ty: Option<hir::FnRetTy<'hir>>, ret_ty: Option<hir::FnRetTy<'hir>>,
span: Span, span: Span,
async_gen_kind: hir::AsyncCoroutineKind, async_gen_kind: hir::CoroutineSource,
body: impl FnOnce(&mut Self) -> hir::Expr<'hir>, body: impl FnOnce(&mut Self) -> hir::Expr<'hir>,
) -> hir::ExprKind<'hir> { ) -> hir::ExprKind<'hir> {
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span))); let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
@ -1005,7 +1005,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
inner_closure_id, inner_closure_id,
async_ret_ty, async_ret_ty,
body.span, body.span,
hir::AsyncCoroutineKind::Closure, hir::CoroutineSource::Closure,
|this| this.with_new_scopes(|this| this.lower_expr_mut(body)), |this| this.with_new_scopes(|this| this.lower_expr_mut(body)),
); );
let hir_id = this.lower_node_id(inner_closure_id); let hir_id = this.lower_node_id(inner_closure_id);

View file

@ -1206,7 +1206,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
closure_id, closure_id,
None, None,
body.span, body.span,
hir::AsyncCoroutineKind::Fn, hir::CoroutineSource::Fn,
|this| { |this| {
// Create a block from the user's function body: // Create a block from the user's function body:
let user_body = this.lower_block_expr(body); let user_body = this.lower_block_expr(body);

View file

@ -8,7 +8,7 @@ use rustc_errors::{
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor}; use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
use rustc_hir::{AsyncCoroutineKind, CoroutineKind, LangItem}; use rustc_hir::{CoroutineKind, CoroutineSource, LangItem};
use rustc_infer::traits::ObligationCause; use rustc_infer::traits::ObligationCause;
use rustc_middle::hir::nested_filter::OnlyBodies; use rustc_middle::hir::nested_filter::OnlyBodies;
use rustc_middle::mir::tcx::PlaceTy; use rustc_middle::mir::tcx::PlaceTy;
@ -2506,8 +2506,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
let kind = match use_span.coroutine_kind() { let kind = match use_span.coroutine_kind() {
Some(coroutine_kind) => match coroutine_kind { Some(coroutine_kind) => match coroutine_kind {
CoroutineKind::Async(async_kind) => match async_kind { CoroutineKind::Async(async_kind) => match async_kind {
AsyncCoroutineKind::Block => "async block", CoroutineSource::Block => "async block",
AsyncCoroutineKind::Closure => "async closure", CoroutineSource::Closure => "async closure",
_ => bug!("async block/closure expected, but async function found."), _ => bug!("async block/closure expected, but async function found."),
}, },
CoroutineKind::Coroutine => "coroutine", CoroutineKind::Coroutine => "coroutine",

View file

@ -682,9 +682,9 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
}; };
let mir_description = match hir.body(body).coroutine_kind { let mir_description = match hir.body(body).coroutine_kind {
Some(hir::CoroutineKind::Async(gen)) => match gen { Some(hir::CoroutineKind::Async(gen)) => match gen {
hir::AsyncCoroutineKind::Block => " of async block", hir::CoroutineSource::Block => " of async block",
hir::AsyncCoroutineKind::Closure => " of async closure", hir::CoroutineSource::Closure => " of async closure",
hir::AsyncCoroutineKind::Fn => { hir::CoroutineSource::Fn => {
let parent_item = let parent_item =
hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id); hir.get_by_def_id(hir.get_parent_item(mir_hir_id).def_id);
let output = &parent_item let output = &parent_item

View file

@ -15,7 +15,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData}; use rustc_hir::definitions::{DefPathData, DefPathDataName, DisambiguatedDefPathData};
use rustc_hir::{AsyncCoroutineKind, CoroutineKind, Mutability}; use rustc_hir::{CoroutineKind, CoroutineSource, Mutability};
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout}; use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
use rustc_middle::ty::{self, ExistentialProjection, ParamEnv, Ty, TyCtxt}; use rustc_middle::ty::{self, ExistentialProjection, ParamEnv, Ty, TyCtxt};
use rustc_middle::ty::{GenericArgKind, GenericArgsRef}; use rustc_middle::ty::{GenericArgKind, GenericArgsRef};
@ -560,9 +560,9 @@ pub fn push_item_name(tcx: TyCtxt<'_>, def_id: DefId, qualified: bool, output: &
fn coroutine_kind_label(coroutine_kind: Option<CoroutineKind>) -> &'static str { fn coroutine_kind_label(coroutine_kind: Option<CoroutineKind>) -> &'static str {
match coroutine_kind { match coroutine_kind {
Some(CoroutineKind::Async(AsyncCoroutineKind::Block)) => "async_block", Some(CoroutineKind::Async(CoroutineSource::Block)) => "async_block",
Some(CoroutineKind::Async(AsyncCoroutineKind::Closure)) => "async_closure", Some(CoroutineKind::Async(CoroutineSource::Closure)) => "async_closure",
Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) => "async_fn", Some(CoroutineKind::Async(CoroutineSource::Fn)) => "async_fn",
Some(CoroutineKind::Coroutine) => "coroutine", Some(CoroutineKind::Coroutine) => "coroutine",
None => "closure", None => "closure",
} }

View file

@ -360,7 +360,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallUnstable {
pub struct Coroutine(pub hir::CoroutineKind); pub struct Coroutine(pub hir::CoroutineKind);
impl<'tcx> NonConstOp<'tcx> for Coroutine { impl<'tcx> NonConstOp<'tcx> for Coroutine {
fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status { fn status_in_item(&self, _: &ConstCx<'_, 'tcx>) -> Status {
if let hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) = self.0 { if let hir::CoroutineKind::Async(hir::CoroutineSource::Block) = self.0 {
Status::Unstable(sym::const_async_blocks) Status::Unstable(sym::const_async_blocks)
} else { } else {
Status::Forbidden Status::Forbidden
@ -373,7 +373,7 @@ impl<'tcx> NonConstOp<'tcx> for Coroutine {
span: Span, span: Span,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> { ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind()); let msg = format!("{}s are not allowed in {}s", self.0.descr(), ccx.const_kind());
if let hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) = self.0 { if let hir::CoroutineKind::Async(hir::CoroutineSource::Block) = self.0 {
ccx.tcx.sess.create_feature_err( ccx.tcx.sess.create_feature_err(
errors::UnallowedOpInConstContext { span, msg }, errors::UnallowedOpInConstContext { span, msg },
sym::const_async_blocks, sym::const_async_blocks,

View file

@ -1511,7 +1511,7 @@ impl<'hir> Body<'hir> {
#[derive(HashStable_Generic, Encodable, Decodable)] #[derive(HashStable_Generic, Encodable, Decodable)]
pub enum CoroutineKind { pub enum CoroutineKind {
/// An explicit `async` block or the body of an async function. /// An explicit `async` block or the body of an async function.
Async(AsyncCoroutineKind), Async(CoroutineSource),
/// A coroutine literal created via a `yield` inside a closure. /// A coroutine literal created via a `yield` inside a closure.
Coroutine, Coroutine,
@ -1535,40 +1535,40 @@ impl CoroutineKind {
} }
} }
/// In the case of a coroutine created as part of an async construct, /// In the case of a coroutine created as part of an async/gen construct,
/// which kind of async construct caused it to be created? /// which kind of async/gen construct caused it to be created?
/// ///
/// This helps error messages but is also used to drive coercions in /// This helps error messages but is also used to drive coercions in
/// type-checking (see #60424). /// type-checking (see #60424).
#[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)] #[derive(Clone, PartialEq, Eq, Hash, Debug, Copy)]
#[derive(HashStable_Generic, Encodable, Decodable)] #[derive(HashStable_Generic, Encodable, Decodable)]
pub enum AsyncCoroutineKind { pub enum CoroutineSource {
/// An explicit `async` block written by the user. /// An explicit `async`/`gen` block written by the user.
Block, Block,
/// An explicit `async` closure written by the user. /// An explicit `async`/`gen` closure written by the user.
Closure, Closure,
/// The `async` block generated as the body of an async function. /// The `async`/`gen` block generated as the body of an async/gen function.
Fn, Fn,
} }
impl fmt::Display for AsyncCoroutineKind { impl fmt::Display for CoroutineSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self { f.write_str(match self {
AsyncCoroutineKind::Block => "async block", CoroutineSource::Block => "async block",
AsyncCoroutineKind::Closure => "async closure body", CoroutineSource::Closure => "async closure body",
AsyncCoroutineKind::Fn => "async fn body", CoroutineSource::Fn => "async fn body",
}) })
} }
} }
impl AsyncCoroutineKind { impl CoroutineSource {
pub fn descr(&self) -> &'static str { pub fn descr(&self) -> &'static str {
match self { match self {
AsyncCoroutineKind::Block => "`async` block", CoroutineSource::Block => "`async` block",
AsyncCoroutineKind::Closure => "`async` closure body", CoroutineSource::Closure => "`async` closure body",
AsyncCoroutineKind::Fn => "`async fn` body", CoroutineSource::Fn => "`async fn` body",
} }
} }
} }

View file

@ -305,7 +305,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) = (parent_node, callee_node) ) = (parent_node, callee_node)
{ {
let fn_decl_span = if hir.body(body).coroutine_kind let fn_decl_span = if hir.body(body).coroutine_kind
== Some(hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Closure)) == Some(hir::CoroutineKind::Async(hir::CoroutineSource::Closure))
{ {
// Actually need to unwrap one more layer of HIR to get to // Actually need to unwrap one more layer of HIR to get to
// the _real_ closure... // the _real_ closure...

View file

@ -636,7 +636,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// In the case of the async block that we create for a function body, // In the case of the async block that we create for a function body,
// we expect the return type of the block to match that of the enclosing // we expect the return type of the block to match that of the enclosing
// function. // function.
Some(hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Fn)) => { Some(hir::CoroutineKind::Async(hir::CoroutineSource::Fn)) => {
debug!("closure is async fn body"); debug!("closure is async fn body");
let def_id = self.tcx.hir().body_owner_def_id(body.id()); let def_id = self.tcx.hir().body_owner_def_id(body.id());
self.deduce_future_output_from_obligations(expr_def_id, def_id).unwrap_or_else( self.deduce_future_output_from_obligations(expr_def_id, def_id).unwrap_or_else(

View file

@ -10,8 +10,8 @@ use rustc_hir::def::Res;
use rustc_hir::def::{CtorKind, CtorOf, DefKind}; use rustc_hir::def::{CtorKind, CtorOf, DefKind};
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{ use rustc_hir::{
AsyncCoroutineKind, CoroutineKind, Expr, ExprKind, GenericBound, HirId, Node, Path, QPath, CoroutineKind, CoroutineSource, Expr, ExprKind, GenericBound, HirId, Node, Path, QPath, Stmt,
Stmt, StmtKind, TyKind, WherePredicate, StmtKind, TyKind, WherePredicate,
}; };
use rustc_hir_analysis::astconv::AstConv; use rustc_hir_analysis::astconv::AstConv;
use rustc_infer::traits::{self, StatementAsExpression}; use rustc_infer::traits::{self, StatementAsExpression};
@ -536,7 +536,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::Coroutine(def_id, ..) ty::Coroutine(def_id, ..)
if matches!( if matches!(
self.tcx.coroutine_kind(def_id), self.tcx.coroutine_kind(def_id),
Some(CoroutineKind::Async(AsyncCoroutineKind::Closure)) Some(CoroutineKind::Async(CoroutineSource::Closure))
) => ) =>
{ {
errors::SuggestBoxing::AsyncBody errors::SuggestBoxing::AsyncBody

View file

@ -917,13 +917,13 @@ impl<'tcx> Stable<'tcx> for mir::AggregateKind<'tcx> {
impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind { impl<'tcx> Stable<'tcx> for rustc_hir::CoroutineKind {
type T = stable_mir::mir::CoroutineKind; type T = stable_mir::mir::CoroutineKind;
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T { fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
use rustc_hir::{AsyncCoroutineKind, CoroutineKind}; use rustc_hir::{CoroutineKind, CoroutineSource};
match self { match self {
CoroutineKind::Async(async_gen) => { CoroutineKind::Async(async_gen) => {
let async_gen = match async_gen { let async_gen = match async_gen {
AsyncCoroutineKind::Block => stable_mir::mir::AsyncCoroutineKind::Block, CoroutineSource::Block => stable_mir::mir::CoroutineSource::Block,
AsyncCoroutineKind::Closure => stable_mir::mir::AsyncCoroutineKind::Closure, CoroutineSource::Closure => stable_mir::mir::CoroutineSource::Closure,
AsyncCoroutineKind::Fn => stable_mir::mir::AsyncCoroutineKind::Fn, CoroutineSource::Fn => stable_mir::mir::CoroutineSource::Fn,
}; };
stable_mir::mir::CoroutineKind::Async(async_gen) stable_mir::mir::CoroutineKind::Async(async_gen)
} }

View file

@ -22,7 +22,7 @@ use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::Visitor; use rustc_hir::intravisit::Visitor;
use rustc_hir::is_range_literal; use rustc_hir::is_range_literal;
use rustc_hir::lang_items::LangItem; use rustc_hir::lang_items::LangItem;
use rustc_hir::{AsyncCoroutineKind, CoroutineKind, Node}; use rustc_hir::{CoroutineKind, CoroutineSource, Node};
use rustc_hir::{Expr, HirId}; use rustc_hir::{Expr, HirId};
use rustc_infer::infer::error_reporting::TypeErrCtxt; use rustc_infer::infer::error_reporting::TypeErrCtxt;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@ -2410,7 +2410,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.and_then(|coroutine_did| { .and_then(|coroutine_did| {
Some(match self.tcx.coroutine_kind(coroutine_did).unwrap() { Some(match self.tcx.coroutine_kind(coroutine_did).unwrap() {
CoroutineKind::Coroutine => format!("coroutine is not {trait_name}"), CoroutineKind::Coroutine => format!("coroutine is not {trait_name}"),
CoroutineKind::Async(AsyncCoroutineKind::Fn) => self CoroutineKind::Async(CoroutineSource::Fn) => self
.tcx .tcx
.parent(coroutine_did) .parent(coroutine_did)
.as_local() .as_local()
@ -2419,10 +2419,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
.map(|name| { .map(|name| {
format!("future returned by `{name}` is not {trait_name}") format!("future returned by `{name}` is not {trait_name}")
})?, })?,
CoroutineKind::Async(AsyncCoroutineKind::Block) => { CoroutineKind::Async(CoroutineSource::Block) => {
format!("future created by async block is not {trait_name}") format!("future created by async block is not {trait_name}")
} }
CoroutineKind::Async(AsyncCoroutineKind::Closure) => { CoroutineKind::Async(CoroutineSource::Closure) => {
format!("future created by async closure is not {trait_name}") format!("future created by async closure is not {trait_name}")
} }
}) })

View file

@ -1611,9 +1611,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str> { fn describe_coroutine(&self, body_id: hir::BodyId) -> Option<&'static str> {
self.tcx.hir().body(body_id).coroutine_kind.map(|gen_kind| match gen_kind { self.tcx.hir().body(body_id).coroutine_kind.map(|gen_kind| match gen_kind {
hir::CoroutineKind::Coroutine => "a coroutine", hir::CoroutineKind::Coroutine => "a coroutine",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Block) => "an async block", hir::CoroutineKind::Async(hir::CoroutineSource::Block) => "an async block",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Fn) => "an async function", hir::CoroutineKind::Async(hir::CoroutineSource::Fn) => "an async function",
hir::CoroutineKind::Async(hir::AsyncCoroutineKind::Closure) => "an async closure", hir::CoroutineKind::Async(hir::CoroutineSource::Closure) => "an async closure",
}) })
} }

View file

@ -135,12 +135,12 @@ pub enum UnOp {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum CoroutineKind { pub enum CoroutineKind {
Async(AsyncCoroutineKind), Async(CoroutineSource),
Coroutine, Coroutine,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum AsyncCoroutineKind { pub enum CoroutineSource {
Block, Block,
Closure, Closure,
Fn, Fn,

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_hir_and_then;
use clippy_utils::source::snippet; use clippy_utils::source::snippet;
use clippy_utils::ty::implements_trait; use clippy_utils::ty::implements_trait;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{AsyncCoroutineKind, Body, BodyId, CoroutineKind, ExprKind, QPath}; use rustc_hir::{CoroutineSource, Body, BodyId, CoroutineKind, ExprKind, QPath};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
@ -45,7 +45,7 @@ declare_lint_pass!(AsyncYieldsAsync => [ASYNC_YIELDS_ASYNC]);
impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync { impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) { fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
use AsyncCoroutineKind::{Block, Closure}; use CoroutineSource::{Block, Closure};
// For functions, with explicitly defined types, don't warn. // For functions, with explicitly defined types, don't warn.
// XXXkhuey maybe we should? // XXXkhuey maybe we should?
if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind { if let Some(CoroutineKind::Async(Block | Closure)) = body.coroutine_kind {

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::{match_def_path, paths}; use clippy_utils::{match_def_path, paths};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{AsyncCoroutineKind, Body, CoroutineKind}; use rustc_hir::{CoroutineSource, Body, CoroutineKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::CoroutineLayout; use rustc_middle::mir::CoroutineLayout;
use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_session::{declare_tool_lint, impl_lint_pass};
@ -195,7 +195,7 @@ impl LateLintPass<'_> for AwaitHolding {
} }
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
use AsyncCoroutineKind::{Block, Closure, Fn}; use CoroutineSource::{Block, Closure, Fn};
if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind { if let Some(CoroutineKind::Async(Block | Closure | Fn)) = body.coroutine_kind {
let def_id = cx.tcx.hir().body_owner_def_id(body.id()); let def_id = cx.tcx.hir().body_owner_def_id(body.id());
if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) { if let Some(coroutine_layout) = cx.tcx.mir_coroutine_witnesses(def_id) {

View file

@ -4,7 +4,7 @@ use if_chain::if_chain;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{ use rustc_hir::{
AsyncCoroutineKind, Block, Body, Closure, CoroutineKind, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound, CoroutineSource, Block, Body, Closure, CoroutineKind, Expr, ExprKind, FnDecl, FnRetTy, GenericArg, GenericBound,
ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind, ImplItem, Item, ItemKind, LifetimeName, Node, Term, TraitRef, Ty, TyKind, TypeBindingKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@ -188,7 +188,7 @@ fn desugared_async_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>)
.. ..
} = block_expr; } = block_expr;
let closure_body = cx.tcx.hir().body(body); let closure_body = cx.tcx.hir().body(body);
if closure_body.coroutine_kind == Some(CoroutineKind::Async(AsyncCoroutineKind::Block)); if closure_body.coroutine_kind == Some(CoroutineKind::Async(CoroutineSource::Block));
then { then {
return Some(closure_body); return Some(closure_body);
} }

View file

@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
use if_chain::if_chain; use if_chain::if_chain;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{AsyncCoroutineKind, Block, Body, CoroutineKind, Expr, ExprKind, LangItem, MatchSource, QPath}; use rustc_hir::{CoroutineSource, Block, Body, CoroutineKind, Expr, ExprKind, LangItem, MatchSource, QPath};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};
@ -87,7 +87,7 @@ impl LateLintPass<'_> for NeedlessQuestionMark {
} }
fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) { fn check_body(&mut self, cx: &LateContext<'_>, body: &'_ Body<'_>) {
if let Some(CoroutineKind::Async(AsyncCoroutineKind::Fn)) = body.coroutine_kind { if let Some(CoroutineKind::Async(CoroutineSource::Fn)) = body.coroutine_kind {
if let ExprKind::Block( if let ExprKind::Block(
Block { Block {
expr: expr:

View file

@ -5,7 +5,7 @@ use clippy_utils::peel_blocks;
use clippy_utils::source::{snippet, walk_span_to_context}; use clippy_utils::source::{snippet, walk_span_to_context};
use clippy_utils::visitors::for_each_expr; use clippy_utils::visitors::for_each_expr;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{AsyncCoroutineKind, Closure, CoroutineKind, Expr, ExprKind, MatchSource}; use rustc_hir::{CoroutineSource, Closure, CoroutineKind, Expr, ExprKind, MatchSource};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro; use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::UpvarCapture; use rustc_middle::ty::UpvarCapture;
@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantAsyncBlock {
fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> { fn desugar_async_block<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<&'tcx Expr<'tcx>> {
if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind && if let ExprKind::Closure(Closure { body, def_id, .. }) = expr.kind &&
let body = cx.tcx.hir().body(*body) && let body = cx.tcx.hir().body(*body) &&
matches!(body.coroutine_kind, Some(CoroutineKind::Async(AsyncCoroutineKind::Block))) matches!(body.coroutine_kind, Some(CoroutineKind::Async(CoroutineSource::Block)))
{ {
cx cx
.typeck_results() .typeck_results()