Skip to content

Commit 45be5dd

Browse files
committed
Option<CoroutineKind>
1 parent b4e3b85 commit 45be5dd

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clippy_lints/src/doc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ fn check_code(cx: &LateContext<'_>, text: &str, edition: Edition, range: Range<u
700700
ItemKind::Fn(box Fn {
701701
sig, body: Some(block), ..
702702
}) if item.ident.name == sym::main => {
703-
let is_async = sig.header.coro_kind.is_async();
703+
let is_async = sig.header.coro_kind.map_or(false, |coro| coro.is_async());
704704
let returns_nothing = match &sig.decl.output {
705705
FnRetTy::Default(..) => true,
706706
FnRetTy::Ty(ty) if ty.kind.is_unit() => true,

clippy_utils/src/ast_utils.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
206206
) => {
207207
eq_closure_binder(lb, rb)
208208
&& lc == rc
209-
&& la.is_async() == ra.is_async()
209+
&& la.map_or(false, |la| la.is_async()) == ra.map_or(false, |ra| ra.is_async())
210210
&& lm == rm
211211
&& eq_fn_decl(lf, rf)
212212
&& eq_expr(le, re)
@@ -563,9 +563,18 @@ pub fn eq_fn_sig(l: &FnSig, r: &FnSig) -> bool {
563563
eq_fn_decl(&l.decl, &r.decl) && eq_fn_header(&l.header, &r.header)
564564
}
565565

566+
fn eq_opt_coro_kind(l: Option<CoroutineKind>, r: Option<CoroutineKind>) -> bool {
567+
match (l, r) {
568+
(Some(CoroutineKind::Async { .. }), Some(CoroutineKind::Async { .. }))
569+
| (Some(CoroutineKind::Gen { .. }), Some(CoroutineKind::Gen { .. })) => true,
570+
(None, None) => true,
571+
_ => false,
572+
}
573+
}
574+
566575
pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
567576
matches!(l.unsafety, Unsafe::No) == matches!(r.unsafety, Unsafe::No)
568-
&& (l.coro_kind.is_async() == r.coro_kind.is_async() || l.coro_kind.is_gen() == r.coro_kind.is_gen())
577+
&& eq_opt_coro_kind(l.coro_kind, r.coro_kind)
569578
&& matches!(l.constness, Const::No) == matches!(r.constness, Const::No)
570579
&& eq_ext(&l.ext, &r.ext)
571580
}

0 commit comments

Comments
 (0)