Skip to content

Commit c4165f3

Browse files
drive-by: Add is_async fn to hir::IsAsync
1 parent fd3bfb3 commit c4165f3

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
6262
}
6363

6464
fn is_async(&self) -> bool {
65-
self.tcx.asyncness(self.def_id()) == hir::IsAsync::Async
65+
self.tcx.asyncness(self.def_id()).is_async()
6666
}
6767
}
6868

compiler/rustc_hir/src/hir.rs

+6
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,12 @@ pub enum IsAsync {
27202720
NotAsync,
27212721
}
27222722

2723+
impl IsAsync {
2724+
pub fn is_async(self) -> bool {
2725+
self == IsAsync::Async
2726+
}
2727+
}
2728+
27232729
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)]
27242730
pub enum Defaultness {
27252731
Default { has_value: bool },

compiler/rustc_hir_analysis/src/check/compare_method.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,7 @@ fn report_trait_method_mismatch<'tcx>(
688688
// Suggestion to change output type. We do not suggest in `async` functions
689689
// to avoid complex logic or incorrect output.
690690
match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
691-
ImplItemKind::Fn(ref sig, _)
692-
if sig.header.asyncness == hir::IsAsync::NotAsync =>
693-
{
691+
ImplItemKind::Fn(ref sig, _) if !sig.header.asyncness.is_async() => {
694692
let msg = "change the output type to match the trait";
695693
let ap = Applicability::MachineApplicable;
696694
match sig.decl.output {

src/tools/clippy/clippy_lints/src/manual_async_fn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::intravisit::FnKind;
77
use rustc_hir::{
88
AsyncGeneratorKind, Block, Body, Closure, Expr, ExprKind, FnDecl, FnRetTy, GeneratorKind, GenericArg, GenericBound,
9-
HirId, IsAsync, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind,
9+
HirId, ItemKind, LifetimeName, Term, TraitRef, Ty, TyKind, TypeBindingKind,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualAsyncFn {
4949
) {
5050
if_chain! {
5151
if let Some(header) = kind.header();
52-
if header.asyncness == IsAsync::NotAsync;
52+
if !header.asyncness.is_async();
5353
// Check that this function returns `impl Future`
5454
if let FnRetTy::Return(ret_ty) = decl.output;
5555
if let Some((trait_ref, output_lifetimes)) = future_trait_ref(cx, ret_ty);

src/tools/clippy/clippy_lints/src/unused_async.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_hir::intravisit::{walk_expr, walk_fn, FnKind, Visitor};
3-
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, IsAsync, YieldSource};
3+
use rustc_hir::{Body, Expr, ExprKind, FnDecl, HirId, YieldSource};
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_middle::hir::nested_filter;
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAsync {
6868
span: Span,
6969
hir_id: HirId,
7070
) {
71-
if !span.from_expansion() && fn_kind.asyncness() == IsAsync::Async {
71+
if !span.from_expansion() && fn_kind.asyncness().is_async() {
7272
let mut visitor = AsyncFnVisitor { cx, found_await: false };
7373
walk_fn(&mut visitor, fn_kind, fn_decl, body.id(), hir_id);
7474
if !visitor.found_await {

src/tools/clippy/clippy_utils/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ use rustc_hir::hir_id::{HirIdMap, HirIdSet};
8787
use rustc_hir::intravisit::{walk_expr, FnKind, Visitor};
8888
use rustc_hir::LangItem::{OptionNone, ResultErr, ResultOk};
8989
use rustc_hir::{
90-
def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Constness, Destination, Expr,
91-
ExprKind, FnDecl, HirId, Impl, ImplItem, ImplItemKind, IsAsync, Item, ItemKind, LangItem, Local, MatchSource,
92-
Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy, QPath, Stmt, StmtKind, TraitItem, TraitItemKind,
93-
TraitRef, TyKind, UnOp,
90+
def, Arm, ArrayLen, BindingAnnotation, Block, BlockCheckMode, Body, Closure, Constness,
91+
Destination, Expr, ExprKind, FnDecl, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind,
92+
LangItem, Local, MatchSource, Mutability, Node, Param, Pat, PatKind, Path, PathSegment, PrimTy,
93+
QPath, Stmt, StmtKind, TraitItem, TraitItemKind, TraitRef, TyKind, UnOp,
9494
};
9595
use rustc_lexer::{tokenize, TokenKind};
9696
use rustc_lint::{LateContext, Level, Lint, LintContext};
@@ -1861,7 +1861,7 @@ pub fn if_sequence<'tcx>(mut expr: &'tcx Expr<'tcx>) -> (Vec<&'tcx Expr<'tcx>>,
18611861

18621862
/// Checks if the given function kind is an async function.
18631863
pub fn is_async_fn(kind: FnKind<'_>) -> bool {
1864-
matches!(kind, FnKind::ItemFn(_, _, header) if header.asyncness == IsAsync::Async)
1864+
matches!(kind, FnKind::ItemFn(_, _, header) if header.asyncness.is_async())
18651865
}
18661866

18671867
/// Peels away all the compiler generated code surrounding the body of an async function,

0 commit comments

Comments
 (0)